Extract clip from video and convert to a bunch of formats

Alec Jacobson

May 23, 2010

weblog/

I've been interested in using video for everybody for which you need a .mp4, .ogv and .flv version of your video. To suck out this clip of Cary Grant from Notorious I used mencoder with the following command:

mencoder -endpos 00:00:01.38 -ss 00:05:35 -of lavf -oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 notorious.1946.x264.mkv -o cary-grant-eyes.flv

That makes a .flv file of a clip from this movie starting at 5m35 seconds and lasting 1.38 seconds. To convert this to a quicktime compatible .mp4 file I use the following ffmpeg command:

ffmpeg -i cary-grant-eyes.flv -vcodec libx264 -vpre libx264-lossless_max cary-grant-eyes.mp4

Finally to convert that .mp4 file to a firefox compatibly .ogv file I use the following ffmpeg2theora command:

ffmpeg2theora cary-grant-eyes.mp4 -o cary-grant-eyes.ogv

Note: It really seems like I should be able to do each of these straight from mencoder but I couldn't figure out how.

Update: I think is the right way to do it (losslessly) with ffmpeg

ffmpeg -ss 1:42:11 -i JFK.DirCut.1991.1080p.BluRay.DTS.x264-ESiR.mkv -acodec copy -vcodec copy -t 00:00:02.4 joe-pesci-jfk-honk.mkv

This makes a 2.4 second clip starting from 1:42:11 in the movie JFK: