如何在C/C ++中设置ffmpeg qscale以进行图像编码 [英] How to set ffmpeg qscale in C/C++ for image encoding

查看:158
本文介绍了如何在C/C ++中设置ffmpeg qscale以进行图像编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