FFmpeg
Loading...
Searching...
No Matches
lcevc_metadata.c
Go to the documentation of this file.
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 "libavcodec/bsf.h"
24#include "libavcodec/cbs.h"
25#include "libavcodec/cbs_bsf.h"
27#include "libavcodec/lcevc.h"
28
46
49{
52 LCEVCRawAdditionalInfo *ai = &ctx->ai;
53 LCEVCRawVUI *vui = &ai->vui;
54 int position, err;
55
56 position = ff_cbs_lcevc_find_process_block(ctx->common.output, au,
58 &block);
59 if (position < 0)
60 return 0;
61
62 memset(ai, 0, sizeof(*ai));
64
65 if (ctx->overscan_appropriate_flag >= 0) {
67 vui->overscan_appropriate_flag = ctx->overscan_appropriate_flag;
68 }
69
70 if (ctx->video_format >= 0) {
72 vui->video_format = ctx->video_format;
73 } else
74 vui->video_format = 5;
75
76 if (ctx->video_full_range_flag >= 0) {
78 vui->video_full_range_flag = ctx->video_full_range_flag;
79 }
80
81 if (ctx->colour_primaries >= 0) {
83 vui->colour_primaries = ctx->colour_primaries;
84 } else
85 vui->colour_primaries = 2;
86 if (ctx->transfer_characteristics >= 0) {
88 vui->transfer_characteristics = ctx->transfer_characteristics;
89 } else
91 if (ctx->matrix_coefficients >= 0) {
93 vui->matrix_coefficients = ctx->matrix_coefficients;
94 } else
95 vui->matrix_coefficients = 2;
96
97 if (ctx->chroma_sample_loc_type >= 0) {
99 vui->chroma_sample_loc_type_top_field = ctx->chroma_sample_loc_type;
100 vui->chroma_sample_loc_type_bottom_field = ctx->chroma_sample_loc_type;
101 }
102
103 err = ff_cbs_lcevc_add_process_block(ctx->common.output, au, position + 1,
105 ai, NULL);
106 if (err < 0)
107 return err;
108
109 return 0;
110}
111
114{
116 int err;
117
118 if (ctx->overscan_appropriate_flag >= 0 || ctx->video_format >= 0 ||
119 ctx->video_full_range_flag >= 0 || ctx->colour_primaries >= 0 ||
120 ctx->transfer_characteristics >= 0 || ctx->matrix_coefficients >= 0 ||
121 ctx->chroma_sample_loc_type >= 0) {
122 err = lcevc_metadata_handle_vui(bsf, au);
123 if (err < 0)
124 return err;
125 }
126
127 if (ctx->delete_filler) {
128 for (int i = 0; i < au->nb_units; i++) {
129 if (au->units[i].type == LCEVC_NON_IDR_NUT ||
130 au->units[i].type == LCEVC_IDR_NUT) {
133 }
134 }
135 }
136
137 return 0;
138}
139
141 .codec_id = AV_CODEC_ID_LCEVC,
142 .fragment_name = "access unit",
143 .unit_name = "NAL unit",
144 .update_fragment = &lcevc_metadata_update_fragment,
145};
146
151
152#define OFFSET(x) offsetof(LCEVCMetadataContext, x)
153#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
155 { "overscan_appropriate_flag", "Set VUI overscan appropriate flag",
156 OFFSET(overscan_appropriate_flag), AV_OPT_TYPE_BOOL,
157 { .i64 = -1 }, -1, 1, FLAGS },
158
159 { "video_format", "Set video format (table E-2)",
160 OFFSET(video_format), AV_OPT_TYPE_INT,
161 { .i64 = -1 }, -1, 5, FLAGS},
162 { "video_full_range_flag", "Set video full range flag",
163 OFFSET(video_full_range_flag), AV_OPT_TYPE_BOOL,
164 { .i64 = -1 }, -1, 1, FLAGS },
165 { "colour_primaries", "Set colour primaries (table E-3)",
166 OFFSET(colour_primaries), AV_OPT_TYPE_INT,
167 { .i64 = -1 }, -1, 255, FLAGS },
168 { "transfer_characteristics", "Set transfer characteristics (table E-4)",
170 { .i64 = -1 }, -1, 255, FLAGS },
171 { "matrix_coefficients", "Set matrix coefficients (table E-5)",
172 OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
173 { .i64 = -1 }, -1, 255, FLAGS },
174
175 { "chroma_sample_loc_type", "Set chroma sample location type (figure E-1)",
176 OFFSET(chroma_sample_loc_type), AV_OPT_TYPE_INT,
177 { .i64 = -1 }, -1, 5, FLAGS },
178
179 { "delete_filler", "Delete all filler",
180 OFFSET(delete_filler), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS},
181
182 { NULL }
183};
184
186 .class_name = "lcevc_metadata_bsf",
187 .item_name = av_default_item_name,
188 .option = lcevc_metadata_options,
189 .version = LIBAVUTIL_VERSION_INT,
190};
191
195
197 .p.name = "lcevc_metadata",
198 .p.codec_ids = lcevc_metadata_codec_ids,
199 .p.priv_class = &lcevc_metadata_class,
200 .priv_data_size = sizeof(LCEVCMetadataContext),
204};
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
const FFBitStreamFilter ff_lcevc_metadata_bsf
int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt)
Filter operation for CBS BSF.
Definition cbs_bsf.c:97
av_cold void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
Definition cbs_bsf.c:191
av_cold int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
Definition cbs_bsf.c:146
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
int ff_cbs_lcevc_add_process_block(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, int position, uint32_t payload_type, void *payload_data, void *payload_ref)
Add a process block to an access unit.
Definition cbs_lcevc.c:610
void ff_cbs_lcevc_delete_process_block_type(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, uint32_t payload_type)
Delete all blocks with the given payload type from an access unit.
Definition cbs_lcevc.c:717
int ff_cbs_lcevc_find_process_block(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, uint32_t payload_type, LCEVCRawProcessBlock **iter)
Iterate over blocks with the given payload type in an access unit.
Definition cbs_lcevc.c:662
#define FLAGS
Definition cmdutils.c:598
common internal and external API header
#define NULL
Definition coverity.c:32
static int16_t block[64]
Definition dct.c:125
static AVPacket * pkt
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_LCEVC
Definition codec_id.h:609
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static const AVClass lcevc_metadata_class
static enum AVCodecID lcevc_metadata_codec_ids[]
static int lcevc_metadata_init(AVBSFContext *bsf)
static int lcevc_metadata_handle_vui(AVBSFContext *bsf, CodedBitstreamFragment *au)
static const AVOption lcevc_metadata_options[]
static const CBSBSFType lcevc_metadata_type
static int lcevc_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, CodedBitstreamFragment *au)
#define OFFSET(x)
LCEVC common definitions.
@ LCEVC_PAYLOAD_TYPE_FILLER
Definition lcevc.h:76
@ LCEVC_PAYLOAD_TYPE_ADDITIONAL_INFO
Definition lcevc.h:75
@ LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG
Definition lcevc.h:71
@ LCEVC_ADDITIONAL_INFO_TYPE_VUI
Definition lcevc.h:81
@ LCEVC_NON_IDR_NUT
Definition lcevc.h:60
@ LCEVC_IDR_NUT
Definition lcevc.h:61
static const struct TransferCharacteristics transfer_characteristics[]
AVOptions.
The bitstream filter state.
Definition bsf.h:68
void * priv_data
Opaque filter-specific private data.
Definition bsf.h:83
Describe the class of an AVClass context structure.
Definition log.h:76
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition cbs.h:175
int nb_units
Number of units in this fragment.
Definition cbs.h:160
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition cbs.h:81
LCEVCRawAdditionalInfo ai
uint8_t overscan_appropriate_flag
Definition cbs_lcevc.h:138
uint8_t matrix_coefficients
Definition cbs_lcevc.h:145
uint8_t video_full_range_flag
Definition cbs_lcevc.h:141
uint8_t overscan_info_present_flag
Definition cbs_lcevc.h:137
uint8_t video_format
Definition cbs_lcevc.h:140
uint8_t chroma_sample_loc_type_bottom_field
Definition cbs_lcevc.h:148
uint8_t transfer_characteristics
Definition cbs_lcevc.h:144
uint8_t colour_description_present_flag
Definition cbs_lcevc.h:142
uint8_t chroma_loc_info_present_flag
Definition cbs_lcevc.h:146
uint8_t chroma_sample_loc_type_top_field
Definition cbs_lcevc.h:147
uint8_t colour_primaries
Definition cbs_lcevc.h:143
uint8_t video_signal_type_present_flag
Definition cbs_lcevc.h:139
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29