[FFmpeg-devel] [PATCH 31/31] hevc_metadata: Update AVCodecParameters during init
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Tue Jul 9 04:10:48 EEST 2019
This commit makes hevc_metadata update the AVCodecParameters during init
to bring them in line with the changes to the bitstream.
Notice that for field-based HEVC the derived height is the height of a
frame, which deviates from current FFmpeg behaviour.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
I am unsure about the part about the height of field-based HEVC.
libavcodec/h265_metadata_bsf.c | 37 ++++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 6 deletions(-)
diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c
index b3a1fda144..01a955028b 100644
--- a/libavcodec/h265_metadata_bsf.c
+++ b/libavcodec/h265_metadata_bsf.c
@@ -193,8 +193,8 @@ static int h265_metadata_update_vps(AVBSFContext *bsf,
return 0;
}
-static int h265_metadata_update_sps(AVBSFContext *bsf,
- H265RawSPS *sps)
+static int h265_metadata_update_sps(AVBSFContext *bsf, H265RawSPS *sps,
+ int *width, int *height)
{
H265MetadataContext *ctx = bsf->priv_data;
int need_vui = 0;
@@ -328,6 +328,13 @@ static int h265_metadata_update_sps(AVBSFContext *bsf,
CROP(bottom, crop_unit_y);
#undef CROP
+ if (width && height) {
+ *width = sps->pic_width_in_luma_samples - crop_unit_x *
+ (sps->conf_win_left_offset + sps->conf_win_right_offset);
+ *height = (1 + sps->vui.field_seq_flag) * (sps->pic_height_in_luma_samples
+ - crop_unit_y * (sps->conf_win_top_offset + sps->conf_win_bottom_offset));
+ }
+
if (need_vui)
sps->vui_parameters_present_flag = 1;
@@ -412,7 +419,8 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
goto fail;
}
if (au->units[i].type == HEVC_NAL_SPS) {
- err = h265_metadata_update_sps(bsf, au->units[i].content);
+ err = h265_metadata_update_sps(bsf, au->units[i].content,
+ NULL, NULL);
if (err < 0)
goto fail;
}
@@ -438,7 +446,9 @@ static int h265_metadata_init(AVBSFContext *bsf)
{
H265MetadataContext *ctx = bsf->priv_data;
CodedBitstreamFragment *au = &ctx->access_unit;
- int err, i;
+ int err, i, width = -1, height = -1, level = ctx->level;
+ int color_range = ctx->video_full_range_flag;
+ int chroma_location = ctx->chroma_sample_loc_type;
err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_HEVC, bsf);
if (err < 0)
@@ -451,8 +461,10 @@ static int h265_metadata_init(AVBSFContext *bsf)
goto fail;
}
- if (ctx->level == LEVEL_AUTO)
+ if (ctx->level == LEVEL_AUTO) {
h265_metadata_guess_level(bsf, au);
+ level = ctx->level_guess ? ctx->level_guess : level;
+ }
for (i = 0; i < au->nb_units; i++) {
if (au->units[i].type == HEVC_NAL_VPS) {
@@ -461,7 +473,8 @@ static int h265_metadata_init(AVBSFContext *bsf)
goto fail;
}
if (au->units[i].type == HEVC_NAL_SPS) {
- err = h265_metadata_update_sps(bsf, au->units[i].content);
+ err = h265_metadata_update_sps(bsf, au->units[i].content,
+ &width, &height);
if (err < 0)
goto fail;
}
@@ -474,6 +487,18 @@ static int h265_metadata_init(AVBSFContext *bsf)
}
}
+ if (color_range >= 0)
+ color_range++;
+ if (chroma_location >= 0)
+ chroma_location++;
+
+ ff_cbs_update_video_parameters(ctx->cbc, bsf->par_out, -1, level,
+ width, height, -1, color_range,
+ ctx->colour_primaries,
+ ctx->transfer_characteristics,
+ ctx->matrix_coefficients,
+ chroma_location, -1);
+
err = 0;
fail:
ff_cbs_fragment_reset(ctx->cbc, au);
--
2.21.0
More information about the ffmpeg-devel
mailing list