Skip to content

Commit

Permalink
libhb: cli: add a way to disable hdr dynamic metadata passthru
Browse files Browse the repository at this point in the history
  • Loading branch information
galad87 committed Jan 2, 2025
1 parent 7081be7 commit 5d34c1b
Show file tree
Hide file tree
Showing 21 changed files with 415 additions and 41 deletions.
39 changes: 37 additions & 2 deletions libhb/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,41 @@ int hb_video_multipass_is_supported(uint32_t codec, int constant_quality)
}
}

int hb_video_hdr_dynamic_metadata_is_supported(uint32_t codec, int hdr_dynamic_metadata, int profile)
{
if (hdr_dynamic_metadata == HB_HDR_DYNAMIC_METADATA_HDR10PLUS)
{
switch (codec)
{
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_VT_H265_10BIT:
case HB_VCODEC_SVT_AV1_10BIT:
return 1;
}
}
#if HB_PROJECT_FEATURE_LIBDOVI
else if (hdr_dynamic_metadata == HB_HDR_DYNAMIC_METADATA_DOVI)
{
if (profile != 5 &&
profile != 7 &&
profile != 8 &&
profile != 10)
{
return 0;
}

switch (codec)
{
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_VT_H265_10BIT:
case HB_VCODEC_SVT_AV1_10BIT:
return 1;
}
}
#endif
return 0;
}

int hb_video_encoder_is_supported(int encoder)
{
const hb_encoder_t *video_encoder = NULL;
Expand Down Expand Up @@ -4446,8 +4481,8 @@ static void job_setup(hb_job_t * job, hb_title_t * title)
job->coll = title->coll;
job->ambient = title->ambient;
job->dovi = title->dovi;
job->passthru_dynamic_hdr_metadata |= title->dovi.dv_profile ? DOVI : NONE;
job->passthru_dynamic_hdr_metadata |= title->hdr_10_plus ? HDR_10_PLUS : NONE;
job->passthru_dynamic_hdr_metadata |= title->dovi.dv_profile ? HB_HDR_DYNAMIC_METADATA_DOVI : HB_HDR_DYNAMIC_METADATA_NONE;
job->passthru_dynamic_hdr_metadata |= title->hdr_10_plus ? HB_HDR_DYNAMIC_METADATA_HDR10PLUS : HB_HDR_DYNAMIC_METADATA_NONE;

job->mux = HB_MUX_MP4;

Expand Down
6 changes: 3 additions & 3 deletions libhb/encsvtav1.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ int encsvtInit(hb_work_object_t *w, hb_job_t *job)
}

