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

FfmpegFlv

Ffmpeg Problem Overview


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

Ffmpeg Solutions


Solution 1 - Ffmpeg

I've cobbled up this command line from various answers that works great for me to get the absolutely first frame out from a video. I use this to save a thumbnail screenshot for the video.

ffmpeg -i inputfile.mkv -vf "select=eq(n\,0)" -q:v 3 output_image.jpg

Explanation:

The select filter -vf "select=eq(n\,0)" is to select only frame #0.

-q:v allows you to set the quality of the output jpeg between 1 and 31. Lower the number, higher the quality. 2 - 5 works good, I use 3.

Note: This will get you an image with the same size as the video. To get a thumbnail, you can use the scale filter to get a thumbnail to fit whatever width you need, like so:

ffmpeg -i inputfile.mkv -vf "select=eq(n\,0)" -vf scale=320:-2 -q:v 3 output_image.jpg

The above command will give you a thumbnail jpeg that will be scaled to match width of 320, and height will be calculated to match the aspect ratio.

Solution 2 - Ffmpeg

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

Solution 3 - Ffmpeg

An easy to grok solution that works for me is

ffmpeg -i <input> -vframes 1 <output>.jpeg

Note that I do get an error "[swscaler @ 0x111652000] deprecated pixel format used, make sure you did set range correctly" but according to a little reading (see for example https://stackoverflow.com/a/43038480/1241736) that can safely be ignored.

Solution 4 - Ffmpeg

It's works for me

ffmpeg -i sample-mp4-file.mp4 -ss 1 -vframes 1 output.jpg

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlexView Question on Stackoverflow
Solution 1 - FfmpegDhiraj GuptaView Answer on Stackoverflow
Solution 2 - Ffmpegjcomeau_ictxView Answer on Stackoverflow
Solution 3 - FfmpeghenryView Answer on Stackoverflow
Solution 4 - FfmpegMohamed AbbasView Answer on Stackoverflow