How can I extract a good quality JPEG image from an H264 video file with ffmpeg?

南笙酒味 提交于 2019-11-26 19:26:33

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!