Skip to content

Commit

Permalink
libhb: revert part of the previous colormatrix override commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
galad87 committed Jan 25, 2021
1 parent c543768 commit 818dbfe
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 35 deletions.
27 changes: 27 additions & 0 deletions libhb/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3841,6 +3841,9 @@ static void job_setup(hb_job_t * job, hb_title_t * title)
job->color_transfer = title->color_transfer;
job->color_matrix = title->color_matrix;
job->color_range = title->color_range;
job->color_prim_override = HB_COLR_PRI_UNDEF;
job->color_transfer_override = HB_COLR_TRA_UNDEF;
job->color_matrix_override = HB_COLR_MAT_UNDEF;

job->mux = HB_MUX_MP4;

Expand All @@ -3859,6 +3862,30 @@ static void job_setup(hb_job_t * job, hb_title_t * title)
#endif
}

int hb_output_color_prim(hb_job_t * job)
{
if (job->color_prim_override != HB_COLR_PRI_UNDEF)
return job->color_prim_override;
else
return job->color_prim;
}

int hb_output_color_transfer(hb_job_t * job)
{
if (job->color_transfer_override != HB_COLR_TRA_UNDEF)
return job->color_transfer_override;
else
return job->color_transfer;
}

int hb_output_color_matrix(hb_job_t * job)
{
if (job->color_matrix_override != HB_COLR_MAT_UNDEF)
return job->color_matrix_override;
else
return job->color_matrix;
}

static void job_clean( hb_job_t * job )
{
if (job)
Expand Down
8 changes: 4 additions & 4 deletions libhb/decavcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,11 +963,11 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv )
}

// Make sure every frame is tagged.
if (pv->job)
if (out->f.color_prim == HB_COLR_PRI_UNDEF || out->f.color_transfer == HB_COLR_TRA_UNDEF || out->f.color_matrix == HB_COLR_MAT_UNDEF)
{
out->f.color_prim = pv->job->color_prim;
out->f.color_transfer = pv->job->color_transfer;
out->f.color_matrix = pv->job->color_matrix;
out->f.color_prim = pv->title->color_prim;
out->f.color_transfer = pv->title->color_transfer;
out->f.color_matrix = pv->title->color_matrix;
}

if (pv->frame->pts != AV_NOPTS_VALUE)
Expand Down
12 changes: 6 additions & 6 deletions libhb/enc_qsv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,9 +1058,9 @@ int encqsvInit(hb_work_object_t *w, hb_job_t *job)
pv->param.videoParam->AsyncDepth = job->qsv.async_depth;

// set and enable colorimetry (video signal information)
pv->param.videoSignalInfo.ColourPrimaries = job->color_prim;
pv->param.videoSignalInfo.TransferCharacteristics = job->color_transfer;
pv->param.videoSignalInfo.MatrixCoefficients = job->color_matrix;
pv->param.videoSignalInfo.ColourPrimaries = hb_output_color_prim(job);
pv->param.videoSignalInfo.TransferCharacteristics = hb_output_color_transfer(job);
pv->param.videoSignalInfo.MatrixCoefficients = hb_output_color_matrix(job);
pv->param.videoSignalInfo.ColourDescriptionPresent = 1;

// parse user-specified encoder options, if present
Expand Down Expand Up @@ -1117,9 +1117,9 @@ int encqsvInit(hb_work_object_t *w, hb_job_t *job)
// reload colorimetry in case values were set in encoder_options
if (pv->param.videoSignalInfo.ColourDescriptionPresent)
{
job->color_prim = pv->param.videoSignalInfo.ColourPrimaries;
job->color_transfer = pv->param.videoSignalInfo.TransferCharacteristics;
job->color_matrix = pv->param.videoSignalInfo.MatrixCoefficients;
job->color_prim_override = pv->param.videoSignalInfo.ColourPrimaries;
job->color_transfer_override = pv->param.videoSignalInfo.TransferCharacteristics;
job->color_matrix_override = pv->param.videoSignalInfo.MatrixCoefficients;
}

// sanitize values that may exceed the Media SDK variable size
Expand Down
12 changes: 6 additions & 6 deletions libhb/encavcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
job->par.num, job->par.den );

