AVRational tick_rate;
int num_ticks_per_picture;
+
+ int delete_padding;
} AV1MetadataContext;
if (ctx->color_primaries >= 0 ||
ctx->transfer_characteristics >= 0 ||
ctx->matrix_coefficients >= 0) {
- if (!clc->color_description_present_flag) {
- clc->color_description_present_flag = 1;
- clc->color_primaries = AVCOL_PRI_UNSPECIFIED;
- clc->transfer_characteristics = AVCOL_TRC_UNSPECIFIED;
- clc->matrix_coefficients = AVCOL_SPC_UNSPECIFIED;
- }
+ clc->color_description_present_flag = 1;
if (ctx->color_primaries >= 0)
clc->color_primaries = ctx->color_primaries;
return 0;
}
-static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out)
+static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
{
AV1MetadataContext *ctx = bsf->priv_data;
- AVPacket *in = NULL;
CodedBitstreamFragment *frag = &ctx->access_unit;
AV1RawOBU td, *obu;
int err, i;
- err = ff_bsf_get_packet(bsf, &in);
+ err = ff_bsf_get_packet_ref(bsf, pkt);
if (err < 0)
return err;
- err = ff_cbs_read_packet(ctx->cbc, frag, in);
+ err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
goto fail;
}
+ if (frag->nb_units == 0) {
+ av_log(bsf, AV_LOG_ERROR, "No OBU in packet.\n");
+ err = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+
for (i = 0; i < frag->nb_units; i++) {
if (frag->units[i].type == AV1_OBU_SEQUENCE_HEADER) {
obu = frag->units[i].content;
}
}
- err = ff_cbs_write_packet(ctx->cbc, out, frag);
+ if (ctx->delete_padding) {
+ for (i = frag->nb_units - 1; i >= 0; i--) {
+ if (frag->units[i].type == AV1_OBU_PADDING)
+ ff_cbs_delete_unit(ctx->cbc, frag, i);
+ }
+ }
+
+ err = ff_cbs_write_packet(ctx->cbc, pkt, frag);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
goto fail;
}
- err = av_packet_copy_props(out, in);
- if (err < 0)
- goto fail;
-
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, frag);
+ ff_cbs_fragment_reset(ctx->cbc, frag);
if (err < 0)
- av_packet_unref(out);
- av_packet_free(&in);
+ av_packet_unref(pkt);
return err;
}
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, frag);
+ ff_cbs_fragment_reset(ctx->cbc, frag);
return err;
}
static void av1_metadata_close(AVBSFContext *bsf)
{
AV1MetadataContext *ctx = bsf->priv_data;
+
+ ff_cbs_fragment_free(ctx->cbc, &ctx->access_unit);
ff_cbs_close(&ctx->cbc);
}
OFFSET(num_ticks_per_picture), AV_OPT_TYPE_INT,
{ .i64 = -1 }, -1, INT_MAX, FLAGS },
+ { "delete_padding", "Delete all Padding OBUs",
+ OFFSET(delete_padding), AV_OPT_TYPE_BOOL,
+ { .i64 = 0 }, 0, 1, FLAGS},
+
{ NULL }
};