From 76589a5b34ba9769372cd8f233890ab892fd27ad Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 29 Jun 2023 12:27:30 +0200 Subject: image_writer: respect jpeg-quality when using ffmpeg for writing --- video/image_writer.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/video/image_writer.c b/video/image_writer.c index 11f0f6fdb5..f6636849c3 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -137,7 +137,11 @@ static bool write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp mp_imgfmt_to_name(image->imgfmt)); goto error_exit; } - if (codec->id == AV_CODEC_ID_PNG) { + + if (codec->id == AV_CODEC_ID_MJPEG) { + avctx->flags |= AV_CODEC_FLAG_QSCALE; + // jpeg_quality is set below + } else if (codec->id == AV_CODEC_ID_PNG) { avctx->compression_level = ctx->opts->png_compression; av_opt_set_int(avctx, "pred", ctx->opts->png_filter, AV_OPT_SEARCH_CHILDREN); @@ -173,6 +177,10 @@ static bool write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp pic->width = avctx->width; pic->height = avctx->height; pic->color_range = avctx->color_range; + if (codec->id == AV_CODEC_ID_MJPEG) { + int qscale = 1 + (100 - ctx->opts->jpeg_quality) * 30 / 100; + pic->quality = qscale * FF_QP2LAMBDA; + } if (ctx->opts->tag_csp) { avctx->color_primaries = pic->color_primaries = mp_csp_prim_to_avcol_pri(image->params.color.primaries); -- cgit v1.2.3