[FFmpeg-devel] [PATCH] Add vps/sps/pps id offset to hevc_metadata bsf
Eran Gonen
eran.gonen at cloudinary.com
Wed Jan 8 18:42:21 EET 2020
Yes. Fixing the identifier misprint
On Wed, Jan 8, 2020 at 5:52 PM Limin Wang <lance.lmwang at gmail.com> wrote:
> On Wed, Jan 08, 2020 at 05:20:07PM +0200, Eran Gonen wrote:
> > ---
> > doc/bitstream_filters.texi | 5 ++
> > libavcodec/h265_metadata_bsf.c | 106 +++++++++++++++++++++++++++++++--
> > 2 files changed, 105 insertions(+), 6 deletions(-)
> >
> > diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> > index 8fe5b3ad75..abd20e19d5 100644
> > --- a/doc/bitstream_filters.texi
> > +++ b/doc/bitstream_filters.texi
> > @@ -357,6 +357,11 @@ Set poc_proportional_to_timing_flag in VPS and VUI
> and use this value
> > to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and
> > E.3.1). Ignored if @option{tick_rate} is not also set.
> >
> > + at item vps_id_offset
> > + at item sps_id_offset
> > + at item pps_id_offset
> > +Replace the original VPS/SPS/PPS idenfier by increasing its value by
> the offset.
>
> idenfier -> identifier?
>
> > +
> > @item crop_left
> > @item crop_right
> > @item crop_top
> > diff --git a/libavcodec/h265_metadata_bsf.c
> b/libavcodec/h265_metadata_bsf.c
> > index b3a1fda144..7aeb1bffd1 100644
> > --- a/libavcodec/h265_metadata_bsf.c
> > +++ b/libavcodec/h265_metadata_bsf.c
> > @@ -68,6 +68,10 @@ typedef struct H265MetadataContext {
> > int level;
> > int level_guess;
> > int level_warned;
> > +
> > + int vps_id_offset;
> > + int sps_id_offset;
> > + int pps_id_offset;
> > } H265MetadataContext;
> >
> >
> > @@ -168,6 +172,8 @@ static int h265_metadata_update_vps(AVBSFContext
> *bsf,
> > {
> > H265MetadataContext *ctx = bsf->priv_data;
> >
> > + vps->vps_video_parameter_set_id = (vps->vps_video_parameter_set_id
> + ctx->vps_id_offset) % HEVC_MAX_VPS_COUNT;
> > +
> > if (ctx->tick_rate.num && ctx->tick_rate.den) {
> > int num, den;
> >
> > @@ -200,6 +206,9 @@ static int h265_metadata_update_sps(AVBSFContext
> *bsf,
> > int need_vui = 0;
> > int crop_unit_x, crop_unit_y;
> >
> > + sps->sps_video_parameter_set_id = (sps->sps_video_parameter_set_id
> + ctx->vps_id_offset) % HEVC_MAX_VPS_COUNT;
> > + sps->sps_seq_parameter_set_id = (sps->sps_seq_parameter_set_id +
> ctx->sps_id_offset) % HEVC_MAX_SPS_COUNT;
> > +
> > if (ctx->sample_aspect_ratio.num && ctx->sample_aspect_ratio.den) {
> > // Table E-1.
> > static const AVRational sar_idc[] = {
> > @@ -336,6 +345,27 @@ static int h265_metadata_update_sps(AVBSFContext
> *bsf,
> > return 0;
> > }
> >
> > +static int h265_metadata_update_pps(AVBSFContext *bsf,
> > + H265RawPPS *pps)
> > +{
> > + H265MetadataContext *ctx = bsf->priv_data;
> > +
> > + pps->pps_seq_parameter_set_id = (pps->pps_seq_parameter_set_id +
> ctx->sps_id_offset) % HEVC_MAX_SPS_COUNT;
> > + pps->pps_pic_parameter_set_id = (pps->pps_pic_parameter_set_id +
> ctx->pps_id_offset) % HEVC_MAX_PPS_COUNT;
> > +
> > + return 0;
> > +}
> > +
> > +static int h265_metadata_update_slice_header(AVBSFContext *bsf,
> > + H265RawSliceHeader *slice)
> > +{
> > + H265MetadataContext *ctx = bsf->priv_data;
> > +
> > + slice->slice_pic_parameter_set_id =
> (slice->slice_pic_parameter_set_id + ctx->pps_id_offset) %
> HEVC_MAX_PPS_COUNT;
> > +
> > + return 0;
> > +}
> > +
> > static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
> > {
> > H265MetadataContext *ctx = bsf->priv_data;
> > @@ -406,15 +436,42 @@ static int h265_metadata_filter(AVBSFContext *bsf,
> AVPacket *pkt)
> > h265_metadata_guess_level(bsf, au);
> >
> > for (i = 0; i < au->nb_units; i++) {
> > - if (au->units[i].type == HEVC_NAL_VPS) {
> > + switch (au->units[i].type) {
> > + case HEVC_NAL_VPS:
> > err = h265_metadata_update_vps(bsf, au->units[i].content);
> > if (err < 0)
> > goto fail;
> > - }
> > - if (au->units[i].type == HEVC_NAL_SPS) {
> > + break;
> > + case HEVC_NAL_SPS:
> > err = h265_metadata_update_sps(bsf, au->units[i].content);
> > if (err < 0)
> > goto fail;
> > + break;
> > + case HEVC_NAL_PPS:
> > + err = h265_metadata_update_pps(bsf, au->units[i].content);
> > + if (err < 0)
> > + goto fail;
> > + break;
> > + case HEVC_NAL_TRAIL_N:
> > + case HEVC_NAL_TRAIL_R:
> > + case HEVC_NAL_TSA_N:
> > + case HEVC_NAL_TSA_R:
> > + case HEVC_NAL_STSA_N:
> > + case HEVC_NAL_STSA_R:
> > + case HEVC_NAL_BLA_W_LP:
> > + case HEVC_NAL_BLA_W_RADL:
> > + case HEVC_NAL_BLA_N_LP:
> > + case HEVC_NAL_IDR_W_RADL:
> > + case HEVC_NAL_IDR_N_LP:
> > + case HEVC_NAL_CRA_NUT:
> > + case HEVC_NAL_RADL_N:
> > + case HEVC_NAL_RADL_R:
> > + case HEVC_NAL_RASL_N:
> > + case HEVC_NAL_RASL_R:
> > + err = h265_metadata_update_slice_header(bsf,
> au->units[i].content);
> > + if (err < 0)
> > + goto fail;
> > + break;
> > }
> > }
> >
> > @@ -455,15 +512,42 @@ static int h265_metadata_init(AVBSFContext *bsf)
> > h265_metadata_guess_level(bsf, au);
> >
> > for (i = 0; i < au->nb_units; i++) {
> > - if (au->units[i].type == HEVC_NAL_VPS) {
> > + switch (au->units[i].type) {
> > + case HEVC_NAL_VPS:
> > err = h265_metadata_update_vps(bsf,
> au->units[i].content);
> > if (err < 0)
> > goto fail;
> > - }
> > - if (au->units[i].type == HEVC_NAL_SPS) {
> > + break;
> > + case HEVC_NAL_SPS:
> > err = h265_metadata_update_sps(bsf,
> au->units[i].content);
> > if (err < 0)
> > goto fail;
> > + break;
> > + case HEVC_NAL_PPS:
> > + err = h265_metadata_update_pps(bsf,
> au->units[i].content);
> > + if (err < 0)
> > + goto fail;
> > + break;
> > + case HEVC_NAL_TRAIL_N:
> > + case HEVC_NAL_TRAIL_R:
> > + case HEVC_NAL_TSA_N:
> > + case HEVC_NAL_TSA_R:
> > + case HEVC_NAL_STSA_N:
> > + case HEVC_NAL_STSA_R:
> > + case HEVC_NAL_BLA_W_LP:
> > + case HEVC_NAL_BLA_W_RADL:
> > + case HEVC_NAL_BLA_N_LP:
> > + case HEVC_NAL_IDR_W_RADL:
> > + case HEVC_NAL_IDR_N_LP:
> > + case HEVC_NAL_CRA_NUT:
> > + case HEVC_NAL_RADL_N:
> > + case HEVC_NAL_RADL_R:
> > + case HEVC_NAL_RASL_N:
> > + case HEVC_NAL_RASL_R:
> > + err = h265_metadata_update_slice_header(bsf,
> au->units[i].content);
> > + if (err < 0)
> > + goto fail;
> > + break;
> > }
> > }
> >
> > @@ -547,6 +631,16 @@ static const AVOption h265_metadata_options[] = {
> > OFFSET(crop_bottom), AV_OPT_TYPE_INT,
> > { .i64 = -1 }, -1, HEVC_MAX_HEIGHT, FLAGS },
> >
> > + { "vps_id_offset", "Increase the vps id by this offset",
> > + OFFSET(vps_id_offset), AV_OPT_TYPE_INT,
> > + { .i64 = 0 }, 0, HEVC_MAX_VPS_COUNT, FLAGS },
> > + { "sps_id_offset", "Increase the sps id by this offset",
> > + OFFSET(sps_id_offset), AV_OPT_TYPE_INT,
> > + { .i64 = 0 }, 0, HEVC_MAX_SPS_COUNT, FLAGS },
> > + { "pps_id_offset", "Increase the pps id by this offset",
> > + OFFSET(pps_id_offset), AV_OPT_TYPE_INT,
> > + { .i64 = 0 }, 0, HEVC_MAX_PPS_COUNT, FLAGS },
> > +
> > { "level", "Set level (tables A.6 and A.7)",
> > OFFSET(level), AV_OPT_TYPE_INT,
> > { .i64 = LEVEL_UNSET }, LEVEL_UNSET, 0xff, FLAGS, "level" },
> > --
> > 2.24.0
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>
> --
> Thanks,
> Limin Wang
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list