From 08cf2c37c4178cf5dd029f960f1553ff111bb48e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 1 Nov 2015 17:53:06 +0100 Subject: [PATCH] Switch to BT.601 Y'CbCr coefficients and back to limited range. Finally makes MPlayer screenshots have correct colors and luma range all the way through. --- h264encode.cpp | 4 ++-- httpd.cpp | 4 ++-- theme.cpp | 10 ++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/h264encode.cpp b/h264encode.cpp index eb6faf3..4b900bf 100644 --- a/h264encode.cpp +++ b/h264encode.cpp @@ -343,12 +343,12 @@ static void sps_rbsp(bitstream *bs) bitstream_put_ui(bs, 1, 1); /* video_signal_type_present_flag */ { bitstream_put_ui(bs, 5, 3); /* video_format (5 = Unspecified) */ - bitstream_put_ui(bs, 1, 1); /* video_full_range_flag */ + bitstream_put_ui(bs, 0, 1); /* video_full_range_flag */ bitstream_put_ui(bs, 1, 1); /* colour_description_present_flag */ { bitstream_put_ui(bs, 1, 8); /* colour_primaries (1 = BT.709) */ bitstream_put_ui(bs, 1, 8); /* transfer_characteristics (1 = BT.709) */ - bitstream_put_ui(bs, 1, 8); /* matrix_coefficients (1 = BT.709) */ + bitstream_put_ui(bs, 6, 8); /* matrix_coefficients (6 = BT.601/SMPTE 170M) */ } } bitstream_put_ui(bs, 0, 1); /* chroma_loc_info_present_flag */ diff --git a/httpd.cpp b/httpd.cpp index 3beff80..5721884 100644 --- a/httpd.cpp +++ b/httpd.cpp @@ -95,8 +95,8 @@ HTTPD::Mux::Mux(AVFormatContext *avctx, int width, int height) // mux, this might simply get ignored. See sps_rbsp(). avstream_video->codec->color_primaries = AVCOL_PRI_BT709; // RGB colorspace (inout_format.color_space). avstream_video->codec->color_trc = AVCOL_TRC_BT709; // Gamma curve (inout_format.gamma_curve). - avstream_video->codec->colorspace = AVCOL_SPC_BT709; // YUV colorspace (output_ycbcr_format.luma_coefficients). - avstream_video->codec->color_range = AVCOL_RANGE_JPEG; // Full vs. limited range (output_ycbcr_format.full_range). + avstream_video->codec->colorspace = AVCOL_SPC_SMPTE170M; // YUV colorspace (output_ycbcr_format.luma_coefficients). + avstream_video->codec->color_range = AVCOL_RANGE_MPEG; // Full vs. limited range (output_ycbcr_format.full_range). avstream_video->codec->chroma_sample_location = AVCHROMA_LOC_LEFT; // Chroma sample location. See chroma_offset_0[] in Mixer::subsample_chroma(). avstream_video->codec->field_order = AV_FIELD_PROGRESSIVE; diff --git a/theme.cpp b/theme.cpp index 1536503..2c9af01 100644 --- a/theme.cpp +++ b/theme.cpp @@ -143,8 +143,14 @@ int EffectChain_finalize(lua_State* L) // happens in a pass not run by Movit (see Mixer::subsample_chroma()). output_ycbcr_format.chroma_subsampling_x = 1; output_ycbcr_format.chroma_subsampling_y = 1; - output_ycbcr_format.luma_coefficients = YCBCR_REC_709; - output_ycbcr_format.full_range = true; + + // Rec. 709 would be the sane thing to do, but it seems many players + // (e.g. MPlayer and VLC) just default to BT.601 coefficients no matter + // what (see discussions in e.g. https://trac.ffmpeg.org/ticket/4978). + // We _do_ set the right flags, though, so that a player that works + // properly doesn't have to guess. + output_ycbcr_format.luma_coefficients = YCBCR_REC_601; + output_ycbcr_format.full_range = false; output_ycbcr_format.num_levels = 256; chain->add_ycbcr_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED, output_ycbcr_format, YCBCR_OUTPUT_SPLIT_Y_AND_CBCR); -- 2.39.2