From db4f1ecb2deb6dcc0c17057770f84240f7fe60be Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 10 Jul 2020 23:53:55 -0700 Subject: [PATCH] FFmpeg: Minor lossless encoding improvements --- src/feature/ffmpeg/ffmpeg-encoder.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/feature/ffmpeg/ffmpeg-encoder.c b/src/feature/ffmpeg/ffmpeg-encoder.c index 71145f696..fc2896d41 100644 --- a/src/feature/ffmpeg/ffmpeg-encoder.c +++ b/src/feature/ffmpeg/ffmpeg-encoder.c @@ -390,12 +390,18 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) { // QuickTime and a few other things require YUV420 encoder->video->pix_fmt = AV_PIX_FMT_YUV420P; } -#if LIBAVCODEC_VERSION_MAJOR >= 57 if (encoder->video->codec->id == AV_CODEC_ID_FFV1) { +#if LIBAVCODEC_VERSION_MAJOR >= 57 av_opt_set(encoder->video->priv_data, "coder", "range_tab", 0); - } + av_opt_set_int(encoder->video->priv_data, "context", 1, 0); #endif + encoder->video->gop_size = 128; + encoder->video->level = 3; + } + if (encoder->video->codec->id == AV_CODEC_ID_PNG) { + encoder->video->compression_level = 8; + } if (strcmp(vcodec->name, "libx264") == 0) { // Try to adaptively figure out when you can use a slower encoder if (encoder->width * encoder->height > 1000000) { @@ -406,13 +412,15 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) { av_opt_set(encoder->video->priv_data, "preset", "faster", 0); } if (encoder->videoBitrate == 0) { - av_opt_set(encoder->video->priv_data, "crf", "0", 0); + av_opt_set(encoder->video->priv_data, "qp", "0", 0); encoder->video->pix_fmt = AV_PIX_FMT_YUV444P; } } if (strcmp(vcodec->name, "libvpx-vp9") == 0 && encoder->videoBitrate == 0) { - av_opt_set(encoder->video->priv_data, "lossless", "1", 0); - encoder->video->pix_fmt = AV_PIX_FMT_YUV444P; + av_opt_set_int(encoder->video->priv_data, "lossless", 1, 0); + av_opt_set_int(encoder->video->priv_data, "crf", 0, 0); + encoder->video->gop_size = 120; + encoder->video->pix_fmt = AV_PIX_FMT_GBRP; } if (strcmp(vcodec->name, "libwebp_anim") == 0 && encoder->videoBitrate == 0) { av_opt_set(encoder->video->priv_data, "lossless", "1", 0);