skip to Main Content

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


  1. 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).

    ffmpeg -i <input> -q:v 8 <output.jpg>
    

    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

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search