How to specify size of output image in FFmpeg command?
Asked Answered
E

2

8

I'm extracting frame images from an MP4 video using ffmpeg in terminal.

I used the command:

ffmpeg -i Video.MP4 Pictures%d.bmp

Problem is that the extracted images have a size of 4.5-5MB! I want smaller images, say around 1-2 MB. How do I limit the size of output images?

Epps answered 15/7, 2013 at 15:17 Comment(0)
A
23

The file size is a function of your video resolution and of the output format you choose. For example:

width x height x 3 bytes ( RGB24)

You have different ways to reduce the output file size.

  1. Change the format for example YUV 4:2:0 with -pix_fmt yuv420 and I think the smaller format you can choose is gray or yuv400 but check with the following command showing the ffmpeg supported pixel format

    ‘ffmpeg -pix_fmts

the BMP format should handle that (generate a 8bpp image) but confirm with the file size that you get a factor 3!

  1. Change the output resolution (HD to SD or CIF) with -s <Width>x<Height>, e.g.:

    ffmpeg -i Video.MP4 -s 192x168 Pictures%d.bmp
    

    or with the -vf option:

    ffmpeg -I Video.MP4 -vf scale=192:168 Pictures%d.bmp
    
Answer answered 15/7, 2013 at 16:42 Comment(2)
Thanks a lot, it worked! Just one more thing - is there any way that I can get the output images in 8-bit grayscale?Epps
yes there is, I edited my answer, have a look a the section 1.Answer
G
4

there is one more option you have to reduce filesize of the output pictures : Use another picture format like *.jpg.

ffmpeg -i input.flv -ss 00:00:14.435 -f image2 -vframes 1 out.jpg

(Source : http://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video)

Have a nice day ;)

Giovannagiovanni answered 16/7, 2013 at 1:45 Comment(1)
Thanks a lot mate, but I'm gonna have to go with changing the image size. I need the output in bitmap format, so cannot go for that option! Have a nice day :)Epps

© 2022 - 2024 — McMap. All rights reserved.