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. See ffmpeg -h encoder=mjpeg
and look for the -huffman
option to see if your version supports this.
Alternatively, Huffman optimization may be performed by jpegtran
:
jpegtran -optimize -copy none -perfect input.jpg > output.jpg
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
ffmpeg -i input -vf "crop=300:300,format=yuvj420p" -q:v 3 -frames:v 1 output.jpg