[FFmpeg-devel] [PATCH 1/2] avcodec/av1_metadata: add an option to insert and remove Temporal Delimiter OBUs
Mark Thompson
sw at jkqxz.net
Thu Oct 4 01:51:34 EEST 2018
On 03/10/18 01:18, James Almer wrote:
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
> libavcodec/av1_metadata_bsf.c | 37 ++++++++++++++++++++++++++++++++++-
> 1 file changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c
> index ed2f018fb6..20c3a39da7 100644
> --- a/libavcodec/av1_metadata_bsf.c
> +++ b/libavcodec/av1_metadata_bsf.c
> @@ -23,12 +23,20 @@
> #include "cbs.h"
> #include "cbs_av1.h"
>
> +enum {
> + PASS,
> + INSERT,
> + REMOVE,
> +};
> +
> typedef struct AV1MetadataContext {
> const AVClass *class;
>
> CodedBitstreamContext *cbc;
> CodedBitstreamFragment access_unit;
>
> + int td;
> +
> int color_primaries;
> int transfer_characteristics;
> int matrix_coefficients;
> @@ -115,7 +123,7 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out)
> AV1MetadataContext *ctx = bsf->priv_data;
> AVPacket *in = NULL;
> CodedBitstreamFragment *frag = &ctx->access_unit;
> - AV1RawOBU *obu;
> + AV1RawOBU td, *obu;
> int err, i;
>
> err = ff_bsf_get_packet(bsf, &in);
> @@ -137,6 +145,23 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out)
> }
> }
>
> + // If a Temporal Delimiter is present, it must be the first OBU.
> + if (frag->units[0].type == AV1_OBU_TEMPORAL_DELIMITER) {
> + if (ctx->td == REMOVE)
> + ff_cbs_delete_unit(ctx->cbc, frag, 0);
> + } else if (ctx->td == INSERT) {
> + td = (AV1RawOBU) {
> + .header.obu_type = AV1_OBU_TEMPORAL_DELIMITER,
> + };
> +
> + err = ff_cbs_insert_unit_content(ctx->cbc, frag, 0, AV1_OBU_TEMPORAL_DELIMITER,
> + &td, NULL);
> + if (err < 0) {
> + av_log(bsf, AV_LOG_ERROR, "Failed to insert Temporal Delimiter.\n");
> + goto fail;
> + }
> + }
> +
> err = ff_cbs_write_packet(ctx->cbc, out, frag);
> if (err < 0) {
> av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
> @@ -207,6 +232,16 @@ static void av1_metadata_close(AVBSFContext *bsf)
> #define OFFSET(x) offsetof(AV1MetadataContext, x)
> #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
> static const AVOption av1_metadata_options[] = {
> + { "td", "Temporal Delimiter OBU",
> + OFFSET(td), AV_OPT_TYPE_INT,
> + { .i64 = PASS }, PASS, REMOVE, FLAGS, "td" },
> + { "pass", NULL, 0, AV_OPT_TYPE_CONST,
> + { .i64 = PASS }, .flags = FLAGS, .unit = "td" },
> + { "insert", NULL, 0, AV_OPT_TYPE_CONST,
> + { .i64 = INSERT }, .flags = FLAGS, .unit = "td" },
> + { "remove", NULL, 0, AV_OPT_TYPE_CONST,
> + { .i64 = REMOVE }, .flags = FLAGS, .unit = "td" },
> +
> { "color_primaries", "Set color primaries (section 6.4.2)",
> OFFSET(color_primaries), AV_OPT_TYPE_INT,
> { .i64 = -1 }, -1, 255, FLAGS },
>
LGTM.
Thanks,
- Mark
More information about the ffmpeg-devel
mailing list