81 int max_dec_pic_buffering = 0;
90 ptl = &
vps->profile_tier_level;
91 max_dec_pic_buffering =
vps->vps_max_dec_pic_buffering_minus1[0] + 1;
93 if (
vps->vps_num_hrd_parameters > 0)
94 hrd = &
vps->hrd_parameters[0];
99 ptl = &
sps->profile_tier_level;
100 max_dec_pic_buffering =
sps->sps_max_dec_pic_buffering_minus1[0] + 1;
102 width =
sps->pic_width_in_luma_samples;
103 height =
sps->pic_height_in_luma_samples;
105 if (
sps->vui.vui_hrd_parameters_present_flag)
106 hrd = &
sps->vui.hrd_parameters;
111 if (
pps->tiles_enabled_flag) {
126 bit_rate = bit_rate * 11 / 10;
132 max_dec_pic_buffering);
135 "level %s.\n",
desc->name);
136 ctx->level_guess =
desc->level_idc;
147 if (
ctx->level_guess) {
150 if (!
ctx->level_warned) {
152 "of stream: using level 8.5.\n");
153 ctx->level_warned = 1;
168 if (
ctx->tick_rate.num &&
ctx->tick_rate.den) {
172 UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
174 vps->vps_time_scale = num;
175 vps->vps_num_units_in_tick = den;
177 vps->vps_timing_info_present_flag = 1;
179 if (
ctx->num_ticks_poc_diff_one > 0) {
180 vps->vps_num_ticks_poc_diff_one_minus1 =
181 ctx->num_ticks_poc_diff_one - 1;
182 vps->vps_poc_proportional_to_timing_flag = 1;
183 }
else if (
ctx->num_ticks_poc_diff_one == 0) {
184 vps->vps_poc_proportional_to_timing_flag = 0;
194 int *crop_left,
int *crop_right,
195 int *crop_top,
int *crop_bottom)
199 int right =
ctx->crop_right;
200 int top =
ctx->crop_top;
201 int bottom =
ctx->crop_bottom;
203 if (
ctx->width > 0) {
204 if (
ctx->width >
sps->pic_width_in_luma_samples) {
206 "The width option value %d is larger than picture width %d\n",
207 ctx->width,
sps->pic_width_in_luma_samples);
213 left =
sps->pic_width_in_luma_samples -
ctx->width - right;
219 right =
sps->pic_width_in_luma_samples -
ctx->width -
left;
221 if (
left < 0 || right < 0 || (
left + right +
ctx->width) !=
222 sps->pic_width_in_luma_samples) {
224 "Invalid value for crop_left %d, crop_right %d, width after "
225 "crop %d, with picture width %d\n",
226 ctx->crop_left,
ctx->crop_right,
ctx->width,
227 sps->pic_width_in_luma_samples);
232 if (
ctx->height > 0) {
233 if (
ctx->height >
sps->pic_height_in_luma_samples) {
235 "The height option value %d is larger than picture height %d\n",
236 ctx->height,
sps->pic_height_in_luma_samples);
242 top =
sps->pic_height_in_luma_samples -
ctx->height - bottom;
248 bottom =
sps->pic_height_in_luma_samples -
ctx->height - top;
250 if (top < 0 || bottom < 0 || (top + bottom +
ctx->height) !=
251 sps->pic_height_in_luma_samples) {
253 "Invalid value for crop_top %d, crop_bottom %d, height after "
254 "crop %d, with picture height %d\n",
255 ctx->crop_top,
ctx->crop_bottom,
ctx->height,
256 sps->pic_height_in_luma_samples);
264 *crop_bottom = bottom;
274 int crop_unit_x, crop_unit_y;
279 int crop_left, crop_right, crop_top, crop_bottom;
282 if (
ctx->sample_aspect_ratio.num &&
ctx->sample_aspect_ratio.den) {
286 ctx->sample_aspect_ratio.den, 65535);
294 sps->vui.aspect_ratio_idc = 255;
295 sps->vui.sar_width = num;
296 sps->vui.sar_height = den;
298 sps->vui.aspect_ratio_idc =
i;
300 sps->vui.aspect_ratio_info_present_flag = 1;
304#define SET_OR_INFER(field, value, present_flag, infer) do { \
308 } else if (!present_flag) \
312 if (
ctx->video_format >= 0 ||
313 ctx->video_full_range_flag >= 0 ||
314 ctx->colour_primaries >= 0 ||
315 ctx->transfer_characteristics >= 0 ||
316 ctx->matrix_coefficients >= 0) {
319 sps->vui.video_signal_type_present_flag, 5);
322 ctx->video_full_range_flag,
323 sps->vui.video_signal_type_present_flag, 0);
325 if (
ctx->colour_primaries >= 0 ||
326 ctx->transfer_characteristics >= 0 ||
327 ctx->matrix_coefficients >= 0) {
330 ctx->colour_primaries,
331 sps->vui.colour_description_present_flag, 2);
334 ctx->transfer_characteristics,
335 sps->vui.colour_description_present_flag, 2);
338 ctx->matrix_coefficients,
339 sps->vui.colour_description_present_flag, 2);
341 sps->vui.colour_description_present_flag = 1;
343 sps->vui.video_signal_type_present_flag = 1;
347 if (
ctx->chroma_sample_loc_type >= 0) {
348 sps->vui.chroma_sample_loc_type_top_field =
349 ctx->chroma_sample_loc_type;
350 sps->vui.chroma_sample_loc_type_bottom_field =
351 ctx->chroma_sample_loc_type;
352 sps->vui.chroma_loc_info_present_flag = 1;
356 if (
ctx->tick_rate.num &&
ctx->tick_rate.den) {
360 UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
362 sps->vui.vui_time_scale = num;
363 sps->vui.vui_num_units_in_tick = den;
365 sps->vui.vui_timing_info_present_flag = 1;
368 if (
ctx->num_ticks_poc_diff_one > 0) {
369 sps->vui.vui_num_ticks_poc_diff_one_minus1 =
370 ctx->num_ticks_poc_diff_one - 1;
371 sps->vui.vui_poc_proportional_to_timing_flag = 1;
372 }
else if (
ctx->num_ticks_poc_diff_one == 0) {
373 sps->vui.vui_poc_proportional_to_timing_flag = 0;
378 &crop_top, &crop_bottom);
382 if (
sps->separate_colour_plane_flag ||
sps->chroma_format_idc == 0) {
386 crop_unit_x = 1 + (
sps->chroma_format_idc < 3);
387 crop_unit_y = 1 + (
sps->chroma_format_idc < 2);
389#define CROP(border, unit) do { \
390 if (crop_ ## border >= 0) { \
391 if (crop_ ## border % unit != 0) { \
392 av_log(bsf, AV_LOG_ERROR, "Invalid value for crop_%s: " \
393 "must be a multiple of %d.\n", #border, unit); \
394 return AVERROR(EINVAL); \
396 sps->conf_win_ ## border ## _offset = \
397 crop_ ## border / unit; \
398 sps->conformance_window_flag = 1; \
402 CROP(right, crop_unit_x);
403 CROP(top, crop_unit_y);
404 CROP(bottom, crop_unit_y);
408 sps->vui_parameters_present_flag = 1;
424 ff_cbs_delete_unit(au, 0);
428 int pic_type = 0, temporal_id = 8, layer_id = 0;
434 if (
nal->nuh_temporal_id_plus1 < temporal_id + 1)
435 temporal_id =
nal->nuh_temporal_id_plus1 - 1;
439 layer_id =
nal->nuh_layer_id;
451 .nuh_layer_id = layer_id,
452 .nuh_temporal_id_plus1 = temporal_id + 1,
454 aud->pic_type = pic_type;
485 .fragment_name =
"access unit",
486 .unit_name =
"NAL unit",
495#define OFFSET(x) offsetof(H265MetadataContext, x)
496#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
501 {
"sample_aspect_ratio",
"Set sample aspect ratio (table E-1)",
503 { .dbl = 0.0 }, 0, 65535,
FLAGS },
505 {
"video_format",
"Set video format (table E-2)",
507 { .i64 = -1 }, -1, 7,
FLAGS },
508 {
"video_full_range_flag",
"Set video full range flag",
510 { .i64 = -1 }, -1, 1,
FLAGS },
511 {
"colour_primaries",
"Set colour primaries (table E-3)",
513 { .i64 = -1 }, -1, 255,
FLAGS },
514 {
"transfer_characteristics",
"Set transfer characteristics (table E-4)",
516 { .i64 = -1 }, -1, 255,
FLAGS },
517 {
"matrix_coefficients",
"Set matrix coefficients (table E-5)",
519 { .i64 = -1 }, -1, 255,
FLAGS },
521 {
"chroma_sample_loc_type",
"Set chroma sample location type (figure E-1)",
523 { .i64 = -1 }, -1, 5,
FLAGS },
526 "Set VPS and VUI tick rate (time_scale / num_units_in_tick)",
528 { .dbl = 0.0 }, 0, UINT_MAX,
FLAGS },
529 {
"num_ticks_poc_diff_one",
530 "Set VPS and VUI number of ticks per POC increment",
532 { .i64 = -1 }, -1, INT_MAX,
FLAGS },
534 {
"crop_left",
"Set left border crop offset",
537 {
"crop_right",
"Set right border crop offset",
540 {
"crop_top",
"Set top border crop offset",
543 {
"crop_bottom",
"Set bottom border crop offset",
546 {
"width",
"Set width after crop",
549 {
"height",
"Set height after crop",
553 {
"level",
"Set level (tables A.6 and A.7)",
556 {
"auto",
"Attempt to guess level from stream properties",
559#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
560 { .i64 = value }, .flags = FLAGS, .unit = "level"
563 {
LEVEL(
"2.1", 63) },
565 {
LEVEL(
"3.1", 93) },
567 {
LEVEL(
"4.1", 123) },
569 {
LEVEL(
"5.1", 153) },
570 {
LEVEL(
"5.2", 156) },
572 {
LEVEL(
"6.1", 183) },
573 {
LEVEL(
"6.2", 186) },
574 {
LEVEL(
"8.5", 255) },
581 .class_name =
"h265_metadata_bsf",
592 .p.name =
"hevc_metadata",
static av_cold void close(AVCodecParserContext *s)
const FFBitStreamFilter ff_hevc_metadata_bsf
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt)
Filter operation for CBS BSF.
av_cold void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
av_cold int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
#define BSF_ELEMENT_OPTIONS_PIR(name, help, field, opt_flags)
#define i(width, name, range_min, range_max)
static int FUNC aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static int FUNC nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
common internal and external API header
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT
Underlying C type is int.
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 AVRational ff_h2645_pixel_aspect[]
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[]
#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.
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]
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
static AVFormatContext * ctx