FFmpeg
Loading...
Searching...
No Matches
h266_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"
26#include "libavcodec/cbs_h266.h"
27#include "libavcodec/vvc.h"
28
29#define IS_H266_SLICE(nut) (nut <= VVC_RASL_NUT || (nut >= VVC_IDR_W_RADL && nut <= VVC_GDR_NUT))
30
38
41{
43 int err, i;
44
45 // If an AUD is present, it must be the first NAL unit.
46 if (pu->nb_units && pu->units[0].type == VVC_AUD_NUT) {
47 if (ctx->aud == BSF_ELEMENT_REMOVE)
48 ff_cbs_delete_unit(pu, 0);
49 } else if ( pkt && ctx->aud == BSF_ELEMENT_INSERT) {
50 const H266RawSlice *first_slice = NULL;
52 H266RawAUD *aud = &ctx->aud_nal;
53 int pic_type = 0, temporal_id = 8, layer_id = 0;
54 for (i = 0; i < pu->nb_units; i++) {
56 if (!nal)
57 continue;
58 if (nal->nuh_temporal_id_plus1 < temporal_id + 1)
59 temporal_id = nal->nuh_temporal_id_plus1 - 1;
60 if ( nal->nal_unit_type == VVC_PH_NUT ) {
61 const H266RawPH *header = pu->units[i].content;
62 ph = &header->ph_picture_header;
63 } else if (IS_H266_SLICE(nal->nal_unit_type)) {
64 const H266RawSlice *slice = pu->units[i].content;
65 layer_id = nal->nuh_layer_id;
67 pic_type < 2)
68 pic_type = 2;
70 pic_type < 1)
71 pic_type = 1;
72 if (!first_slice) {
73 first_slice = slice;
74 if (first_slice->header.
75 sh_picture_header_in_slice_header_flag)
76 ph = &first_slice->header.sh_picture_header;
77 else if (!ph)
78 break;
79 }
80 }
81 }
82 if (!ph) {
83 av_log(bsf, AV_LOG_ERROR, "no available picture header");
85 }
86
87 aud->nal_unit_header = (H266RawNALUnitHeader) {
88 .nal_unit_type = VVC_AUD_NUT,
89 .nuh_layer_id = layer_id,
90 .nuh_temporal_id_plus1 = temporal_id + 1,
91 };
92 aud->aud_pic_type = pic_type;
93 aud->aud_irap_or_gdr_flag = ph->ph_gdr_or_irap_pic_flag;
94
95 err = ff_cbs_insert_unit_content(pu, 0, VVC_AUD_NUT, aud, NULL);
96 if (err < 0) {
97 av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n");
98 return err;
99 }
100 }
101
102 /* TODO: implement more metadata parsing, like VUI, Levels etc. */
103 //for (i = 0; i < pu->nb_units; i++) {
104 // if (pu->units[i].type == VVC_SPS_NUT) {
105 // }
106 //}
107 return 0;
108}
109
111 .codec_id = AV_CODEC_ID_VVC,
112 .fragment_name = "access unit",
113 .unit_name = "NAL unit",
114 .update_fragment = &h266_metadata_update_fragment,
115};
116
118{
120}
121
122#define OFFSET(x) offsetof(H266MetadataContext, x)
123#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
125 BSF_ELEMENT_OPTIONS_PIR("aud", "Access Unit Delimiter NAL units",
126 aud, FLAGS),
127
128 { NULL }
129};
130
132 .class_name = "h266_metadata_bsf",
133 .item_name = av_default_item_name,
134 .option = h266_metadata_options,
135 .version = LIBAVUTIL_VERSION_INT,
136};
137
141
143 .p.name = "vvc_metadata",
144 .p.codec_ids = h266_metadata_codec_ids,
145 .p.priv_class = &h266_metadata_class,
146 .priv_data_size = sizeof(H266MetadataContext),
150};
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
const FFBitStreamFilter ff_vvc_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 BSF_ELEMENT_OPTIONS_PIR(name, help, field, opt_flags)
Definition cbs_bsf.h:119
@ BSF_ELEMENT_REMOVE
Definition cbs_bsf.h:113
@ BSF_ELEMENT_INSERT
Definition cbs_bsf.h:111
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
static int FUNC ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
static int FUNC nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
#define FLAGS
Definition cmdutils.c:598
common internal and external API header
#define NULL
Definition coverity.c:32
static AVPacket * pkt
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_VVC
Definition codec_id.h:247
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
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 h266_metadata_class
static const AVOption h266_metadata_options[]
static int h266_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, CodedBitstreamFragment *pu)
static int h266_metadata_init(AVBSFContext *bsf)
static const CBSBSFType h266_metadata_type
static enum AVCodecID h266_metadata_codec_ids[]
#define IS_H266_SLICE(nut)
@ VVC_SLICE_TYPE_B
Definition vvc.h:64
@ VVC_SLICE_TYPE_P
Definition vvc.h:65
@ VVC_PH_NUT
Definition vvc.h:48
@ VVC_AUD_NUT
Definition vvc.h:49
AVOptions.
static const uint8_t header[24]
Definition sdr2.c:68
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
void * content
Pointer to the decomposed form of this unit.
Definition cbs.h:114
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition cbs.h:81
CBSBSFContext common
uint8_t sh_slice_type
Definition cbs_h266.h:780
H266RawPictureHeader sh_picture_header
Definition cbs_h266.h:774
H266RawSliceHeader header
Definition cbs_h266.h:844
#define av_log(a,...)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
static AVFormatContext * ctx
Definition movenc.c:49