I have high quality images 8mp+ and need to reduce their size as much as I can without loosing too much quality. Photoshop and the similar have a “save for web” features that works great.
How do I accomplish this with ffmpeg? Images are JPG
Actually, I need the images to be cropped from the center.
so
original image: 1200×800, quality: excelent
–> cropped images: 300×300 from center of original image, quality: excelent
—-> save for web cropped images, quality: save for web
what are the ffmpeg commands I need to run?
2
Answers
You need to specify the quality setting with the
-q:v
flag, which takes a numerical argument from 1 (best, largest) to 31 (worst, smallest).It’s up to you to figure out what quality setting is “good enough” and “small enough”.
For the addendum question, see http://ffmpeg.org/ffmpeg-filters.html#crop
JPEG quality
-q:v
See the
-q:v
option in How can I extract a good quality JPEG image from an H264 video file with ffmpeg?Optimization
Make sure you’re using a recent
ffmpeg
which will enable Huffman optimization by default. This can result in a small file size reduction. Seeffmpeg -h encoder=mjpeg
and look for the-huffman
option to see if your version supports this.Alternatively, Huffman optimization may be performed by
jpegtran
:Pixel format
I’m guessing Photoshop’s “Save for Web” only outputs yuvj420p pixel format, while
ffmpeg
will choose a pixel format (yuvj420p, yuvj422p, or yuvj444p) that most closely matches the input pixel format. You can force yuvj420p with the format filter. This will result in a smaller file size but may also accentuate artifacts in certain areas, but you may not notice a difference.crop filter
Use the crop filter. Default is to center the crop, so just use
-vf crop=300:300
.Example command