How can I extract a good quality JPEG image from a

2020-01-25 12:42发布

问题:

Currently I am using this command to extract the images:

ffmpeg.exe -i 10fps.h264 -r 10 -f image2 10fps.h264_%03d.jpeg

But how can I improve the JPEG image quality?

回答1:

Use -qscale:v

Use -qscale:v (or the alias -q:v) as an output option. Effective range for JPEG is 2-31 with 31 being the worst quality. I recommend trying values of 2-5.

To output a series of images:

ffmpeg -i input.mp4 -qscale:v 2 output_%03d.jpg

To output a single image at ~60 seconds duration:

ffmpeg -ss 60 -i input.mp4 -qscale:v 4 -frames:v 1 output.jpg

This will work with any video input. See below if your input is MJPEG.


MJPEG

If you input is MJPEG (Motion JPEG) then the images can be extracted without any quality loss.

The ffmpeg or ffprobe console output can tell you if your input is MJPEG:

$ ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nw=1 input.avi
codec_name=mjpeg

Then you can extract the frames using the mjpeg2jpeg bitstream filter:

$ ffmpeg -i input.avi -codec:v copy -bsf:v mjpeg2jpeg output_%03d.jpg

Also see

  • FFmpeg FAQ: How do I encode movie to single pictures?
  • FFmpeg Wiki: Create a thumbnail image every X seconds of the video


回答2:

Output the images in a lossless format such as PNG:

ffmpeg.exe -i 10fps.h264 -r 10 -f image2 10fps.h264_%03d.png

Then use another program (where you can more precisely specify quality, subsampling and DCT method – e.g. GIMP) to convert the PNGs you want to JPEG.

It is possible to obtain slightly sharper images in JPEG format this way than is possible with -qmin 1 -q:v 1 and outputting as JPEG directly from ffmpeg.