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

社会主义新天地 提交于 2019-12-02 23:33:34

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
Dhiraj Gupta

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!