Commit 3921eed3 authored by James Almer's avatar James Almer

avcodec/av1_metadata: filter parameter sets in packet side data

Extradata included in packet side data is meant to replace the codec context
extradata. So when muxing for example to MP4 without this change and if
extradata is present in a packet side data, the result will be that the
parameter sets present in keyframes will be filtered, but the parameter sets
ultimately included in the av1C box will not.

This is especially important for AV1 as both currently supported encoders don't
export the Sequence Header in the codec context extradata, but as packet side
data instead.
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent 449eaeb7
...@@ -111,6 +111,50 @@ static int av1_metadata_update_sequence_header(AVBSFContext *bsf, ...@@ -111,6 +111,50 @@ static int av1_metadata_update_sequence_header(AVBSFContext *bsf,
return 0; return 0;
} }
static int av1_metadata_update_side_data(AVBSFContext *bsf, AVPacket *pkt)
{
AV1MetadataContext *ctx = bsf->priv_data;
CodedBitstreamFragment *frag = &ctx->access_unit;
uint8_t *side_data;
int side_data_size;
int err, i;
side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
&side_data_size);
if (!side_data_size)
return 0;
err = ff_cbs_read(ctx->cbc, frag, side_data, side_data_size);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read extradata from packet side data.\n");
return err;
}
for (i = 0; i < frag->nb_units; i++) {
if (frag->units[i].type == AV1_OBU_SEQUENCE_HEADER) {
AV1RawOBU *obu = frag->units[i].content;
err = av1_metadata_update_sequence_header(bsf, &obu->obu.sequence_header);
if (err < 0)
return err;
}
}
err = ff_cbs_write_fragment_data(ctx->cbc, frag);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write extradata into packet side data.\n");
return err;
}
side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, frag->data_size);
if (!side_data)
return AVERROR(ENOMEM);
memcpy(side_data, frag->data, frag->data_size);
ff_cbs_fragment_reset(ctx->cbc, frag);
return 0;
}
static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
{ {
AV1MetadataContext *ctx = bsf->priv_data; AV1MetadataContext *ctx = bsf->priv_data;
...@@ -122,6 +166,10 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) ...@@ -122,6 +166,10 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
if (err < 0) if (err < 0)
return err; return err;
err = av1_metadata_update_side_data(bsf, pkt);
if (err < 0)
goto fail;
err = ff_cbs_read_packet(ctx->cbc, frag, pkt); err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment