Guide

Trim a video with an API

How do I cut a clip out of a video over an API?

Put -ss (where to start) and -t (how long) in the input's options, and -c copy in the output's. Seeking on the input rather than the output is what makes the cut fast, and -c copy skips re-encoding entirely.

The ffmpeg command

What you would run locally, for reference.

ffmpeg -ss 00:00:05 -t 10 -i input.mp4 -c copy output.mp4

The API request

The same flags, sent as JSON. Authenticate with Authorization: Token <your-api-token>.

POST /api/ffmpeg/job/
{
  "global_options": [
    "-y"
  ],
  "inputs": [
    {
      "input_source": "https://example.com/input.mp4",
      "options": [
        "-ss",
        "00:00:05",
        "-t",
        "10"
      ]
    }
  ],
  "outputs": [
    {
      "filename": "output.mp4",
      "options": [
        "-c",
        "copy"
      ]
    }
  ]
}

Worth knowing

  • With -c copy the cut snaps to the nearest keyframe, so it can land up to a few seconds off. Drop -c copy and add -c:v libx264 when the cut has to be frame-exact.
  • -t is a duration, -to is an end timestamp. Mixing them up is the most common way to get a clip of the wrong length.

What it costs

Jobs bill in processing seconds — the CPU time this one actually uses — with a floor of 25 seconds per GB pulled out of storage to run it, so a stream-copy still counts. Uploading the output and downloading it afterwards are free. See the plans.

Related guides

Start free API reference

Ask me for anything

QuickFFmpeg is early and plenty is still missing. Tell me what you need and it goes straight to the top of my list.

This arrives anonymously. Log in first if you'd like an answer.