如何从带有ffmpeg的H264视频文件中提取高质量的JPEG图像? [英] How can I extract a good quality JPEG image from an H264 video file with ffmpeg?
问题描述
目前我正在使用此命令提取图片:
ffmpeg.exe -i 10fps.h264 -r 10 -f image2 10fps.h264_%03d.jpeg
但是如何提高JPEG图片质量?
-qscale:v > code> -qscale:v
(或别名 -q:v
)作为输出选项。 JPEG的有效范围是2-31,31是最差的质量。我建议尝试2-5的值。 要输出一系列图片:
ffmpeg -i input.mp4 -qscale:v 2 output_%03d.jpg
以约60秒的持续时间输出单个图像:
ffmpeg -ss 60 -i input.mp4 -qscale:v 2 - vframes 1 output.jpg
这将适用于任何视频输入。
MJPEG
ffmpeg
如果您输入的是MJPEG(Motion JPEG)或 ffprobe
控制台输出可以告诉您输入是否为MJPEG:
$ ffprobe -v error -select_streams v:0 -show_entries stream = codec_name -of default = nw = 1 input.avi
codec_name = mjpeg
然后,您可以使用 mjpeg2jpeg
比特流过滤器:
$ ffmpeg -i input.avi -codec:v copy -bsf:v mjpeg2jpeg output_%03d.jpg
另请参阅
- FFmpeg常见问题:如何将电影编码为单张图片?
- FFmpeg Wiki:每X秒创建一个缩略图视频
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?
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 2 -vframes 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
这篇关于如何从带有ffmpeg的H264视频文件中提取高质量的JPEG图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!