TechEarl

How to Trim or Cut a Video with ffmpeg

Trim or cut a video from the command line with ffmpeg: the fast lossless -c copy way, the keyframe gotcha that makes your cut land early, and the frame-accurate re-encode. With -ss and -to/-t explained.

Ishan KarunaratnePublished ⏱️ 9 min readUpdated
Share thisCopied
Trim or cut a video from the command line with ffmpeg using -ss and -to or -t, the fast lossless stream-copy way and the frame-accurate re-encode.

The fast way to cut a clip out of a video with ffmpeg is to seek to the start, set an end point, and copy the streams without re-encoding:

bash
ffmpeg -ss 00:00:10 -to 00:00:20 -i input.mp4 -c copy out.mp4

That pulls seconds 10 to 20 out of input.mp4 into out.mp4 in a fraction of a second, with zero quality loss, because -c copy (stream copy) muxes the existing video and audio packets straight through instead of decoding and re-encoding them. For most "grab this segment" jobs it is the whole answer.

There is one catch worth understanding before you trust the output, and it is the source of nearly every "my cut started in the wrong place" complaint: stream copy can only cut on keyframes. The rest of this page covers that gotcha, the frame-accurate alternative, and what -ss, -to, and -t actually mean.

The fast, lossless cut (-c copy)

Two forms, depending on whether you think in end-time or duration. Use -to for an absolute end timestamp:

bash
# Keep everything from 00:00:10 to 00:00:20 (10 seconds of output)
ffmpeg -ss 00:00:10 -to 00:00:20 -i input.mp4 -c copy out.mp4

Or use -t for a duration measured from the start point:

bash
# Start at 00:00:10 and keep 10 seconds
ffmpeg -ss 00:00:10 -t 10 -i input.mp4 -c copy out.mp4

-to and -t are not the same flag. -to is an end position (stop at this point); -t is a duration (run for this long). The wrinkle is where -to sits relative to -i. In the commands above, -ss and -to both come before -i, so both are input options: ffmpeg seeks the input to 10 seconds and stops reading it at the 20-second position of the original file. That is why -ss 00:00:10 -to 00:00:20 gives you ten seconds, the same clip as -ss 00:00:10 -t 10. The trap is splitting the pair. Write -ss 00:00:10 -i input.mp4 -to 00:00:20 and -to becomes an output option; after an input seek the output's timestamps start again from zero, so the output runs until its own 20-second mark and you get a twenty-second clip (seconds 10 to 30 of the source). (Put both after -i and both apply on the output side against the original timeline, so -i input.mp4 -ss 10 -to 20 is a ten-second clip again.) -to and -t are mutually exclusive; if you pass both, -t wins. If a clip ever comes out longer than expected, check whether -to ended up after -i while -ss stayed before it, or whether you reached for -to thinking it meant duration.

This stream-copy command is instant and lossless: nothing is re-compressed, so there is no generation loss and no codec choice to make. It is the right tool for splitting a long screen recording, lopping dead air off the front, or carving a rough segment out of a large file. When the large file is something you first need to pull down, grabbing the video at full quality gives you the source to trim against.

The keyframe gotcha (why your cut lands early)

Video is not stored as independent frames. It is stored in groups of pictures (GOPs), each beginning with a keyframe (an I-frame, a complete standalone image), followed by predicted frames that only describe what changed. You cannot start decoding mid-GOP, so a stream copy cannot begin output anywhere except on a keyframe.

That means when you ask for -ss 00:00:10 with -c copy, ffmpeg snaps the start back to the nearest keyframe at or before 10 seconds. If the closest keyframe sits at 00:00:08, your clip begins two seconds early. Nothing is broken and no quality is lost, the cut point is just constrained to where the keyframes are. Keyframe spacing depends on how the source was encoded (often one every 2 to 10 seconds), so the error varies by file.

This is exactly the "result quality varies with -c copy, sometimes it is better without it" confusion you see in old forum threads. It was never random. It is the keyframe constraint. When the start needs to be exact, you re-encode.

The frame-accurate cut (re-encode)

Drop -c copy and ffmpeg decodes the source and re-encodes the output, so it can start on any frame you ask for, not just a keyframe:

bash
# Frame-accurate: exact start, exact length, re-encoded
ffmpeg -ss 00:00:10 -to 00:00:20 -i input.mp4 -c:v libx264 -crf 18 -c:a aac out.mp4

This is slower (it does real encoding work) and technically lossy (you are re-compressing), but -crf 18 for libx264 is visually near-transparent, so the quality cost is small. Use it when a couple of stray frames at the head of the clip would be obvious: cutting on a line of dialogue, trimming for social media, or stitching segments that have to line up.

Rule of thumb: reach for -c copy first for speed and zero loss, and only re-encode when the start point has to be precise.

Where -ss goes: before -i vs after -i

