[Libav-user] How to pass quality scale to mjpeg encoder

Carl Eugen Hoyos ceffmpeg at gmail.com
Thu Jan 25 23:43:36 EET 2018


2018-01-25 15:54 GMT+01:00 Tobias Rapp <t.rapp at noa-archive.com>:
> On 25.01.2018 09:25, Tobias Rapp wrote:
>>
>> Hi,
>>
>> trying to do the equivalent of FFmpeg command-line output option "-q:v 3"
>> on library level I came up with the following code (error checking stripped
>> off):
>>
>>      AVCodecContext *enc_ctx = NULL;
>>      const AVCodec *codec = avcodec_find_encoder_by_name("mjpeg");
>>      int ret;
>>
>>      enc_ctx = avcodec_alloc_context3(codec);
>>      enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
>>      enc_ctx->global_quality = FF_QP2LAMBDA * 3.0;
>>      ret = avcodec_open2(enc_ctx, enc_ctx->codec, NULL);
>>
>> Unfortunately it doesn't seem to have any effect on the output image size.
>> Is there something obvious that I'm missing?
>>
>
> Answering myself: Apparently setting the encoder option is not sufficient
> for mjpeg. The encoding quality has to be set for each frame that is passed
> to the encoder.
>
> Example:
>
>     frame->quality = enc_ctx->global_quality;
>     frame->pict_type = AV_PICTURE_TYPE_NONE;
>     ret = avcodec_send_frame(enc_ctx, frame);

Do you know if this was always needed?

Carl Eugen


More information about the Libav-user mailing list