// set colorimetry
context->color_primaries = job->color_prim;
context->color_trc = job->color_transfer;
context->colorspace = job->color_matrix;
context->color_primaries = hb_output_color_prim(job);
context->color_trc = hb_output_color_transfer(job);
context->colorspace = hb_output_color_matrix(job);

if (!job->inline_parameter_sets)
{
Expand Down Expand Up @@ -656,9 +656,9 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
* Reload colorimetry settings in case custom
* values were set in the encoder_options string.
*/
job->color_prim = context->color_primaries;
job->color_transfer = context->color_trc;
job->color_matrix = context->colorspace;
job->color_prim_override = context->color_primaries;
job->color_transfer_override = context->color_trc;
job->color_matrix_override = context->colorspace;

if (job->pass_id == HB_PASS_ENCODE_1ST &&
context->stats_out != NULL)
Expand Down
12 changes: 6 additions & 6 deletions libhb/encx264.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job )

/* set up the VUI color model & gamma to match what the COLR atom
* set in muxmp4.c says. See libhb/muxmp4.c for notes. */
param.vui.i_colorprim = job->color_prim;
param.vui.i_transfer = job->color_transfer;
param.vui.i_colmatrix = job->color_matrix;
param.vui.i_colorprim = hb_output_color_prim(job);
param.vui.i_transfer = hb_output_color_transfer(job);
param.vui.i_colmatrix = hb_output_color_matrix(job);

/* place job->encoder_options in an hb_dict_t for convenience */
hb_dict_t * x264_opts = NULL;
Expand Down Expand Up @@ -425,9 +425,9 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job )

/* Reload colorimetry settings in case custom values were set
* in the encoder_options string */
job->color_prim = param.vui.i_colorprim;
job->color_transfer = param.vui.i_transfer;
job->color_matrix = param.vui.i_colmatrix;
job->color_prim_override = param.vui.i_colorprim;
job->color_transfer_override = param.vui.i_transfer;
job->color_matrix_override = param.vui.i_colmatrix;

/* For 25 fps sources, HandBrake's explicit keyints will match the x264 defaults:
* min-keyint 25 (same as auto), keyint 250. */
Expand Down
12 changes: 6 additions & 6 deletions libhb/encx265.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ int encx265Init(hb_work_object_t *w, hb_job_t *job)
* flags, if any, should be set in the x265_param struct).
*/
char colorprim[11], transfer[11], colormatrix[11];
snprintf(colorprim, sizeof(colorprim), "%d", job->color_prim);
snprintf(transfer, sizeof(transfer), "%d", job->color_transfer);
snprintf(colormatrix, sizeof(colormatrix), "%d", job->color_matrix);
snprintf(colorprim, sizeof(colorprim), "%d", hb_output_color_prim(job));
snprintf(transfer, sizeof(transfer), "%d", hb_output_color_transfer(job));
snprintf(colormatrix, sizeof(colormatrix), "%d", hb_output_color_matrix(job));

