I'm using the following command to create thumbnails with FFMPEG:
ffmpeg -itsoffset -1 -i video.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 240x180 image.png
And it works fine. However, when the video isn't 4:3 ratio, it will still create a 240x180 image, and the extra space will be painted black. Is there some variation of the command that will prevent this and give me an image proportional to the video's ratio? In other words, I want 240x180 to be the maximum size of the thumbnail, but not the minimum.
Extra points if the command creates a smaller image when the video is smaller than 240x180.
Thumbnails & Screenshots using FFmpeg – 3 Efficient Techniques 1 Periodic Screenshot/Thumbnail with Resizing. Here is another common use case that FFmpeg can solve easily – how do you take screenshots/thumbnails at regular intervals, and store them to JPG files ... 2 Screenshot/Thumbnail every 10 seconds. ... 3 Conclusion. ...
Here is another common use case that FFmpeg can solve easily – how do you take screenshots/thumbnails at regular intervals, and store them to JPG files after resizing them? Here is a simple one-liner that can take care of creating a thumbnail and resizing it for you.
The other answers are fine... but for most "video" content, JPEG is a more space-efficient choice for a thumbnail image. This answer discusses JPEG quality settings.
The above answers are great, but most of them assume specific video dimensions and don't operate on a generic aspect ratio. You can pad the video to fit any aspect ratio, regardless of specific dimensions, using this: I use the ratio 16/9 in my example.
Use the scale
filter:
ffmpeg -itsoffset -1 -i video.avi -vframes 1 -filter:v scale="280:-1" image.png
This will preserve the aspect ratio to achieve a width of 280 pixels. To increase the width to a maximum of 280 pixels but preserve the ratio, use:
scale='min(280\, iw):-1'
Here, we'll just assume that your video is in landscape format, so we can set the maximum width to 280 and forget about the height, which should be 180 for a 3:2 video and 158 for 16:9 content.
Notes:
-vcodec mjpeg
doesn't make sense when you're writing to a PNG file-f rawvideo
doesn't do anything here either-an
is not needed because FFmpeg can't write audio to a PNG fileIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With