简体   繁体   中英

How to get equal segment times using ffmpeg?

I used the following command to split a video into segments :

ffmpeg -i inputfile -c copy -map 0 -segment_time 5 -f segment outputfile

But I got varying segment times ie. some segments were 5s, some were 2s and others were 8s. How do I correct this ?

You Cant achieve this unless you re-encode this. ffmpeg will do its best to split close to the time you specified for each segment. This is based in key_frames it will find the closest key frame and cut there. In order to cut exact segments you will need to re encode the whole video.

$ ffmpeg -i input.mp4 -c:v libx264 -crf 22 -map 0 \
    -segment_time XX \
    -g 9 \
    -sc_threshold 0 
    -force_key_frames "expr:gte(t,n_forced*9)" \
    -f segment output%03d.mp4

NOTE: XX: Specifies your time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM