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;
55 int position, err;
56
57 position = ff_cbs_lcevc_find_process_block(ctx->common.output, au,
59 &unit, &block);
60 if (position < 0)
61 return 0;
62
63 memset(ai, 0, sizeof(*ai));
65
66 if (ctx->overscan_appropriate_flag >= 0) {
68 vui->overscan_appropriate_flag = ctx->overscan_appropriate_flag;
69 }
70
71 if (ctx->video_format >= 0) {
73 vui->video_format = ctx->video_format;
74 } else
75 vui->video_format = 5;
76
77 if (ctx->video_full_range_flag >= 0) {
79 vui->video_full_range_flag = ctx->video_full_range_flag;
80 }
81
82 if (ctx->colour_primaries >= 0) {
84 vui->colour_primaries = ctx->colour_primaries;
85 } else
86 vui->colour_primaries = 2;
87 if (ctx->transfer_characteristics >= 0) {
89 vui->transfer_characteristics = ctx->transfer_characteristics;
90 } else
92 if (ctx->matrix_coefficients >= 0) {
94 vui->matrix_coefficients = ctx->matrix_coefficients;
95 } else
96 vui->matrix_coefficients = 2;
97
98 if (ctx->chroma_sample_loc_type >= 0) {
100 vui->chroma_sample_loc_type_top_field = ctx->chroma_sample_loc_type;
101 vui->chroma_sample_loc_type_bottom_field = ctx->chroma_sample_loc_type;
102 }
103
104 err = ff_cbs_lcevc_add_process_block(ctx->common.output, unit, position + 1,
106 ai, NULL);
107 if (err < 0)
108 return err;
109
110 return 0;
111}
112
115{
117 int err;
118
119 if (ctx->overscan_appropriate_flag >= 0 || ctx->video_format >= 0 ||
120 ctx->video_full_range_flag >= 0 || ctx->colour_primaries >= 0 ||
121 ctx->transfer_characteristics >= 0 || ctx->matrix_coefficients >= 0 ||
122 ctx->chroma_sample_loc_type >= 0) {
123 err = lcevc_metadata_handle_vui(bsf, au);
124 if (err < 0)
125 return err;
126 }
127
128 if (ctx->delete_filler) {
129 for (int i = 0; i < au->nb_units; i++) {
130 if (au->units[i].type == LCEVC_NON_IDR_NUT ||
131 au->units[i].type == LCEVC_IDR_NUT) {
134 }
135 }
136 }
137
138 return 0;
139}
140
142 .codec_id = AV_CODEC_ID_LCEVC,
143 .fragment_name = "access unit",
144 .unit_name = "NAL unit",
145 .update_fragment = &lcevc_metadata_update_fragment,
146};
147
152
153#define OFFSET(x) offsetof(LCEVCMetadataContext, x)
154#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
156 { "overscan_appropriate_flag", "Set VUI overscan appropriate flag",
157 OFFSET(overscan_appropriate_flag), AV_OPT_TYPE_BOOL,
158 { .i64 = -1 }, -1, 1, FLAGS },
159
160 { "video_format", "Set video format (table E-2)",
161 OFFSET(video_format), AV_OPT_TYPE_INT,
162 { .i64 = -1 }, -1, 5, FLAGS},
163 { "video_full_range_flag", "Set video full range flag",
164 OFFSET(video_full_range_flag), AV_OPT_TYPE_BOOL,
165 { .i64 = -1 }, -1, 1, FLAGS },
166 { "colour_primaries", "Set colour primaries (table E-3)",
167 OFFSET(colour_primaries), AV_OPT_TYPE_INT,
168 { .i64 = -1 }, -1, 255, FLAGS },
169 { "transfer_characteristics", "Set transfer characteristics (table E-4)",
171 { .i64 = -1 }, -1, 255, FLAGS },
172 { "matrix_coefficients", "Set matrix coefficients (table E-5)",
173 OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
174 { .i64 = -1 }, -1, 255, FLAGS },
175
176 { "chroma_sample_loc_type", "Set chroma sample location type (figure E-1)",
177 OFFSET(chroma_sample_loc_type), AV_OPT_TYPE_INT,
178 { .i64 = -1 }, -1, 5, FLAGS },
179
180 { "delete_filler", "Delete all filler",
181 OFFSET(delete_filler), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS},
182
183 { NULL }
184};
185
187 .class_name = "lcevc_metadata_bsf",
188 .item_name = av_default_item_name,
189 .option = lcevc_metadata_options,
190 .version = LIBAVUTIL_VERSION_INT,
191};
192
196
198 .p.name = "lcevc_metadata",
199 .p.codec_ids = lcevc_metadata_codec_ids,
200 .p.priv_class = &lcevc_metadata_class,
201 .priv_data_size = sizeof(LCEVCMetadataContext),
205};
static AVFormatContext * ctx
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, CodedBitstreamUnit *unit, int position, uint32_t payload_type, void *payload_data, void *payload_ref)
Add a process block to a NAL unit of type IDR or NON_IDR, at the given position of its block list or ...
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:712
int ff_cbs_lcevc_find_process_block(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, uint32_t payload_type, CodedBitstreamUnit **block_unit, LCEVCRawProcessBlock **iter)
Iterate over blocks with the given payload type in an access unit.
Definition cbs_lcevc.c:654
#define FLAGS
Definition cmdutils.c:596
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:613
@ 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:615
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
#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)
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition cbs.c:118
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:587
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
Coded bitstream unit structure.
Definition cbs.h:77
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