I have one video with duration of one minute and 35 seconds. I am able to split it into multiple 30 second segments (I am fully aware of other ways to split a video but chose this for a particular reason). However, this yields 3 videos, 30 seconds long, and one video, 5 seconds long. What would be the best way to eliminate a straggling video that is less than 15 seconds and append to segments?

split to segments

ffmpeg -i test.mp4 -codec:v copy -codec:a copy -segment_time 30 test-%03d.mp4


ffprobe -i test.mp4 -show_format -v quiet | grep '.=.'
  • So you want the segments to be 30, 30, 20 and 15 seconds long? – slhck May 4 '15 at 6:36
  • @slhck Yes, you are correct! – MaryCoding May 4 '15 at 12:42

ffmpeg on its own cannot do that. You have to figure out the duration of the individual segment yourself, as there's no way to specify a minimum duration.

For this you'd probably iterate over the total length of the video twice. In the first run, determine the length of the segments. If you find that the last segment is shorter than, say, 15 seconds, you simply have to adjust the length of the second to last one. This can be easily done with scripting languages.

Once you have that, you need to tell the segment muxer the individual segment durations:

-segment_times 0,30,60,80
  • ok, makes more sense this way. currently the way i am segmenting the video i have to spcify this expr:gte(t,n_forced*30) to exactly get the segment the correct length of 30 seconds. How can i specify expr:gte(t,n_forced*x) for multiple segments ? – MaryCoding May 4 '15 at 20:03
  • I would just pick the least common denominator, e.g. 5 seconds. It's fine if you force a keyframe every 1–10 seconds. – slhck May 4 '15 at 21:53

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.