Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm having trouble finding a cli application that can take a video file (avi, mkv, and mp4 preferably) and cut out very short clips (2-6 seconds) with precision time accuracy. I've tried ffmpeg, mencoder, avidemux, and mp4box but they all cut on keyframes which creates 6+ second clips. Is there a tool that will re-encode the input file and cut the accurate time or cut inaccurately, re-encode, and then cut accurately?

share|improve this question
You'll probably have to reencode before cutting to get it right. You could probably speed things up by first cutting out the surrounding keyframes and only reencode the snippets. – Nifle Aug 7 '12 at 18:19
Which FFmpeg command have you tried, exactly? I believe if you decode the video before (i.e. place the -ss parameter after -i), it should be more accurate. – slhck Aug 7 '12 at 18:19
The FFmpeg trick worked! I didn't realize the order mattered so much. Is this the same for any of the other tools? – curmil Aug 7 '12 at 19:30

2 Answers 2

up vote 12 down vote accepted

You can accurately cut videos with FFmpeg. Since version 2.5 it's very easy. This would for example cut 5 seconds, starting from 5 minutes, 3 seconds and 123 milliseconds.

ffmpeg -ss 00:05:03.123 -i input.mp4 -t 5 -c:v libx264 -c:a libfaac out.mp4

The position may be either in seconds or in hh:mm:ss[.xxx] form. You can also use -to instead of -t to specify the end point instead of the duration.

See also the Seeking wiki entry.

If you have an older version of ffmpeg, then for accurate seeking, you need to place the -ss after -i, which makes the encoding process a little slower, because the entire video has to be decoded first:

ffmpeg -i input.mp4 -ss 00:05:03.123 -t 5 -c:v libx264 -c:a libfaac out.mp4

Note that in these examples, video and audio will be re-encoded. You can try copying over the audio stream with -c:a copy too. Copying the video stream will – in most cases – not work properly because then you could only cut at keyframes, which don't occur so often in a video.

share|improve this answer
Instead of -c:v libx264 -c:a libfaac I think we can use -acodec copy -vcodec copy which tells ffmpeg just to detect and use the same codecs as the original file. Can anyone confirm? – Baodad Jan 23 at 4:31
@Baodad You can, but this will not accurately cut. When copying video/audio bitstreams, ffmpeg needs to start at a keyframe, which may just be placed at every second or even further apart. – slhck Jan 23 at 7:14
How do overcome the "Unknown encoder 'libfaac'" error? – Doug Apr 24 at 3:16
@Doug Choose a different encoder, for example -c:a aac -strict experimental. That's the simplest solution. – slhck Apr 24 at 6:34

Like Baodad said in the comments (I post because it's not easy to find if you read quickly), the better approach is to detect the audio/video encoders automatically by ffmpeg, so :

ffmpeg -ss 00:05:17.18 -i in.mp4 -t 00:06:29.10 -acodec copy -vcodec copy out.mp4 
  • start @ 00:05:17.18
  • input = in.mp4
  • stop @ 00:06:29.10
  • output = out.mp4
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.