Google PageSpeed recommends the images on my web page could be optimized. The lossless compression would save an average of 11%, however my images are created with the following FFmpeg command:
ffmpeg -i '$video_path' -vcodec mjpeg -vframes 1 -an -f rawvideo -ss 00:00:20 -s 145*108 $thumb_image
Is there a way I can optimize these images?
First of all -s 145*108
is not a valid ffmpeg option; it should be -s 145x108
. For proper scaling of your images see the answer to How to create thumbnail image from .flv video by using ffmpeg? for some examples that will keep your aspect ratio. You did not specify your image type, so I'll assume you are outputting to jpeg. You can change the output quality with -qscale:v
(or -qscale
if using old ffmpeg syntax). Range for jpeg is a linear scale of 1-31 where 1 is best quality and 31 is worst quality.
As for losslessly optimizing jpeg, you can use jpgcrush
or jpegtran
:
jpegtran -optimize -copy none -perfect -v input.jpg > output.jpg
I've noticed that Opera doesn't properly display images processed with jpgcrush
but this was some time ago that I checked.
For png you have a variety of tools including pngcrush
, optipng
, and advpng
among several others:
optipng -o7 input.png
Remember that FFmpeg usage questions are better suited for superuser.
If 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