Deletes both filler NAL units and filler SEI messages.
---
libavcodec/h264_metadata_bsf.c | 44 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index ac0b9823b..58d598e6d 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -62,6 +62,8 @@ typedef struct H264MetadataContext {
int crop_bottom;
const char *sei_user_data;
+
+ int delete_filler;
} H264MetadataContext;
@@ -278,6 +280,45 @@ static int h264_metadata_filter(AVBSFContext *bsf,
AVPacket *out)
}
}
+ if (ctx->delete_filler) {
+ for (i = 0; i < au->nb_units; i++) {
+ int delete_unit = 0;
+ if (au->units[i].type == H264_NAL_FILLER_DATA) {
+ // Filler NAL units.
+ delete_unit = 1;
+ }
+ if (au->units[i].type == H264_NAL_SEI) {
+ // Filler SEI messages.
+ H264RawSEI *sei = au->units[i].content;
+
+ for (j = 0; j < sei->payload_count; j++) {
+ if (sei->payload[j].payload_type ==
+ H264_SEI_TYPE_FILLER_PAYLOAD) {
+ if (j + 1 < sei->payload_count) {
+ memmove(&sei->payload[j],
+ &sei->payload[j + 1],
+ (sei->payload_count - (j + 1)) *
+ sizeof(*sei->payload));
+ }
+ --j;
+ --sei->payload_count;
+ }
+ }
+ if (sei->payload_count == 0)
+ delete_unit = 1;
+ }
+ if (delete_unit) {
+ err = ff_cbs_delete_unit(&ctx->cbc, au, i);
+ if (err < 0) {
+ av_log(bsf, AV_LOG_ERROR, "Failed to delete "
+ "filler NAL.\n");
+ goto fail;
+ }
+ --i;
+ }
+ }
+ }
+
has_sps = 0;
for (i = 0; i < au->nb_units; i++) {
if (au->units[i].type == H264_NAL_SPS) {
@@ -495,6 +536,9 @@ static const AVOption h264_metadata_options[] = {
{ "sei_user_data", "Insert SEI user data (UUID+string)",
OFFSET(sei_user_data), AV_OPT_TYPE_STRING, { .str = NULL } },
+ { "delete_filler", "Delete all filler (both NAL and SEI)",
+ OFFSET(delete_filler), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1 },
+
{ NULL }
};
--
2.11.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel