History

lavc: APV metadata bitstream filter

Mark Thompson committed 1 year ago

Commit de42e061 parent d03c9944 files · +137 −1Browse files

Unified · Split

4 files
  1. libavcodec/bitstream_filters.c +1 −0
  2. libavcodec/bsf/Makefile +1 −0
  3. libavcodec/bsf/apv_metadata.c +134 −0
  4. libavcodec/version.h +1 −1
libavcodec/bitstream_filters.c+1−0
@@ -25,6 +25,7 @@ · 24 unmodified lines
25#include "bsf_internal.h"25#include "bsf_internal.h"
26 26
27extern const FFBitStreamFilter ff_aac_adtstoasc_bsf;27extern const FFBitStreamFilter ff_aac_adtstoasc_bsf;
28extern const FFBitStreamFilter ff_apv_metadata_bsf;
28extern const FFBitStreamFilter ff_av1_frame_merge_bsf;29extern const FFBitStreamFilter ff_av1_frame_merge_bsf;
29extern const FFBitStreamFilter ff_av1_frame_split_bsf;30extern const FFBitStreamFilter ff_av1_frame_split_bsf;
30extern const FFBitStreamFilter ff_av1_metadata_bsf;31extern const FFBitStreamFilter ff_av1_metadata_bsf;
libavcodec/bsf/Makefile+1−0
@@ -2,6 +2,7 @@ clean:: · 1 unmodified line
2 $(RM) $(CLEANSUFFIXES:%=libavcodec/bsf/%)2 $(RM) $(CLEANSUFFIXES:%=libavcodec/bsf/%)
3 3
4OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += bsf/aac_adtstoasc.o4OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += bsf/aac_adtstoasc.o
5OBJS-$(CONFIG_APV_METADATA_BSF) += bsf/apv_metadata.o
5OBJS-$(CONFIG_AV1_FRAME_MERGE_BSF) += bsf/av1_frame_merge.o6OBJS-$(CONFIG_AV1_FRAME_MERGE_BSF) += bsf/av1_frame_merge.o
6OBJS-$(CONFIG_AV1_FRAME_SPLIT_BSF) += bsf/av1_frame_split.o7OBJS-$(CONFIG_AV1_FRAME_SPLIT_BSF) += bsf/av1_frame_split.o
7OBJS-$(CONFIG_AV1_METADATA_BSF) += bsf/av1_metadata.o8OBJS-$(CONFIG_AV1_METADATA_BSF) += bsf/av1_metadata.o
libavcodec/bsf/apv_metadata.c+134−0
@@ -0,0 +1,134 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "libavutil/common.h"
20#include "libavutil/opt.h"
21
22#include "bsf.h"
23#include "bsf_internal.h"
24#include "cbs.h"
25#include "cbs_bsf.h"
26#include "cbs_apv.h"
27
28typedef struct APVMetadataContext {
29 CBSBSFContext common;
30
31 int color_primaries;
32 int transfer_characteristics;
33 int matrix_coefficients;
34 int full_range_flag;
35} APVMetadataContext;
36
37
38static int apv_metadata_update_frame_header(AVBSFContext *bsf,
39 APVRawFrameHeader *hdr)
40{
41 APVMetadataContext *ctx = bsf->priv_data;
42
43 if (ctx->color_primaries >= 0 ||
44 ctx->transfer_characteristics >= 0 ||
45 ctx->matrix_coefficients >= 0 ||
46 ctx->full_range_flag >= 0) {
47 hdr->color_description_present_flag = 1;
48
49 if (ctx->color_primaries >= 0)
50 hdr->color_primaries = ctx->color_primaries;
51 if (ctx->transfer_characteristics >= 0)
52 hdr->transfer_characteristics = ctx->transfer_characteristics;
53 if (ctx->matrix_coefficients >= 0)
54 hdr->matrix_coefficients = ctx->matrix_coefficients;
55 if (ctx->full_range_flag >= 0)
56 hdr->full_range_flag = ctx->full_range_flag;
57 }
58
59 return 0;
60}
61
62static int apv_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt,
63 CodedBitstreamFragment *frag)
64{
65 int err, i;
66
67 for (i = 0; i < frag->nb_units; i++) {
68 if (frag->units[i].type == APV_PBU_PRIMARY_FRAME) {
69 APVRawFrame *pbu = frag->units[i].content;
70 err = apv_metadata_update_frame_header(bsf, &pbu->frame_header);
71 if (err < 0)
72 return err;
73 }
74 }
75
76 return 0;
77}
78
79static const CBSBSFType apv_metadata_type = {
80 .codec_id = AV_CODEC_ID_APV,
81 .fragment_name = "access unit",
82 .unit_name = "PBU",
83 .update_fragment = &apv_metadata_update_fragment,
84};
85
86static int apv_metadata_init(AVBSFContext *bsf)
87{
88 return ff_cbs_bsf_generic_init(bsf, &apv_metadata_type);
89}
90
91#define OFFSET(x) offsetof(APVMetadataContext, x)
92#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
93static const AVOption apv_metadata_options[] = {
94 { "color_primaries", "Set color primaries (section 5.3.5)",
95 OFFSET(color_primaries), AV_OPT_TYPE_INT,
96 { .i64 = -1 }, -1, 255, FLAGS },
97 { "transfer_characteristics", "Set transfer characteristics (section 5.3.5)",
98 OFFSET(transfer_characteristics), AV_OPT_TYPE_INT,
99 { .i64 = -1 }, -1, 255, FLAGS },
100 { "matrix_coefficients", "Set matrix coefficients (section 5.3.5)",
101 OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
102 { .i64 = -1 }, -1, 255, FLAGS },
103
104 { "full_range_flag", "Set full range flag flag (section 5.3.5)",
105 OFFSET(full_range_flag), AV_OPT_TYPE_INT,
106 { .i64 = -1 }, -1, 1, FLAGS, .unit = "cr" },
107 { "tv", "TV (limited) range", 0, AV_OPT_TYPE_CONST,
108 { .i64 = 0 }, .flags = FLAGS, .unit = "cr" },
109 { "pc", "PC (full) range", 0, AV_OPT_TYPE_CONST,
110 { .i64 = 1 }, .flags = FLAGS, .unit = "cr" },
111
112 { NULL }
113};
114
115static const AVClass apv_metadata_class = {
116 .class_name = "apv_metadata_bsf",
117 .item_name = av_default_item_name,
118 .option = apv_metadata_options,
119 .version = LIBAVUTIL_VERSION_INT,
120};
121
122static const enum AVCodecID apv_metadata_codec_ids[] = {
123 AV_CODEC_ID_APV, AV_CODEC_ID_NONE,
124};
125
126const FFBitStreamFilter ff_apv_metadata_bsf = {
127 .p.name = "apv_metadata",
128 .p.codec_ids = apv_metadata_codec_ids,
129 .p.priv_class = &apv_metadata_class,
130 .priv_data_size = sizeof(APVMetadataContext),
131 .init = &apv_metadata_init,
132 .close = &ff_cbs_bsf_generic_close,
133 .filter = &ff_cbs_bsf_generic_filter,
134};
libavcodec/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30#include "version_major.h"30#include "version_major.h"
31 31
32#define LIBAVCODEC_VERSION_MINOR 132#define LIBAVCODEC_VERSION_MINOR 1
33#define LIBAVCODEC_VERSION_MICRO 10133#define LIBAVCODEC_VERSION_MICRO 102
34 34
35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
36 LIBAVCODEC_VERSION_MINOR, \36 LIBAVCODEC_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t