FFMPEG Correct Way to Fast Cut Video

Posted at

Following the two articles:
- FFMPEG Time-Range To Time-Diff Using JavaScript
- FFMPEG – Cut, Copy, Re-Encode – Faster!

here are the two commands you need to run,
to REALLY fast crop|cut videos,

say your range is 00:39:00.680-00:39:19.120

first run:
javascript:(function(zero,base,a,b,c,userin){if(null===userin)return;userin=userin.replace(/\\s*/g,"").split("-");a=Number(new Date(base+userin[0]));b=Number(new Date(base+userin[1]));c=new Date(b-a+zero);c=("00"+c.getHours()).substr(-2)+":"+("00"+c.getMinutes()).substr(-2)+":"+("00"+c.getSeconds()).substr(-2)+"."+("000"+c.getMilliseconds()).substr(-3);prompt("☆ RANGE:  "+userin.join("")+"\
"+"∆ DIFF: "+c+"\
",c)})(Number(new Date("2016-01-01 "+"00:00:00.000")),"2016-01-01 ",null,null,null,prompt("FFMPEG Compatible Range2Diff","00:39:00.680-00:39:19.120"));

and get the diff: 00:00:18.440

there is a trick to use -ss!

you use it twice!
first before the file name- with HH:MM:00.00 so it will JUMP FAST to the ~sort of~ correct place,
next after the -i myVideo.mp4 you specify -ss 00:00:SS.sss to do exact cut,
this way you do not have to wait A LOT OF TIME for FFMPEG to get to the accurate place (from the start of the file!)

ffmpeg -ss "00:39:00.000" -i myVideo.mp4 -vcodec copy -acodec copy -ss "00:00:00.680" -g 1 -t "00:00:18.440" cut.mp4

now to "cure" any jump'iness re-encode the cut.mp4 file don't forget the -g 1 switch!
ffmpeg -i cut.mp4 -g 1 cutFixed.mp4

it all should be very fast!

less fast, but rebuild index, fix framing and de-interlace (with very little quality/size change) in one go!:
ffmpeg -ss "00:39:00.000" -i myVideo_in.mp4 -ss "00:00:00.680" -t "00:00:18.440" -vf "yadif=0:-1:0" -vsync 2 -async 1 myVideo_out.mp4

adding -g 1 will increase the size and damage the quality a little bit but will ease streaming and processing (youtube..)
ffmpeg -ss "00:39:00.000" -i myVideo_in.mp4 -ss "00:00:00.680" -t "00:00:18.440" -vf "yadif=0:-1:0" -vsync 2 -async 1 -g 1 myVideo_out.mp4