如何在C/C ++中设置ffmpeg qscale以进行图像编码 [英] How to set ffmpeg qscale in C/C++ for image encoding
问题描述
我有一个使用ffmpeg作为后端的C ++工作图像编码器.我正在接收视频并将帧保存为jpeg,但是在调整输出jpeg的质量时遇到困难.
我尝试过的事情:
设置 AVCodecContext
的 global_quality
和 compression_level
字段.
我也尝试过使用选项 AVDictionary
设置 qscale
,但是在那里也没有成功.
I have a working image encoder in C++ using ffmpeg as the backend. I am taking videos in and saving frames out as jpeg, but I am having difficulty adjusting the quality of the output jpegs.
Things I have tried:
Setting AVCodecContext
's global_quality
and compression_level
fields.
I have also tried setting qscale
with an AVDictionary
of options, but have been unsuccessful there too.
我知道这是可能的,因为通过命令行我可以 ffmpeg -i INPUT -q:v 2 output_frame_%02d.jpg
并获得更高质量的图像.
I know its possible because with the command line I can
ffmpeg -i INPUT -q:v 2 output_frame_%02d.jpg
and get higher quality images.
推荐答案
命令行 -q
选项会影响两件事
The command line -q
option effects two things
enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
其中enc_ctx是输出流的AVCodecContext,而FF_QP2LAMBDA是118
where enc_ctx is the AVCodecContext for the output stream and FF_QP2LAMBDA is 118
这篇关于如何在C/C ++中设置ffmpeg qscale以进行图像编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!