Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ffmpeg

flv

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 
like image 926
lex Avatar asked Dec 13 '10 02:12

lex


People also ask

How do I extract a frame from a video using FFmpeg?

Use the FFmpeg executable with the seek option. You'll need to convert to a time first, e.g. if I want frame 150 and my video is 29.97 FPS the command will be ffmpeg -ss 00:00:05.01 -i myvideo. avi -frames:v 1 myimage.


1 Answers

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.

like image 140
Dhiraj Gupta Avatar answered Oct 06 '22 01:10

Dhiraj Gupta