diff options
author | James Almer <jamrial@gmail.com> | 2018-10-02 21:05:51 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2018-10-03 20:17:14 -0300 |
commit | af2acbd23f8553b4030974dc9161b877f8e17340 (patch) | |
tree | 7aa537ae2ea544c6ee66610e316d9c0c67d787fc /libavcodec/av1_metadata_bsf.c | |
parent | 7ca2ee059e3d3e170a8e119af10649671c524112 (diff) | |
download | ffmpeg-af2acbd23f8553b4030974dc9161b877f8e17340.tar.gz |
avcodec/av1_metadata: add an option to insert and remove Temporal Delimiter OBUs
Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/av1_metadata_bsf.c')
-rw-r--r-- | libavcodec/av1_metadata_bsf.c | 37 |
1 files changed, 36 insertions, 1 deletions
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 }, |