How to extract the 1st frame and restore as an image with ffmpeg?

lex picture lex · Dec 13, 2010 · Viewed 44.9k times · Source

Anyone knows the trick?

And how to install ffmpeg ? yum install mpeg only returns this:

======================================================================================== Matched: mpeg ========================================================================================
libiec61883.i386 : Streaming library for IEEE1394
libiec61883.x86_64 : Streaming library for IEEE1394
qffmpeg-devel.i386 : Development package for qffmpeg
qffmpeg-devel.x86_64 : Development package for qffmpeg
qffmpeg-libs.i386 : Libraries for qffmpeg
qffmpeg-libs.x86_64 : Libraries for qffmpeg

Answer

jcomeau_ictx picture jcomeau_ictx · Dec 13, 2010

It's on the manpage:

* You can extract images from a video, or create a video from many
       images:

       For extracting images from a video:

               ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg

       This will extract one video frame per second from the video and will
       output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images
       will be rescaled to fit the new WxH values.

       If you want to extract just a limited number of frames, you can use
       the above command in combination with the -vframes or -t option, or in
       combination with -ss to start extracting from a certain point in time.

But of course you have to install it first. I'm on Debian and don't use yum.

[update for the other question]


i=1
for avi in *.avi; do
 ffmpeg -i $avi -vframes 1 -f image2 /tmp/$i.jpg; i=$((i+1))
done

Tested and works.

[update for yet another question...]


for flv in *.flv; do
 ffmpeg -i $flv -vframes 1 -f image2 ${flv%%.flv}.jpg
done