mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-21 10:55:51 +02:00
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>
This commit is contained in:
parent
7ca2ee059e
commit
af2acbd23f
@ -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 },
|
||||
|
Loading…
Reference in New Issue
Block a user