76 int max_dec_pic_buffering = 0;
85 ptl = &
vps->profile_tier_level;
86 max_dec_pic_buffering =
vps->vps_max_dec_pic_buffering_minus1[0] + 1;
88 if (
vps->vps_num_hrd_parameters > 0)
89 hrd = &
vps->hrd_parameters[0];
94 ptl = &
sps->profile_tier_level;
95 max_dec_pic_buffering =
sps->sps_max_dec_pic_buffering_minus1[0] + 1;
97 width =
sps->pic_width_in_luma_samples;
100 if (
sps->vui.vui_hrd_parameters_present_flag)
101 hrd = &
sps->vui.hrd_parameters;
106 if (
pps->tiles_enabled_flag) {
121 bit_rate = bit_rate * 11 / 10;
127 max_dec_pic_buffering);
130 "level %s.\n",
desc->name);
131 ctx->level_guess =
desc->level_idc;
142 if (
ctx->level_guess) {
145 if (!
ctx->level_warned) {
147 "of stream: using level 8.5.\n");
148 ctx->level_warned = 1;
163 if (
ctx->tick_rate.num &&
ctx->tick_rate.den) {
167 UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
169 vps->vps_time_scale = num;
170 vps->vps_num_units_in_tick = den;
172 vps->vps_timing_info_present_flag = 1;
174 if (
ctx->num_ticks_poc_diff_one > 0) {
175 vps->vps_num_ticks_poc_diff_one_minus1 =
176 ctx->num_ticks_poc_diff_one - 1;
177 vps->vps_poc_proportional_to_timing_flag = 1;
178 }
else if (
ctx->num_ticks_poc_diff_one == 0) {
179 vps->vps_poc_proportional_to_timing_flag = 0;
193 int crop_unit_x, crop_unit_y;
195 if (
ctx->sample_aspect_ratio.num &&
ctx->sample_aspect_ratio.den) {
199 { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
200 { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
201 { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
202 { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
207 ctx->sample_aspect_ratio.den, 65535);
210 if (num == sar_idc[
i].num &&
211 den == sar_idc[
i].den)
215 sps->vui.aspect_ratio_idc = 255;
216 sps->vui.sar_width = num;
217 sps->vui.sar_height = den;
219 sps->vui.aspect_ratio_idc =
i;
221 sps->vui.aspect_ratio_info_present_flag = 1;
225 #define SET_OR_INFER(field, value, present_flag, infer) do { \
229 } else if (!present_flag) \
233 if (
ctx->video_format >= 0 ||
234 ctx->video_full_range_flag >= 0 ||
235 ctx->colour_primaries >= 0 ||
236 ctx->transfer_characteristics >= 0 ||
237 ctx->matrix_coefficients >= 0) {
240 sps->vui.video_signal_type_present_flag, 5);
243 ctx->video_full_range_flag,
244 sps->vui.video_signal_type_present_flag, 0);
246 if (
ctx->colour_primaries >= 0 ||
247 ctx->transfer_characteristics >= 0 ||
248 ctx->matrix_coefficients >= 0) {
251 ctx->colour_primaries,
252 sps->vui.colour_description_present_flag, 2);
255 ctx->transfer_characteristics,
256 sps->vui.colour_description_present_flag, 2);
259 ctx->matrix_coefficients,
260 sps->vui.colour_description_present_flag, 2);
262 sps->vui.colour_description_present_flag = 1;
264 sps->vui.video_signal_type_present_flag = 1;
268 if (
ctx->chroma_sample_loc_type >= 0) {
269 sps->vui.chroma_sample_loc_type_top_field =
270 ctx->chroma_sample_loc_type;
271 sps->vui.chroma_sample_loc_type_bottom_field =
272 ctx->chroma_sample_loc_type;
273 sps->vui.chroma_loc_info_present_flag = 1;
277 if (
ctx->tick_rate.num &&
ctx->tick_rate.den) {
281 UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
283 sps->vui.vui_time_scale = num;
284 sps->vui.vui_num_units_in_tick = den;
286 sps->vui.vui_timing_info_present_flag = 1;
289 if (
ctx->num_ticks_poc_diff_one > 0) {
290 sps->vui.vui_num_ticks_poc_diff_one_minus1 =
291 ctx->num_ticks_poc_diff_one - 1;
292 sps->vui.vui_poc_proportional_to_timing_flag = 1;
293 }
else if (
ctx->num_ticks_poc_diff_one == 0) {
294 sps->vui.vui_poc_proportional_to_timing_flag = 0;
298 if (
sps->separate_colour_plane_flag ||
sps->chroma_format_idc == 0) {
302 crop_unit_x = 1 + (
sps->chroma_format_idc < 3);
303 crop_unit_y = 1 + (
sps->chroma_format_idc < 2);
305 #define CROP(border, unit) do { \
306 if (ctx->crop_ ## border >= 0) { \
307 if (ctx->crop_ ## border % unit != 0) { \
308 av_log(bsf, AV_LOG_ERROR, "Invalid value for crop_%s: " \
309 "must be a multiple of %d.\n", #border, unit); \
310 return AVERROR(EINVAL); \
312 sps->conf_win_ ## border ## _offset = \
313 ctx->crop_ ## border / unit; \
314 sps->conformance_window_flag = 1; \
317 CROP(left, crop_unit_x);
318 CROP(right, crop_unit_x);
319 CROP(top, crop_unit_y);
320 CROP(bottom, crop_unit_y);
324 sps->vui_parameters_present_flag = 1;
344 int pic_type = 0, temporal_id = 8, layer_id = 0;
367 .nuh_layer_id = layer_id,
368 .nuh_temporal_id_plus1 = temporal_id + 1,
370 aud->pic_type = pic_type;
401 .fragment_name =
"access unit",
402 .unit_name =
"NAL unit",
411 #define OFFSET(x) offsetof(H265MetadataContext, x)
412 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
417 {
"sample_aspect_ratio",
"Set sample aspect ratio (table E-1)",
419 { .dbl = 0.0 }, 0, 65535,
FLAGS },
421 {
"video_format",
"Set video format (table E-2)",
423 { .i64 = -1 }, -1, 7,
FLAGS },
424 {
"video_full_range_flag",
"Set video full range flag",
426 { .i64 = -1 }, -1, 1,
FLAGS },
427 {
"colour_primaries",
"Set colour primaries (table E-3)",
429 { .i64 = -1 }, -1, 255,
FLAGS },
430 {
"transfer_characteristics",
"Set transfer characteristics (table E-4)",
432 { .i64 = -1 }, -1, 255,
FLAGS },
433 {
"matrix_coefficients",
"Set matrix coefficients (table E-5)",
435 { .i64 = -1 }, -1, 255,
FLAGS },
437 {
"chroma_sample_loc_type",
"Set chroma sample location type (figure E-1)",
439 { .i64 = -1 }, -1, 6,
FLAGS },
442 "Set VPS and VUI tick rate (num_units_in_tick / time_scale)",
444 { .dbl = 0.0 }, 0, UINT_MAX,
FLAGS },
445 {
"num_ticks_poc_diff_one",
446 "Set VPS and VUI number of ticks per POC increment",
448 { .i64 = -1 }, -1, INT_MAX,
FLAGS },
450 {
"crop_left",
"Set left border crop offset",
453 {
"crop_right",
"Set right border crop offset",
456 {
"crop_top",
"Set top border crop offset",
459 {
"crop_bottom",
"Set bottom border crop offset",
463 {
"level",
"Set level (tables A.6 and A.7)",
466 {
"auto",
"Attempt to guess level from stream properties",
469 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
470 { .i64 = value }, .flags = FLAGS, .unit = "level"
473 {
LEVEL(
"2.1", 63) },
475 {
LEVEL(
"3.1", 93) },
477 {
LEVEL(
"4.1", 123) },
479 {
LEVEL(
"5.1", 153) },
480 {
LEVEL(
"5.2", 156) },
482 {
LEVEL(
"6.1", 183) },
483 {
LEVEL(
"6.2", 186) },
484 {
LEVEL(
"8.5", 255) },
502 .
name =
"hevc_metadata",
static enum AVCodecID codec_ids[]
static av_cold int init(AVCodecContext *avctx)
void ff_cbs_delete_unit(CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt)
Filter operation for CBS BSF.
int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
#define BSF_ELEMENT_OPTIONS_PIR(name, help, field, opt_flags)
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int len, int clip)
common internal and external API header
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define LIBAVUTIL_VERSION_INT
const H265RawProfileTierLevel * ptl
const H265LevelDescriptor * ff_h265_guess_level(const H265RawProfileTierLevel *ptl, int64_t bitrate, int width, int height, int slice_segments, int tile_rows, int tile_cols, int max_dec_pic_buffering)
Guess the level of a stream from some parameters.
static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
#define FF_ARRAY_ELEMS(a)
The bitstream filter state.
void * priv_data
Opaque filter-specific private data.
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
This structure stores compressed data.
Rational number (pair of numerator and denominator).
Coded bitstream fragment structure, combining one or more units.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
int nb_units
Number of units in this fragment.
Coded bitstream unit structure.
void * content
Pointer to the decomposed form of this unit.
CodedBitstreamUnitType type
Codec-specific type of this unit.
int chroma_sample_loc_type
int num_ticks_poc_diff_one
AVRational sample_aspect_ratio
int video_full_range_flag
int poc_proportional_to_timing_flag
int transfer_characteristics
H265RawSubLayerHRDParameters vcl_sub_layer_hrd_parameters[HEVC_MAX_SUB_LAYERS]
uint8_t nal_hrd_parameters_present_flag
uint8_t vcl_hrd_parameters_present_flag
H265RawSubLayerHRDParameters nal_sub_layer_hrd_parameters[HEVC_MAX_SUB_LAYERS]
H265RawSliceHeader header
uint32_t bit_rate_value_minus1[HEVC_MAX_CPB_CNT]