6

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?

Anthony
  • 317
  • 1
  • 5
  • 23

1 Answers1

7

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.

JPG

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.

PNG

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.

Community
  • 1
  • 1
llogan
  • 121,796
  • 28
  • 232
  • 243
  • What is the -o7, and how long does the png opti take. There's this counter that's going on for a while like `zc = 6 zm = 9 zs = 1 f = 2`. Do I have to wait until f get's to 7 or something? – Sam Jun 07 '20 at 23:50
  • After running the optipng command I think my image is actually bigger by .2 mb – Sam Jun 08 '20 at 00:19
  • @Sam `-o` sets the optimization level with 7 being the highest and most time consuming. If it is bigger perhaps the image was already fully optimized, or try another tool as mentioned in the answer. – llogan Jun 08 '20 at 21:13