如何从H264视频文件和ffmpeg中提取优质JPEG图像?

时间:2021-01-25 21:22:28

Currently I am using this command to extract the images:

目前我正在使用这个命令来提取图像:

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

ffmpeg。exe - 10 fps。h264 - r10 -f image2 10fps.h264_%03d.jpeg。

But how can I improve the JPEG image quality?

但是如何提高JPEG图像的质量呢?

1 个解决方案

#1


119  

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.

使用-qscale:v(或别名-q:v)作为输出选项。JPEG的有效范围是2-31,其中31是最差的质量。我建议尝试2-5的值。

You can add -huffman optimal for a small, but measurable decrease in output file size.

您可以将-huffman优化为一个小的,但可测量的输出文件大小的减少。

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 -huffman optimal output.jpg

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

这将与任何视频输入一起工作。如果您的输入是MJPEG,请参阅下面的内容。


MJPEG

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

如果您输入的是MJPEG(动作JPEG),那么可以在没有任何质量损失的情况下提取图像。

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

ffmpeg或ffprobe控制台输出可以告诉您输入是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:

然后您可以使用mjpeg2jpeg bitstream过滤器来提取帧:

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

Also see

#1


119  

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.

使用-qscale:v(或别名-q:v)作为输出选项。JPEG的有效范围是2-31,其中31是最差的质量。我建议尝试2-5的值。

You can add -huffman optimal for a small, but measurable decrease in output file size.

您可以将-huffman优化为一个小的,但可测量的输出文件大小的减少。

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 -huffman optimal output.jpg

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

这将与任何视频输入一起工作。如果您的输入是MJPEG,请参阅下面的内容。


MJPEG

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

如果您输入的是MJPEG(动作JPEG),那么可以在没有任何质量损失的情况下提取图像。

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

ffmpeg或ffprobe控制台输出可以告诉您输入是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:

然后您可以使用mjpeg2jpeg bitstream过滤器来提取帧:

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

Also see