-1

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: 1200x800, quality: excelent --> cropped images: 300x300 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?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 3
    There are several problems with this question. First, we don't know what you need, so we can't tell you what to do. "without losing too much quality" is a meaningless statement. What is "too much" for you can be vastly different for the next person. Second, we aren't here to do your work for you, we're here to help you. So you need to show what you've already attempted, and explain a specific problem you need help solving. – Jonathan Hall Jun 25 '19 at 12:50

2 Answers2

0

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

L. Scott Johnson
  • 4,213
  • 2
  • 17
  • 28
0

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
llogan
  • 121,796
  • 28
  • 232
  • 243