From aac27d5ff7b1453edfb627962d34421194c20b77 Mon Sep 17 00:00:00 2001 From: SuslikV Date: Thu, 21 Nov 2019 14:35:09 +0200 Subject: [PATCH] Add non-subsampled color format for h264 encoder Forces the 4:4:4 color format for "0 crf" and "0 cqp" setting of the H264 encoder. By default, the 4:2:0 is used, that is not lossless itself. --- include/FFmpegUtilities.h | 3 +++ src/FFmpegWriter.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/include/FFmpegUtilities.h b/include/FFmpegUtilities.h index 62d64df1..81c44796 100644 --- a/include/FFmpegUtilities.h +++ b/include/FFmpegUtilities.h @@ -122,6 +122,9 @@ #ifndef PIX_FMT_YUV420P #define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P #endif + #ifndef PIX_FMT_YUV444P + #define PIX_FMT_YUV444P AV_PIX_FMT_YUV444P + #endif // FFmpeg's libavutil/common.h defines an RSHIFT incompatible with Ruby's // definition in ruby/config.h, so we move it to FF_RSHIFT diff --git a/src/FFmpegWriter.cpp b/src/FFmpegWriter.cpp index 2b97ba91..6cd40e11 100644 --- a/src/FFmpegWriter.cpp +++ b/src/FFmpegWriter.cpp @@ -438,6 +438,7 @@ void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string va av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value), 51), 0); // 0-51 if (std::stoi(value) == 0) { av_opt_set(c->priv_data, "preset", "veryslow", 0); + c->pix_fmt = PIX_FMT_YUV444P; // no chroma subsampling } break; case AV_CODEC_ID_HEVC : @@ -497,6 +498,7 @@ void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string va av_opt_set_int(c->priv_data, "crf", std::min(std::stoi(value), 51), 0); // 0-51 if (std::stoi(value) == 0) { av_opt_set(c->priv_data, "preset", "veryslow", 0); + c->pix_fmt = PIX_FMT_YUV444P; // no chroma subsampling } break; case AV_CODEC_ID_HEVC :