FFmpeg
h265_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 "bsf.h"
23 #include "bsf_internal.h"
24 #include "cbs.h"
25 #include "cbs_bsf.h"
26 #include "cbs_h265.h"
27 #include "h2645data.h"
28 #include "hevc.h"
29 #include "h265_profile_level.h"
30 
31 enum {
33  LEVEL_AUTO = -1,
34 };
35 
36 typedef struct H265MetadataContext {
38 
40 
41  int aud;
42 
44 
50 
52 
56 
57  int crop_left;
59  int crop_top;
61 
62  int level;
66 
67 
69  const CodedBitstreamFragment *au)
70 {
74  const H265RawHRDParameters *hrd = NULL;
75  int64_t bit_rate = 0;
76  int width = 0, height = 0;
77  int tile_cols = 0, tile_rows = 0;
78  int max_dec_pic_buffering = 0;
79  int i;
80 
81  for (i = 0; i < au->nb_units; i++) {
82  const CodedBitstreamUnit *unit = &au->units[i];
83 
84  if (unit->type == HEVC_NAL_VPS) {
85  const H265RawVPS *vps = unit->content;
86 
87  ptl = &vps->profile_tier_level;
88  max_dec_pic_buffering = vps->vps_max_dec_pic_buffering_minus1[0] + 1;
89 
90  if (vps->vps_num_hrd_parameters > 0)
91  hrd = &vps->hrd_parameters[0];
92 
93  } else if (unit->type == HEVC_NAL_SPS) {
94  const H265RawSPS *sps = unit->content;
95 
96  ptl = &sps->profile_tier_level;
97  max_dec_pic_buffering = sps->sps_max_dec_pic_buffering_minus1[0] + 1;
98 
99  width = sps->pic_width_in_luma_samples;
100  height = sps->pic_height_in_luma_samples;
101 
102  if (sps->vui.vui_hrd_parameters_present_flag)
103  hrd = &sps->vui.hrd_parameters;
104 
105  } else if (unit->type == HEVC_NAL_PPS) {
106  const H265RawPPS *pps = unit->content;
107 
108  if (pps->tiles_enabled_flag) {
109  tile_cols = pps->num_tile_columns_minus1 + 1;
110  tile_rows = pps->num_tile_rows_minus1 + 1;
111  }
112  }
113  }
114 
115  if (hrd) {
117  bit_rate = (hrd->nal_sub_layer_hrd_parameters[0].bit_rate_value_minus1[0] + 1) *
118  (INT64_C(1) << hrd->bit_rate_scale + 6);
119  } else if (hrd->vcl_hrd_parameters_present_flag) {
120  bit_rate = (hrd->vcl_sub_layer_hrd_parameters[0].bit_rate_value_minus1[0] + 1) *
121  (INT64_C(1) << hrd->bit_rate_scale + 6);
122  // Adjust for VCL vs. NAL limits.
123  bit_rate = bit_rate * 11 / 10;
124  }
125  }
126 
127  desc = ff_h265_guess_level(ptl, bit_rate, width, height,
128  0, tile_rows, tile_cols,
129  max_dec_pic_buffering);
130  if (desc) {
131  av_log(bsf, AV_LOG_DEBUG, "Stream appears to conform to "
132  "level %s.\n", desc->name);
133  ctx->level_guess = desc->level_idc;
134  }
135 }
136 
138  uint8_t *level_idc)
139 {
141 
142  if (ctx->level != LEVEL_UNSET) {
143  if (ctx->level == LEVEL_AUTO) {
144  if (ctx->level_guess) {
145  *level_idc = ctx->level_guess;
146  } else {
147  if (!ctx->level_warned) {
148  av_log(bsf, AV_LOG_WARNING, "Unable to determine level "
149  "of stream: using level 8.5.\n");
150  ctx->level_warned = 1;
151  }
152  *level_idc = 255;
153  }
154  } else {
155  *level_idc = ctx->level;
156  }
157  }
158 }
159 
161  H265RawVPS *vps)
162 {
164 
165  if (ctx->tick_rate.num && ctx->tick_rate.den) {
166  int num, den;
167 
168  av_reduce(&num, &den, ctx->tick_rate.num, ctx->tick_rate.den,
169  UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
170 
171  vps->vps_time_scale = num;
172  vps->vps_num_units_in_tick = den;
173 
174  vps->vps_timing_info_present_flag = 1;
175 
176  if (ctx->num_ticks_poc_diff_one > 0) {
177  vps->vps_num_ticks_poc_diff_one_minus1 =
178  ctx->num_ticks_poc_diff_one - 1;
179  vps->vps_poc_proportional_to_timing_flag = 1;
180  } else if (ctx->num_ticks_poc_diff_one == 0) {
181  vps->vps_poc_proportional_to_timing_flag = 0;
182  }
183  }
184 
185  h265_metadata_update_level(bsf, &vps->profile_tier_level.general_level_idc);
186 
187  return 0;
188 }
189 
191  H265RawSPS *sps)
192 {
194  int need_vui = 0;
195  int crop_unit_x, crop_unit_y;
196 
197  if (ctx->sample_aspect_ratio.num && ctx->sample_aspect_ratio.den) {
198  int num, den, i;
199 
200  av_reduce(&num, &den, ctx->sample_aspect_ratio.num,
201  ctx->sample_aspect_ratio.den, 65535);
202 
203  for (i = 1; i < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect); i++) {
204  if (num == ff_h2645_pixel_aspect[i].num &&
205  den == ff_h2645_pixel_aspect[i].den)
206  break;
207  }
209  sps->vui.aspect_ratio_idc = 255;
210  sps->vui.sar_width = num;
211  sps->vui.sar_height = den;
212  } else {
213  sps->vui.aspect_ratio_idc = i;
214  }
215  sps->vui.aspect_ratio_info_present_flag = 1;
216  need_vui = 1;
217  }
218 
219 #define SET_OR_INFER(field, value, present_flag, infer) do { \
220  if (value >= 0) { \
221  field = value; \
222  need_vui = 1; \
223  } else if (!present_flag) \
224  field = infer; \
225  } while (0)
226 
227  if (ctx->video_format >= 0 ||
228  ctx->video_full_range_flag >= 0 ||
229  ctx->colour_primaries >= 0 ||
230  ctx->transfer_characteristics >= 0 ||
231  ctx->matrix_coefficients >= 0) {
232 
233  SET_OR_INFER(sps->vui.video_format, ctx->video_format,
234  sps->vui.video_signal_type_present_flag, 5);
235 
236  SET_OR_INFER(sps->vui.video_full_range_flag,
237  ctx->video_full_range_flag,
238  sps->vui.video_signal_type_present_flag, 0);
239 
240  if (ctx->colour_primaries >= 0 ||
241  ctx->transfer_characteristics >= 0 ||
242  ctx->matrix_coefficients >= 0) {
243 
244  SET_OR_INFER(sps->vui.colour_primaries,
245  ctx->colour_primaries,
246  sps->vui.colour_description_present_flag, 2);
247 
248  SET_OR_INFER(sps->vui.transfer_characteristics,
249  ctx->transfer_characteristics,
250  sps->vui.colour_description_present_flag, 2);
251 
252  SET_OR_INFER(sps->vui.matrix_coefficients,
253  ctx->matrix_coefficients,
254  sps->vui.colour_description_present_flag, 2);
255 
256  sps->vui.colour_description_present_flag = 1;
257  }
258  sps->vui.video_signal_type_present_flag = 1;
259  need_vui = 1;
260  }
261 
262  if (ctx->chroma_sample_loc_type >= 0) {
263  sps->vui.chroma_sample_loc_type_top_field =
264  ctx->chroma_sample_loc_type;
265  sps->vui.chroma_sample_loc_type_bottom_field =
266  ctx->chroma_sample_loc_type;
267  sps->vui.chroma_loc_info_present_flag = 1;
268  need_vui = 1;
269  }
270 
271  if (ctx->tick_rate.num && ctx->tick_rate.den) {
272  int num, den;
273 
274  av_reduce(&num, &den, ctx->tick_rate.num, ctx->tick_rate.den,
275  UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
276 
277  sps->vui.vui_time_scale = num;
278  sps->vui.vui_num_units_in_tick = den;
279 
280  sps->vui.vui_timing_info_present_flag = 1;
281  need_vui = 1;
282 
283  if (ctx->num_ticks_poc_diff_one > 0) {
284  sps->vui.vui_num_ticks_poc_diff_one_minus1 =
285  ctx->num_ticks_poc_diff_one - 1;
286  sps->vui.vui_poc_proportional_to_timing_flag = 1;
287  } else if (ctx->num_ticks_poc_diff_one == 0) {
288  sps->vui.vui_poc_proportional_to_timing_flag = 0;
289  }
290  }
291 
292  if (sps->separate_colour_plane_flag || sps->chroma_format_idc == 0) {
293  crop_unit_x = 1;
294  crop_unit_y = 1;
295  } else {
296  crop_unit_x = 1 + (sps->chroma_format_idc < 3);
297  crop_unit_y = 1 + (sps->chroma_format_idc < 2);
298  }
299 #define CROP(border, unit) do { \
300  if (ctx->crop_ ## border >= 0) { \
301  if (ctx->crop_ ## border % unit != 0) { \
302  av_log(bsf, AV_LOG_ERROR, "Invalid value for crop_%s: " \
303  "must be a multiple of %d.\n", #border, unit); \
304  return AVERROR(EINVAL); \
305  } \
306  sps->conf_win_ ## border ## _offset = \
307  ctx->crop_ ## border / unit; \
308  sps->conformance_window_flag = 1; \
309  } \
310  } while (0)
311  CROP(left, crop_unit_x);
312  CROP(right, crop_unit_x);
313  CROP(top, crop_unit_y);
314  CROP(bottom, crop_unit_y);
315 #undef CROP
316 
317  if (need_vui)
318  sps->vui_parameters_present_flag = 1;
319 
320  h265_metadata_update_level(bsf, &sps->profile_tier_level.general_level_idc);
321 
322  return 0;
323 }
324 
327 {
329  int err, i;
330 
331  // If an AUD is present, it must be the first NAL unit.
332  if (au->nb_units && au->units[0].type == HEVC_NAL_AUD) {
333  if (ctx->aud == BSF_ELEMENT_REMOVE)
334  ff_cbs_delete_unit(au, 0);
335  } else {
336  if (pkt && ctx->aud == BSF_ELEMENT_INSERT) {
337  H265RawAUD *aud = &ctx->aud_nal;
338  int pic_type = 0, temporal_id = 8, layer_id = 0;
339 
340  for (i = 0; i < au->nb_units; i++) {
341  const H265RawNALUnitHeader *nal = au->units[i].content;
342  if (!nal)
343  continue;
344  if (nal->nuh_temporal_id_plus1 < temporal_id + 1)
345  temporal_id = nal->nuh_temporal_id_plus1 - 1;
346 
347  if (au->units[i].type <= HEVC_NAL_RSV_VCL31) {
348  const H265RawSlice *slice = au->units[i].content;
349  layer_id = nal->nuh_layer_id;
350  if (slice->header.slice_type == HEVC_SLICE_B &&
351  pic_type < 2)
352  pic_type = 2;
353  if (slice->header.slice_type == HEVC_SLICE_P &&
354  pic_type < 1)
355  pic_type = 1;
356  }
357  }
358 
359  aud->nal_unit_header = (H265RawNALUnitHeader) {
360  .nal_unit_type = HEVC_NAL_AUD,
361  .nuh_layer_id = layer_id,
362  .nuh_temporal_id_plus1 = temporal_id + 1,
363  };
364  aud->pic_type = pic_type;
365 
367  if (err < 0) {
368  av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n");
369  return err;
370  }
371  }
372  }
373 
374  if (ctx->level == LEVEL_AUTO && !ctx->level_guess)
375  h265_metadata_guess_level(bsf, au);
376 
377  for (i = 0; i < au->nb_units; i++) {
378  if (au->units[i].type == HEVC_NAL_VPS) {
379  err = h265_metadata_update_vps(bsf, au->units[i].content);
380  if (err < 0)
381  return err;
382  }
383  if (au->units[i].type == HEVC_NAL_SPS) {
384  err = h265_metadata_update_sps(bsf, au->units[i].content);
385  if (err < 0)
386  return err;
387  }
388  }
389 
390  return 0;
391 }
392 
395  .fragment_name = "access unit",
396  .unit_name = "NAL unit",
397  .update_fragment = &h265_metadata_update_fragment,
398 };
399 
401 {
403 }
404 
405 #define OFFSET(x) offsetof(H265MetadataContext, x)
406 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
407 static const AVOption h265_metadata_options[] = {
408  BSF_ELEMENT_OPTIONS_PIR("aud", "Access Unit Delimiter NAL units",
409  aud, FLAGS),
410 
411  { "sample_aspect_ratio", "Set sample aspect ratio (table E-1)",
412  OFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL,
413  { .dbl = 0.0 }, 0, 65535, FLAGS },
414 
415  { "video_format", "Set video format (table E-2)",
416  OFFSET(video_format), AV_OPT_TYPE_INT,
417  { .i64 = -1 }, -1, 7, FLAGS },
418  { "video_full_range_flag", "Set video full range flag",
419  OFFSET(video_full_range_flag), AV_OPT_TYPE_INT,
420  { .i64 = -1 }, -1, 1, FLAGS },
421  { "colour_primaries", "Set colour primaries (table E-3)",
422  OFFSET(colour_primaries), AV_OPT_TYPE_INT,
423  { .i64 = -1 }, -1, 255, FLAGS },
424  { "transfer_characteristics", "Set transfer characteristics (table E-4)",
426  { .i64 = -1 }, -1, 255, FLAGS },
427  { "matrix_coefficients", "Set matrix coefficients (table E-5)",
428  OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
429  { .i64 = -1 }, -1, 255, FLAGS },
430 
431  { "chroma_sample_loc_type", "Set chroma sample location type (figure E-1)",
432  OFFSET(chroma_sample_loc_type), AV_OPT_TYPE_INT,
433  { .i64 = -1 }, -1, 5, FLAGS },
434 
435  { "tick_rate",
436  "Set VPS and VUI tick rate (time_scale / num_units_in_tick)",
437  OFFSET(tick_rate), AV_OPT_TYPE_RATIONAL,
438  { .dbl = 0.0 }, 0, UINT_MAX, FLAGS },
439  { "num_ticks_poc_diff_one",
440  "Set VPS and VUI number of ticks per POC increment",
441  OFFSET(num_ticks_poc_diff_one), AV_OPT_TYPE_INT,
442  { .i64 = -1 }, -1, INT_MAX, FLAGS },
443 
444  { "crop_left", "Set left border crop offset",
445  OFFSET(crop_left), AV_OPT_TYPE_INT,
446  { .i64 = -1 }, -1, HEVC_MAX_WIDTH, FLAGS },
447  { "crop_right", "Set right border crop offset",
448  OFFSET(crop_right), AV_OPT_TYPE_INT,
449  { .i64 = -1 }, -1, HEVC_MAX_WIDTH, FLAGS },
450  { "crop_top", "Set top border crop offset",
451  OFFSET(crop_top), AV_OPT_TYPE_INT,
452  { .i64 = -1 }, -1, HEVC_MAX_HEIGHT, FLAGS },
453  { "crop_bottom", "Set bottom border crop offset",
454  OFFSET(crop_bottom), AV_OPT_TYPE_INT,
455  { .i64 = -1 }, -1, HEVC_MAX_HEIGHT, FLAGS },
456 
457  { "level", "Set level (tables A.6 and A.7)",
459  { .i64 = LEVEL_UNSET }, LEVEL_UNSET, 0xff, FLAGS, .unit = "level" },
460  { "auto", "Attempt to guess level from stream properties",
462  { .i64 = LEVEL_AUTO }, .flags = FLAGS, .unit = "level" },
463 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
464  { .i64 = value }, .flags = FLAGS, .unit = "level"
465  { LEVEL("1", 30) },
466  { LEVEL("2", 60) },
467  { LEVEL("2.1", 63) },
468  { LEVEL("3", 90) },
469  { LEVEL("3.1", 93) },
470  { LEVEL("4", 120) },
471  { LEVEL("4.1", 123) },
472  { LEVEL("5", 150) },
473  { LEVEL("5.1", 153) },
474  { LEVEL("5.2", 156) },
475  { LEVEL("6", 180) },
476  { LEVEL("6.1", 183) },
477  { LEVEL("6.2", 186) },
478  { LEVEL("8.5", 255) },
479 #undef LEVEL
480 
481  { NULL }
482 };
483 
484 static const AVClass h265_metadata_class = {
485  .class_name = "h265_metadata_bsf",
486  .item_name = av_default_item_name,
487  .option = h265_metadata_options,
488  .version = LIBAVUTIL_VERSION_INT,
489 };
490 
491 static const enum AVCodecID h265_metadata_codec_ids[] = {
493 };
494 
496  .p.name = "hevc_metadata",
497  .p.codec_ids = h265_metadata_codec_ids,
498  .p.priv_class = &h265_metadata_class,
499  .priv_data_size = sizeof(H265MetadataContext),
501  .close = &ff_cbs_bsf_generic_close,
503 };
H265MetadataContext::crop_bottom
int crop_bottom
Definition: h265_metadata.c:60
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
level
uint8_t level
Definition: svq3.c:204
ff_cbs_bsf_generic_init
int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
Definition: cbs_bsf.c:110
bsf_internal.h
opt.h
H265MetadataContext::chroma_sample_loc_type
int chroma_sample_loc_type
Definition: h265_metadata.c:51
H265RawSubLayerHRDParameters::bit_rate_value_minus1
uint32_t bit_rate_value_minus1[HEVC_MAX_CPB_CNT]
Definition: cbs_h265.h:93
CBSBSFType::codec_id
enum AVCodecID codec_id
Definition: cbs_bsf.h:32
H265MetadataContext::transfer_characteristics
int transfer_characteristics
Definition: h265_metadata.c:48
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:107
AVBitStreamFilter::name
const char * name
Definition: bsf.h:112
ff_cbs_insert_unit_content
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, void *content_ref)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:782
int64_t
long long int64_t
Definition: coverity.c:34
H265RawSlice::header
H265RawSliceHeader header
Definition: cbs_h265.h:534
LEVEL
#define LEVEL(name, value)
h265_metadata_options
static const AVOption h265_metadata_options[]
Definition: h265_metadata.c:407
level_idc
int level_idc
Definition: h264_levels.c:29
AVOption
AVOption.
Definition: opt.h:346
H265RawNALUnitHeader::nuh_temporal_id_plus1
uint8_t nuh_temporal_id_plus1
Definition: cbs_h265.h:32
CBSBSFContext
Definition: cbs_bsf.h:53
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:74
cbs.h
cbs_h265.h
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
H265MetadataContext::matrix_coefficients
int matrix_coefficients
Definition: h265_metadata.c:49
AV_OPT_TYPE_RATIONAL
@ AV_OPT_TYPE_RATIONAL
Definition: opt.h:240
H265MetadataContext::aud_nal
H265RawAUD aud_nal
Definition: h265_metadata.c:39
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:70
H265LevelDescriptor
Definition: h265_profile_level.h:27
H265RawSPS
Definition: cbs_h265.h:244
H265RawVPS
Definition: cbs_h265.h:183
H265RawPPS
Definition: cbs_h265.h:346
BSF_ELEMENT_REMOVE
@ BSF_ELEMENT_REMOVE
Definition: cbs_bsf.h:106
bsf.h
cbs_bsf.h
H265RawHRDParameters::vcl_hrd_parameters_present_flag
uint8_t vcl_hrd_parameters_present_flag
Definition: cbs_h265.h:102
LEVEL_UNSET
@ LEVEL_UNSET
Definition: h265_metadata.c:32
H265MetadataContext::level
int level
Definition: h265_metadata.c:62
H265MetadataContext::crop_left
int crop_left
Definition: h265_metadata.c:57
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
h265_metadata_guess_level
static void h265_metadata_guess_level(AVBSFContext *bsf, const CodedBitstreamFragment *au)
Definition: h265_metadata.c:68
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:168
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
ptl
const H265RawProfileTierLevel * ptl
Definition: h265_levels.c:170
ff_h265_guess_level
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.
Definition: h265_profile_level.c:162
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
width
#define width
HEVC_NAL_RSV_VCL31
@ HEVC_NAL_RSV_VCL31
Definition: hevc.h:60
H265MetadataContext::video_full_range_flag
int video_full_range_flag
Definition: h265_metadata.c:46
tile_rows
int tile_rows
Definition: h265_levels.c:217
H265RawHRDParameters::bit_rate_scale
uint8_t bit_rate_scale
Definition: cbs_h265.h:110
tile_cols
int tile_cols
Definition: av1_levels.c:73
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
h265_metadata_update_fragment
static int h265_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, CodedBitstreamFragment *au)
Definition: h265_metadata.c:325
h2645data.h
H265MetadataContext::common
CBSBSFContext common
Definition: h265_metadata.c:37
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
HEVC_SLICE_B
@ HEVC_SLICE_B
Definition: hevc.h:96
NULL
#define NULL
Definition: coverity.c:32
H265RawAUD
Definition: cbs_h265.h:437
FFBitStreamFilter
Definition: bsf_internal.h:27
HEVC_NAL_PPS
@ HEVC_NAL_PPS
Definition: hevc.h:63
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
h265_metadata_update_vps
static int h265_metadata_update_vps(AVBSFContext *bsf, H265RawVPS *vps)
Definition: h265_metadata.c:160
H265MetadataContext::level_warned
int level_warned
Definition: h265_metadata.c:64
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
HEVC_MAX_HEIGHT
@ HEVC_MAX_HEIGHT
Definition: hevc.h:139
H265RawSliceHeader::slice_type
uint8_t slice_type
Definition: cbs_h265.h:454
H265RawNALUnitHeader
Definition: cbs_h265.h:29
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
H265MetadataContext::level_guess
int level_guess
Definition: h265_metadata.c:63
OFFSET
#define OFFSET(x)
Definition: h265_metadata.c:405
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition: bsf_internal.h:31
aud
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
Definition: cbs_h264_syntax_template.c:841
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
CBSBSFType
Definition: cbs_bsf.h:31
ff_cbs_bsf_generic_close
void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
Definition: cbs_bsf.c:155
transfer_characteristics
static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
Definition: vf_colorspace.c:165
h265_profile_level.h
H265RawHRDParameters
Definition: cbs_h265.h:100
height
#define height
H265MetadataContext
Definition: h265_metadata.c:36
H265MetadataContext::tick_rate
AVRational tick_rate
Definition: h265_metadata.c:53
H265RawNALUnitHeader::nuh_layer_id
uint8_t nuh_layer_id
Definition: cbs_h265.h:31
H265MetadataContext::poc_proportional_to_timing_flag
int poc_proportional_to_timing_flag
Definition: h265_metadata.c:54
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
SET_OR_INFER
#define SET_OR_INFER(field, value, present_flag, infer)
FLAGS
#define FLAGS
Definition: h265_metadata.c:406
common.h
H265MetadataContext::video_format
int video_format
Definition: h265_metadata.c:45
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
HEVC_SLICE_P
@ HEVC_SLICE_P
Definition: hevc.h:97
h265_metadata_codec_ids
static enum AVCodecID h265_metadata_codec_ids[]
Definition: h265_metadata.c:491
ff_h2645_pixel_aspect
const AVRational ff_h2645_pixel_aspect[]
Definition: h2645data.c:21
H265RawProfileTierLevel
Definition: cbs_h265.h:35
H265RawHRDParameters::nal_hrd_parameters_present_flag
uint8_t nal_hrd_parameters_present_flag
Definition: cbs_h265.h:101
HEVC_NAL_VPS
@ HEVC_NAL_VPS
Definition: hevc.h:61
AVBSFContext::priv_data
void * priv_data
Opaque filter-specific private data.
Definition: bsf.h:83
ff_cbs_bsf_generic_filter
int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt)
Filter operation for CBS BSF.
Definition: cbs_bsf.c:61
H265MetadataContext::colour_primaries
int colour_primaries
Definition: h265_metadata.c:47
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
h265_metadata_type
static const CBSBSFType h265_metadata_type
Definition: h265_metadata.c:393
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
h265_metadata_update_level
static void h265_metadata_update_level(AVBSFContext *bsf, uint8_t *level_idc)
Definition: h265_metadata.c:137
BSF_ELEMENT_OPTIONS_PIR
#define BSF_ELEMENT_OPTIONS_PIR(name, help, field, opt_flags)
Definition: cbs_bsf.h:112
h265_metadata_init
static int h265_metadata_init(AVBSFContext *bsf)
Definition: h265_metadata.c:400
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
h265_metadata_update_sps
static int h265_metadata_update_sps(AVBSFContext *bsf, H265RawSPS *sps)
Definition: h265_metadata.c:190
HEVC_NAL_AUD
@ HEVC_NAL_AUD
Definition: hevc.h:64
CROP
#define CROP(border, unit)
H265MetadataContext::crop_top
int crop_top
Definition: h265_metadata.c:59
H265RawHRDParameters::vcl_sub_layer_hrd_parameters
H265RawSubLayerHRDParameters vcl_sub_layer_hrd_parameters[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:124
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
H265MetadataContext::crop_right
int crop_right
Definition: h265_metadata.c:58
desc
const char * desc
Definition: libsvtav1.c:75
HEVC_NAL_SPS
@ HEVC_NAL_SPS
Definition: hevc.h:62
h265_metadata_class
static const AVClass h265_metadata_class
Definition: h265_metadata.c:484
ff_hevc_metadata_bsf
const FFBitStreamFilter ff_hevc_metadata_bsf
Definition: h265_metadata.c:495
LEVEL_AUTO
@ LEVEL_AUTO
Definition: h265_metadata.c:33
AVPacket
This structure stores compressed data.
Definition: packet.h:499
H265RawHRDParameters::nal_sub_layer_hrd_parameters
H265RawSubLayerHRDParameters nal_sub_layer_hrd_parameters[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:123
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
H265MetadataContext::num_ticks_poc_diff_one
int num_ticks_poc_diff_one
Definition: h265_metadata.c:55
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
H265MetadataContext::sample_aspect_ratio
AVRational sample_aspect_ratio
Definition: h265_metadata.c:43
HEVC_MAX_WIDTH
@ HEVC_MAX_WIDTH
Definition: hevc.h:138
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:153
ff_cbs_delete_unit
void ff_cbs_delete_unit(CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
Definition: cbs.c:859
H265RawSlice
Definition: cbs_h265.h:533
H265MetadataContext::aud
int aud
Definition: h265_metadata.c:41
BSF_ELEMENT_INSERT
@ BSF_ELEMENT_INSERT
Definition: cbs_bsf.h:104