FFmpeg trim video: accurate cuts by time
To trim a video with FFmpeg you choose between a fast cut that copies the streams and an accurate cut that re-encodes. The fast cut can start on the nearest keyframe, so it may land early. This page gives the command for each, explains why, and shows how to check that the cut landed where you wanted.
Fast cut or accurate cut
FFmpeg can cut a clip two ways. A fast cut copies the existing video data and does not re-encode it. An accurate cut decodes and re-encodes, so it can start on any frame. Fast is about the speed of copying a file; accurate takes as long as an encode. The price of fast is that it can only start where the video has a keyframe.
Every command on this page was run by us on test files. Our main test file, a.mp4, is 10.000 seconds long, 1280x720 at 30 frames per second, H.264 video with AAC audio, and we gave it a keyframe every 2 seconds so the effect is easy to see. Make it with this command:
ffmpeg -f lavfi -i testsrc2=duration=10:size=1280x720:rate=30 -f lavfi -i sine=frequency=440:duration=10:sample_rate=48000 -c:v libx264 -pix_fmt yuv420p -g 60 -keyint_min 60 -sc_threshold 0 -c:a aac -shortest a.mp4| Method | Command | Result on our test file |
|---|---|---|
| Fast cut (no re-encode) | ffmpeg -ss 3 -i a.mp4 -t 4 -c copy fast.mp4 | File length 4.133 s, not 4.000 s. It contains 152 video packets, the first one 1.000 s before the start we asked for. |
| Accurate cut (re-encode) | ffmpeg -ss 3 -i a.mp4 -t 4 -c:v libx264 -c:a aac accurate.mp4 | File length 4.000 s, 120 frames. Its first frame matches the source frame at 3.0 s (PSNR 42.7 dB) and does not match the frame at 2.0 s (16.8 dB). |
Rule of thumb: use a fast cut for rough cuts and for splitting long recordings where a second either way does not matter. Use an accurate cut when the cut point must be exact, for example on a word boundary.
We ran each command with -y added, so it could overwrite old test files. It is left out below; add it if you want FFmpeg to overwrite without asking.
Trim with start and end times
Start time is -ss. For the end, use either a duration with -t, or an end time with -to. The two behave differently depending on where you put -ss, and that is the most common mistake.
ffmpeg -i a.mp4 -ss 3 -to 7 -c:v libx264 -c:a aac startend.mp4On our test file this gave 4.000 s, as expected. Now the same idea with -ss before the input:
ffmpeg -ss 3 -i a.mp4 -to 7 -c:v libx264 -c:a aac startend2.mp4That gave 7.000 s. When -ss comes before -i, timestamps restart at zero from the seek point, so -to 7 means 7 seconds after the start, not second 7 of the source. To avoid the trap, either put -ss and -to together after the input, or use -t for a duration.
ffmpeg -ss 3 -i a.mp4 -t 4 -c:v libx264 -c:a aac accurate.mp4Times can be seconds (3.5) or hours:minutes:seconds (00:00:03.5).
Trim without re-encoding
Add -c copy to copy the streams without re-encoding. It is quick and it does not lose quality. It also behaves differently from an accurate cut. These are our measurements on a.mp4, whose keyframes are at 0, 2, 4, 6 and 8 seconds.
| Command | What we measured |
|---|---|
| ffmpeg -ss 3 -i a.mp4 -t 4 -c copy fast.mp4 | MP4 length 4.133 s. FFmpeg's own playback of it starts at the 3.0 s frame, because the MP4 hides the extra second with an edit list. The first packet in the file is stamped -1.000 s. |
| ffmpeg -ss 4 -i a.mp4 -t 4 -c copy keyframe_cut.mp4 | Start on a keyframe. MP4 length 4.067 s, 122 frames, first frame is the source frame at 4.0 s. |
| ffmpeg -i a.mp4 -ss 3 -t 4 -c copy fast_after.mp4 | -ss after -i with copy. Video stream started at 1.000 s while audio started at 0.008 s, 92 frames, and the first picture was the source frame at 4.0 s, not 3.0 s. Avoid this combination. |
| ffmpeg -ss 3 -i a.mp4 -t 4 -c copy fast.mkv | Same cut into MKV. ffprobe reported 5.213 s, 152 frames, and the first frame was the source frame at 2.0 s. |
To cut exactly with no re-encode, choose a start time that sits on a keyframe. List the keyframes of a file with the ffprobe command on this page's keyframe section, and use one of those times. If your cut point is not on a keyframe, use an accurate cut.
We ran each command with -y added, so it could overwrite old test files. It is left out below; add it if you want FFmpeg to overwrite without asking.
Trim with frame accuracy
When the cut must fall on an exact frame, re-encode. Two ways worked in our tests. Both took 4 seconds from a 30 frames per second file and gave 120 frames.
ffmpeg -ss 3 -i a.mp4 -frames:v 120 -c:v libx264 -c:a aac -af atrim=duration=4 frames120.mp4ffmpeg -i a.mp4 -vf "trim=start_frame=90:end_frame=210,setpts=PTS-STARTPTS" -af "atrim=start=3:end=7,asetpts=PTS-STARTPTS" trimfilter.mp4In the trim filter, end_frame is not included, so start_frame=90 and end_frame=210 keeps 120 frames. The setpts and asetpts parts reset the timestamps to start at zero; leave them out and the output may start late or carry a gap. Keep the audio trim in step with the video trim, or the sound will be off.
Why a cut can start a second early
A fast cut can only begin where a keyframe is, because the frames after a keyframe depend on it. If you ask for 3.0 s and the nearest keyframe before it is at 2.0 s, FFmpeg starts the data at 2.0 s. See the keyframes of our test file:
ffprobe -v error -select_streams v:0 -skip_frame nokey -show_entries frame=pts_time -of csv=p=0 a.mp4It printed 0.000000, 2.000000, 4.000000, 6.000000 and 8.000000. We asked for a cut at 3.0 s. What each container did with it:
- MKV and MPEG-TS: 152 frames, and the first frame was the source frame at 2.000 s, one second early. ffprobe reported 5.213 s for both files.
- MP4 with -avoid_negative_ts make_zero added: 152 frames, first frame at 2.000 s, 5.147 s long.
- MP4 by default: the file also holds the extra second, but marks it with a negative start time (-1.000 s for the first packet). Players that follow that mark begin at 3.0 s. Other tools may show the early frames or report a longer duration. FFmpeg's own decoder began at the 3.0 s frame.
Fixes: choose a start that is on a keyframe; or re-encode (accurate cut); or, when you make the files yourself, set a shorter keyframe interval so there is a keyframe near where you will cut. In our test files we used -g 60 for a keyframe every 2 seconds at 30 fps.
The gap depends on how the video was encoded. We saw a full second because our test keyframes are 2 seconds apart. Check your own files.
Check the cut
Do not trust the file name. Check the length, the frame count and the first frame.
ffprobe -v error -show_entries format=duration:stream=codec_type,start_time,duration -of compact accurate.mp4ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of csv=p=0 accurate.mp4ffmpeg -v error -i accurate.mp4 -f null -ffprobe -v error -select_streams v:0 -show_entries packet=pts_time,flags -of csv=p=0 -read_intervals %+0.5 fast.mp4To prove which source frame a cut starts on, write per-frame checksums of the source and the cut, then match them. We did this with the following two commands and compared the lists with a short Python script. The first frame of fast.mp4 matched source frame 90 (3.000 s), and the first frame of our MKV copy matched source frame 60 (2.000 s).
ffmpeg -v error -i a.mp4 -an -f framemd5 a.md5ffmpeg -v error -i fast.mkv -an -f framemd5 fast.mkv.md5Then play the first and last 2 seconds in a player, and listen to the audio at the cut.
Method and limits
All tests ran on FFmpeg 8.1.2 (a full Windows build) and ffprobe 8.1.2, on Windows 11. We made the test files ourselves with FFmpeg's built-in test sources, so there is no camera footage in any test.
Each measurement comes from one test file with a keyframe every 2 seconds, so the one-second gap is a property of that file. Copy cuts depend on the FFmpeg version, the container and the encoder, so your numbers may differ; check yours with the commands above. We did not test camera footage, variable frame rate files, or other codecs. We did not time the commands.
The complete list of commands we ran, with what ffprobe reported, is in the data for this site. We ran each command with -y added, so it could overwrite old test files. It is left out below; add it if you want FFmpeg to overwrite without asking.
Related: Join videos with FFmpeg without errors, FFmpeg command builder and FFmpeg for video editors.
Each command comes with the sample clip it was run on, the exact output and a check of where the cut landed. The FFmpeg version is stated next to every command.
- Cut accuracy depends on the source codec and keyframe spacing, so results on your file may differ.
- Behaviour can change between FFmpeg versions.
Page checked on Oct 10, 2026.