aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2020-04-22 12:09:46 -0300
committerJames Almer <jamrial@gmail.com>2020-05-03 11:39:00 -0300
commit502dacdc50e204947f7a32bf5c31bc4fbcba80d6 (patch)
treeaa0e276b822a042b9ba1c6f8cee2f4c8d5fab455
parent3921eed398c9ac01e9923e51d1bf9086556e03d1 (diff)
downloadffmpeg-502dacdc50e204947f7a32bf5c31bc4fbcba80d6.tar.gz
avcodec/h264_metadata: filter parameter sets in packet side data
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r--libavcodec/h264_metadata_bsf.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index d96a50dbf7..451eaa0b67 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -275,6 +275,49 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
return 0;
}
+static int h264_metadata_update_side_data(AVBSFContext *bsf, AVPacket *pkt)
+{
+ H264MetadataContext *ctx = bsf->priv_data;
+ CodedBitstreamFragment *au = &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, au, 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 < au->nb_units; i++) {
+ if (au->units[i].type == H264_NAL_SPS) {
+ err = h264_metadata_update_sps(bsf, au->units[i].content);
+ if (err < 0)
+ return err;
+ }
+ }
+
+ err = ff_cbs_write_fragment_data(ctx->cbc, au);
+ 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, au->data_size);
+ if (!side_data)
+ return AVERROR(ENOMEM);
+ memcpy(side_data, au->data, au->data_size);
+
+ ff_cbs_fragment_reset(ctx->cbc, au);
+
+ return 0;
+}
+
static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
{
H264MetadataContext *ctx = bsf->priv_data;
@@ -286,6 +329,10 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
if (err < 0)
return err;
+ err = h264_metadata_update_side_data(bsf, pkt);
+ if (err < 0)
+ goto fail;
+
err = ff_cbs_read_packet(ctx->cbc, au, pkt);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");