From: Mark Thompson <sw@jkqxz.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 6/6] lavc: APV metadata bitstream filter Date: Mon, 21 Apr 2025 16:24:37 +0100 Message-ID: <20250421152445.2110045-7-sw@jkqxz.net> (raw) In-Reply-To: <20250421152445.2110045-1-sw@jkqxz.net> --- libavcodec/bitstream_filters.c | 1 + libavcodec/bsf/Makefile | 1 + libavcodec/bsf/apv_metadata.c | 134 +++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 libavcodec/bsf/apv_metadata.c diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index f923411bee..da9d0d2513 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -25,6 +25,7 @@ #include "bsf_internal.h" extern const FFBitStreamFilter ff_aac_adtstoasc_bsf; +extern const FFBitStreamFilter ff_apv_metadata_bsf; extern const FFBitStreamFilter ff_av1_frame_merge_bsf; extern const FFBitStreamFilter ff_av1_frame_split_bsf; extern const FFBitStreamFilter ff_av1_metadata_bsf; diff --git a/libavcodec/bsf/Makefile b/libavcodec/bsf/Makefile index 40b7fc6e9b..39ea091b50 100644 --- a/libavcodec/bsf/Makefile +++ b/libavcodec/bsf/Makefile @@ -2,6 +2,7 @@ clean:: $(RM) $(CLEANSUFFIXES:%=libavcodec/bsf/%) OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += bsf/aac_adtstoasc.o +OBJS-$(CONFIG_APV_METADATA_BSF) += bsf/apv_metadata.o OBJS-$(CONFIG_AV1_FRAME_MERGE_BSF) += bsf/av1_frame_merge.o OBJS-$(CONFIG_AV1_FRAME_SPLIT_BSF) += bsf/av1_frame_split.o OBJS-$(CONFIG_AV1_METADATA_BSF) += bsf/av1_metadata.o diff --git a/libavcodec/bsf/apv_metadata.c b/libavcodec/bsf/apv_metadata.c new file mode 100644 index 0000000000..a1cdcf86c8 --- /dev/null +++ b/libavcodec/bsf/apv_metadata.c @@ -0,0 +1,134 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavutil/opt.h" + +#include "bsf.h" +#include "bsf_internal.h" +#include "cbs.h" +#include "cbs_bsf.h" +#include "cbs_apv.h" + +typedef struct APVMetadataContext { + CBSBSFContext common; + + int color_primaries; + int transfer_characteristics; + int matrix_coefficients; + int full_range_flag; +} APVMetadataContext; + + +static int apv_metadata_update_frame_header(AVBSFContext *bsf, + APVRawFrameHeader *hdr) +{ + APVMetadataContext *ctx = bsf->priv_data; + + if (ctx->color_primaries >= 0 || + ctx->transfer_characteristics >= 0 || + ctx->matrix_coefficients >= 0 || + ctx->full_range_flag >= 0) { + hdr->color_description_present_flag = 1; + + if (ctx->color_primaries >= 0) + hdr->color_primaries = ctx->color_primaries; + if (ctx->transfer_characteristics >= 0) + hdr->transfer_characteristics = ctx->transfer_characteristics; + if (ctx->matrix_coefficients >= 0) + hdr->matrix_coefficients = ctx->matrix_coefficients; + if (ctx->full_range_flag >= 0) + hdr->full_range_flag = ctx->full_range_flag; + } + + return 0; +} + +static int apv_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, + CodedBitstreamFragment *frag) +{ + int err, i; + + for (i = 0; i < frag->nb_units; i++) { + if (frag->units[i].type == APV_PBU_PRIMARY_FRAME) { + APVRawFrame *pbu = frag->units[i].content; + err = apv_metadata_update_frame_header(bsf, &pbu->frame_header); + if (err < 0) + return err; + } + } + + return 0; +} + +static const CBSBSFType apv_metadata_type = { + .codec_id = AV_CODEC_ID_APV, + .fragment_name = "access unit", + .unit_name = "PBU", + .update_fragment = &apv_metadata_update_fragment, +}; + +static int apv_metadata_init(AVBSFContext *bsf) +{ + return ff_cbs_bsf_generic_init(bsf, &apv_metadata_type); +} + +#define OFFSET(x) offsetof(APVMetadataContext, x) +#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM) +static const AVOption apv_metadata_options[] = { + { "color_primaries", "Set color primaries (section 5.3.5)", + OFFSET(color_primaries), AV_OPT_TYPE_INT, + { .i64 = -1 }, -1, 255, FLAGS }, + { "transfer_characteristics", "Set transfer characteristics (section 5.3.5)", + OFFSET(transfer_characteristics), AV_OPT_TYPE_INT, + { .i64 = -1 }, -1, 255, FLAGS }, + { "matrix_coefficients", "Set matrix coefficients (section 5.3.5)", + OFFSET(matrix_coefficients), AV_OPT_TYPE_INT, + { .i64 = -1 }, -1, 255, FLAGS }, + + { "full_range_flag", "Set full range flag flag (section 5.3.5)", + OFFSET(full_range_flag), AV_OPT_TYPE_INT, + { .i64 = -1 }, -1, 1, FLAGS, .unit = "cr" }, + { "tv", "TV (limited) range", 0, AV_OPT_TYPE_CONST, + { .i64 = 0 }, .flags = FLAGS, .unit = "cr" }, + { "pc", "PC (full) range", 0, AV_OPT_TYPE_CONST, + { .i64 = 1 }, .flags = FLAGS, .unit = "cr" }, + + { NULL } +}; + +static const AVClass apv_metadata_class = { + .class_name = "apv_metadata_bsf", + .item_name = av_default_item_name, + .option = apv_metadata_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +static const enum AVCodecID apv_metadata_codec_ids[] = { + AV_CODEC_ID_APV, AV_CODEC_ID_NONE, +}; + +const FFBitStreamFilter ff_apv_metadata_bsf = { + .p.name = "apv_metadata", + .p.codec_ids = apv_metadata_codec_ids, + .p.priv_class = &apv_metadata_class, + .priv_data_size = sizeof(APVMetadataContext), + .init = &apv_metadata_init, + .close = &ff_cbs_bsf_generic_close, + .filter = &ff_cbs_bsf_generic_filter, +}; -- 2.47.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2025-04-21 15:26 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-04-21 15:24 [FFmpeg-devel] [PATCH v2 0/6] APV support Mark Thompson 2025-04-21 15:24 ` [FFmpeg-devel] [PATCH v2 1/6] lavc: APV codec ID and descriptor Mark Thompson 2025-04-21 15:24 ` [FFmpeg-devel] [PATCH v2 2/6] lavc/cbs: APV support Mark Thompson 2025-04-21 15:24 ` [FFmpeg-devel] [PATCH v2 3/6] lavf: APV demuxer Mark Thompson 2025-04-21 15:24 ` [FFmpeg-devel] [PATCH v2 4/6] lavc: APV decoder Mark Thompson 2025-04-21 15:24 ` [FFmpeg-devel] [PATCH v2 5/6] lavc/apv: AVX2 transquant for x86-64 Mark Thompson 2025-04-21 16:53 ` James Almer 2025-04-21 19:50 ` Mark Thompson 2025-04-22 20:00 ` James Almer 2025-04-23 19:52 ` Michael Niedermayer 2025-04-23 20:47 ` Mark Thompson 2025-04-21 15:24 ` Mark Thompson [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250421152445.2110045-7-sw@jkqxz.net \ --to=sw@jkqxz.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git