// Update and set Dolby Vision level
if (job->passthru_dynamic_hdr_metadata & DOVI)
if (job->passthru_dynamic_hdr_metadata & HB_HDR_DYNAMIC_METADATA_DOVI)
{
int level_idx, high_tier;
hb_parse_av1_extradata(*w->extradata, &level_idx, &high_tier);
Expand Down Expand Up @@ -486,7 +486,7 @@ static int send(hb_work_object_t *w, hb_buffer_t *in)
for (int i = 0; i < in->nb_side_data; i++)
{
const AVFrameSideData *side_data = in->side_data[i];
if (job->passthru_dynamic_hdr_metadata & HDR_10_PLUS &&
if (job->passthru_dynamic_hdr_metadata & HB_HDR_DYNAMIC_METADATA_HDR10PLUS &&
side_data->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS)
{
uint8_t *payload = NULL;
Expand All @@ -501,7 +501,7 @@ static int send(hb_work_object_t *w, hb_buffer_t *in)
svt_add_metadata(headerPtr, EB_AV1_METADATA_TYPE_ITUT_T35, payload, playload_size);
av_freep(&payload);
}
else if (job->passthru_dynamic_hdr_metadata & DOVI &&
else if (job->passthru_dynamic_hdr_metadata & HB_HDR_DYNAMIC_METADATA_DOVI &&
side_data->type == AV_FRAME_DATA_DOVI_RPU_BUFFER_T35)
{
svt_add_metadata(headerPtr, EB_AV1_METADATA_TYPE_ITUT_T35, side_data->data, side_data->size);
Expand Down
6 changes: 3 additions & 3 deletions libhb/encx265.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ int encx265Init(hb_work_object_t *w, hb_job_t *job)
/*
* Update and set Dolby Vision level
*/
if (job->passthru_dynamic_hdr_metadata & DOVI)
if (job->passthru_dynamic_hdr_metadata & HB_HDR_DYNAMIC_METADATA_DOVI)
{
char dolbyVisionProfile[256];
snprintf(dolbyVisionProfile, sizeof(dolbyVisionProfile),
Expand Down Expand Up @@ -713,7 +713,7 @@ static hb_buffer_t* x265_encode(hb_work_object_t *w, hb_buffer_t *in)
for (int i = 0; i < in->nb_side_data; i++)
{
const AVFrameSideData *side_data = in->side_data[i];
if (job->passthru_dynamic_hdr_metadata & HDR_10_PLUS &&
if (job->passthru_dynamic_hdr_metadata & HB_HDR_DYNAMIC_METADATA_HDR10PLUS &&
side_data->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS)
{
uint8_t *payload = NULL;
Expand Down Expand Up @@ -743,7 +743,7 @@ static hb_buffer_t* x265_encode(hb_work_object_t *w, hb_buffer_t *in)
sei_payload->payloadType = USER_DATA_REGISTERED_ITU_T_T35;
sei->numPayloads++;
}
if (job->passthru_dynamic_hdr_metadata & DOVI &&
if (job->passthru_dynamic_hdr_metadata & HB_HDR_DYNAMIC_METADATA_DOVI &&
side_data->type == AV_FRAME_DATA_DOVI_RPU_BUFFER)
{
x265_dolby_vision_rpu *rpu = &pic_in.rpu;
Expand Down
15 changes: 14 additions & 1 deletion libhb/handbrake/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ struct hb_dovi_conf_s
unsigned dv_bl_signal_compatibility_id;
};

typedef enum
{
HB_HDR_DYNAMIC_METADATA_NONE = 0,
HB_HDR_DYNAMIC_METADATA_HDR10PLUS = 1 << 1,
HB_HDR_DYNAMIC_METADATA_DOVI = 1 << 2,
HB_HDR_DYNAMIC_METADATA_ALL = HB_HDR_DYNAMIC_METADATA_HDR10PLUS | HB_HDR_DYNAMIC_METADATA_DOVI
} hb_hdr_dynamic_metadata_mode_t;

int hb_str_ends_with(const char *base, const char *str);

/*******************************************************************************
Expand Down Expand Up @@ -437,6 +445,11 @@ int hb_video_quality_is_supported(uint32_t codec);
int hb_video_bitrate_is_supported(uint32_t codec);
int hb_video_multipass_is_supported(uint32_t codec, int constant_quality);

int hb_video_hdr_dynamic_metadata_is_supported(uint32_t codec, int hdr_dynamic_metadata, int profile);

int hb_hdr_dynamic_metadata_get_from_name(const char *name);
const char* hb_hdr_dynamic_metadata_get_name(int hdr_dynamic_metadata);

int hb_video_encoder_is_supported(int encoder);
int hb_video_encoder_get_count_of_analysis_passes(int encoder);
int hb_video_encoder_pix_fmt_is_supported(int encoder, int pix_fmt, const char *profile);
Expand Down Expand Up @@ -750,7 +763,7 @@ struct hb_job_s
hb_ambient_viewing_environment_metadata_t ambient;
hb_dovi_conf_t dovi;

enum {NONE = 0x0, ALL = 0x3, DOVI = 0x1, HDR_10_PLUS = 0x2} passthru_dynamic_hdr_metadata;
hb_hdr_dynamic_metadata_mode_t passthru_dynamic_hdr_metadata;


hb_list_t * list_chapter;
Expand Down
Loading

0 comments on commit 5d34c1b

Please sign in to comment.