FFmpeg: Minor lossless encoding improvements

This commit is contained in:
Vicki Pfau 2020-07-10 23:53:55 -07:00
parent 1b755e17d0
commit db4f1ecb2d
1 changed files with 13 additions and 5 deletions

View File

@ -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);