You will see -ss written both before and after -i, and the placement used to matter a lot more than it does now.

bash
# -ss before -i: fast input seek (jumps to a keyframe near the time, then reads)
ffmpeg -ss 00:00:10 -i input.mp4 -t 10 -c copy out.mp4

# -ss after -i: ffmpeg reads from the start and discards frames up to -ss
ffmpeg -i input.mp4 -ss 00:00:10 -t 10 -c:v libx264 -crf 18 out.mp4

The old story was: -ss before -i is fast but inaccurate, -ss after -i is slow but accurate. That changed with ffmpeg 2.1, which made input seeking frame-accurate when you are re-encoding. So in any modern ffmpeg (the current release is 9.1, from November 2026), -ss before -i is both fast and frame-accurate for a re-encode, and it is the better default: it seeks straight to a keyframe near the target instead of decoding the whole file up to that point.

The placement only really matters in two cases now. With -c copy, accuracy is bounded by keyframes no matter where -ss sits, so put it before -i for the speed. With a re-encode, before--i is faster and just as accurate; the after--i form (decode-and-discard from frame zero) is only worth reaching for if you hit a pathological file where input seeking misbehaves. If you want the legacy keyframe-only input-seek behavior back, -noaccurate_seek restores it.

Timestamp formats

ffmpeg accepts time values in two forms anywhere it wants a time (-ss, -to, -t):

  • HH:MM:SS.ms, for example 00:01:30.500 for one minute thirty and a half seconds. Hours and the fractional part are optional, so 01:30 and 90 and 00:01:30 all mean the same point.
  • Plain seconds, for example 90 or 90.5. Handy for short clips: -ss 5 -t 3 is "start at 5 seconds, keep 3."

Both work in either flag, so mix whichever reads more clearly. Sub-second precision (.ms) matters most on the re-encode path, where the cut can actually land on that exact frame.

Splitting one file into several segments

If the goal is to chop a long file into equal pieces rather than extract one clip, the segment muxer does it in a single pass without re-encoding:

bash
# Split into ~60-second chunks, stream-copied, cut at keyframes
ffmpeg -i input.mp4 -c copy -f segment -segment_time 60 -reset_timestamps 1 part%03d.mp4

The same keyframe rule applies: each split lands on the nearest keyframe, so the chunks are approximately 60 seconds, not exactly. For exact-length segments you would re-encode with a forced keyframe interval, but for most "break this up so it uploads" tasks the copy version is what you want.

FAQ

-to is an end position (stop at this point), and -t is a duration (run for this long). With -ss 00:00:10 -to 00:00:20 you get a 10-second clip; with -ss 00:00:10 -t 10 you also get 10 seconds. Those match when -to sits before -i next to -ss, because as an input option -to is a position in the source file. Move -to after -i while -ss stays before it and the output's timestamps start from zero at the seek point, so -to 00:00:20 gives a 20-second clip. The two flags are mutually exclusive, and if you pass both, -t takes priority. Mixing them up is the usual reason a clip comes out longer than expected.

Because -c copy can only cut on keyframes. ffmpeg snaps your start point back to the nearest keyframe at or before the time you asked for, so if the closest keyframe is a couple of seconds earlier, that is where the clip begins. Drop -c copy and re-encode for a frame-accurate start.

With -c copy, yes: the streams are copied without re-encoding, so there is no quality loss (the only constraint is keyframe-aligned cut points). If you re-encode for a frame-accurate cut, it is technically lossy, but a quality setting like -crf 18 for libx264 is visually near-transparent.

Before -i in almost every case. Since ffmpeg 2.1, input seeking is frame-accurate when re-encoding, so before--i is both fast and accurate. With -c copy the cut is keyframe-bounded wherever -ss sits, so before -i just gets you the speed.

Yes. ffmpeg is the same tool on every platform; only the install differs (brew install ffmpeg on macOS, the official builds or your package manager elsewhere). The commands above are identical. On Windows, run them in a real terminal rather than relying on a shell alias.

See also

Sources

Authoritative references this article was fact-checked against.

Tagsffmpegtrim videocut videoCLIvideo editingstream copykeyframe

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Systems and Network Architect · Chief Technology Officer

Systems and network architect and Chief Technology Officer with more than two decades designing, building, and running production software, cloud and network architecture, Linux systems, and the bare metal underneath them, and lately working AI into the stack. A US Army veteran who served in Operation Iraqi Freedom. What I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts

Extract a thumbnail or frame from a video with ffmpeg: fast -ss seek, the thumbnail filter, one frame every N seconds, -q:v 2, and a tiled contact sheet.

Extract a Thumbnail or Frame From a Video with ffmpeg

Grab a thumbnail or a single frame from a video with ffmpeg: pull a frame at a timestamp, let the thumbnail filter pick a representative one, sample one every N seconds, control JPEG quality with -q:v, and tile the samples into a contact sheet grid.