I need to trim videos with a precise end frame, however, ffmpeg seems to cut the video at the nearest first key-frame. So I don't have enough control over the ending frame. I try to insert key-frame before trimming, but it doesn't work. These are my command lines:

ffmpeg -i <sVideoFilename> -force_key_frames 00:00:1:520 -vcodec wmv1 -acodec wmav2 -q:a 0 -q:v 0 <sVideoFilenamekf>

ffmpeg -i <sVideoFilenamekf> -ss 00:00:1:520 -to 00:00:3:640 -vcodec wmv1 -acodec wmav2 -q:v 0 -q:a 10 -r 30 <sVideoFilenameTrimmed>*

What's wrong with my command line ? Thanks for your answer

  • I updated the question to reflect that you are looking for frame level precision rather than millisecond precision. That may pull in more answers. I don't personally know FFMPEG all that well as I always use other commercial encoders. – AJ Henderson Jun 12 '13 at 13:28

You seem to have a fundamental misunderstanding of how video works. Video is composed of frames. You can't have millisecond precision because video doesn't have millisecond precision. If there are 30 frames per second in the video, you can only stop after one of those frames. That means your options are only every 1/30th of a second roughly. If the format is group of pictures based it may be limited when it can end as well depending on the formats ability to end a group of pictures early. (A group of pictures is used in formats where some frames are stored as changes from other related frames rather than full images.)

What are you trying to accomplish that you need this precision for? Perhaps there may be an alternate way to accomplish your goal.

  • 1
    I need to synchronize the video with another machine. The video is too much longer and i need to trim it (just need 2s). I don't have 1/30th of a second precision (~=33ms). I cut between 1062ms and 3640ms but i get a video length of 2130ms (not 2578 as planned). I can send you the video if you want to test it. Thanks for your answer. – RMI Jun 12 '13 at 8:25
  • @RMI - Maybe I'm not reading your command lines correctly, but they say a start point of 1520ms, not 1062ms. This makes the output of 2130ms correct. – AJ Henderson Jun 12 '13 at 13:36
  • 1
    If i trim with the first parameters (1520 to 3640) i have an length error too > than 1/30. I try with another video, it's the same problem. Perhaps the problem is the video codec. – RMI Jun 13 '13 at 9:49
  • @RMI - what is the result with the first parameter at 1520? – AJ Henderson Jun 13 '13 at 13:19
  • 2s197 with or without keyframe – RMI Jun 14 '13 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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