if (param_parse(pv, param, "colorprim", colorprim) ||
param_parse(pv, param, "transfer", transfer) ||
Expand Down Expand Up @@ -222,9 +222,9 @@ int encx265Init(hb_work_object_t *w, hb_job_t *job)
* Reload colorimetry settings in case custom
* values were set in the encoder_options string.
*/
job->color_prim = param->vui.colorPrimaries;
job->color_transfer = param->vui.transferCharacteristics;
job->color_matrix = param->vui.matrixCoeffs;
job->color_prim_override = param->vui.colorPrimaries;
job->color_transfer_override = param->vui.transferCharacteristics;
job->color_matrix_override = param->vui.matrixCoeffs;

/*
* Settings which can't be overridden in the encodeer_options string
Expand Down
4 changes: 4 additions & 0 deletions libhb/handbrake/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ struct hb_job_s
int color_transfer;
int color_matrix;
int color_range;

int color_prim_override;
int color_transfer_override;
int color_matrix_override;
// see https://developer.apple.com/library/content/technotes/tn2162/_index.html
// https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html#//apple_ref/doc/uid/TP40000939-CH205-125526
// libav pixfmt.h
Expand Down
20 changes: 20 additions & 0 deletions libhb/hb_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,21 @@ hb_dict_t* hb_job_to_dict( const hb_job_t * job )
hb_value_int(job->color_transfer));
hb_dict_set(video_dict, "ColorMatrix",
hb_value_int(job->color_matrix));
if (job->color_prim_override != HB_COLR_PRI_UNDEF)
{
hb_dict_set(video_dict, "ColorPrimariesOverride",
hb_value_int(job->color_prim_override));
}
if (job->color_transfer_override != HB_COLR_TRA_UNDEF)
{
hb_dict_set(video_dict, "ColorTransferOverride",
hb_value_int(job->color_transfer_override));
}
if (job->color_matrix_override != HB_COLR_MAT_UNDEF)
{
hb_dict_set(video_dict, "ColorMatrixOverride",
hb_value_int(job->color_matrix_override));
}

if (job->vquality > HB_INVALID_VIDEO_QUALITY)
{
Expand Down Expand Up @@ -1044,11 +1059,13 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict )
// TwoPass, Turbo,
// ColorFormat, ColorRange,
// ColorPrimaries, ColorTransfer, ColorMatrix,
// ColorPrimariesOverride, ColorTransferOverride, ColorMatrixOverride,
// QSV {Decode, AsyncDepth}}
"s:{s:o, s?F, s?i, s?s, s?s, s?s, s?s, s?s,"
" s?b, s?b,"
" s?i, s?i,"
" s?i, s?i, s?i,"
" s?i, s?i, s?i,"
" s?{s?b, s?i}},"
// Audio {CopyMask, FallbackEncoder, AudioList}
"s?{s?o, s?o, s?o},"
Expand Down Expand Up @@ -1096,6 +1113,9 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict )
"ColorPrimaries", unpack_i(&job->color_prim),
"ColorTransfer", unpack_i(&job->color_transfer),
"ColorMatrix", unpack_i(&job->color_matrix),
"ColorPrimariesOverride", unpack_i(&job->color_prim_override),
"ColorTransferOverride", unpack_i(&job->color_transfer_override),
"ColorMatrixOverride", unpack_i(&job->color_matrix_override),
"QSV",
"Decode", unpack_b(&job->qsv.decode),
"AsyncDepth", unpack_i(&job->qsv.async_depth),
Expand Down
6 changes: 3 additions & 3 deletions libhb/preset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1731,11 +1731,11 @@ int hb_preset_apply_video(const hb_dict_t *preset, hb_dict_t *job_dict)
break;
}

hb_dict_set(video_dict, "ColorPrimaries",
hb_dict_set(video_dict, "ColorPrimariesOverride",
hb_value_int(color_prim));
hb_dict_set(video_dict, "ColorTransfer",
hb_dict_set(video_dict, "ColorTransferOverride",
hb_value_int(color_transfer));
hb_dict_set(video_dict, "ColorMatrix",
hb_dict_set(video_dict, "ColorMatrixOverride",
hb_value_int(color_matrix));
}
hb_dict_set(video_dict, "Encoder", hb_value_dup(vcodec_value));
Expand Down
6 changes: 3 additions & 3 deletions libhb/work.c
Original file line number Diff line number Diff line change
Expand Up @@ -1456,9 +1456,9 @@ static void do_job(hb_job_t *job)
init.pix_fmt = get_best_pix_ftm(job);
init.color_range = AVCOL_RANGE_MPEG;

init.color_prim = job->color_prim;
init.color_transfer = job->color_transfer;
init.color_matrix = job->color_matrix;
init.color_prim = title->color_prim;
init.color_transfer = title->color_transfer;
init.color_matrix = title->color_matrix;
init.geometry.width = title->geometry.width;
init.geometry.height = title->geometry.height;

Expand Down
2 changes: 1 addition & 1 deletion test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ static void ShowHelp()
" Dimensions will be made divisible by this number.\n"
" (default: set by preset, typically 2)\n"
" -M, --color-matrix <string>\n"
" Set the color space signaled by the input:\n"
" Set the color space signaled by the output:\n"
" Overrides color signalling with no conversion.\n"
" 2020\n"
" 709\n"
Expand Down

0 comments on commit 818dbfe

Please sign in to comment.