FFmpeg
h265_metadata_bsf.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 "cbs.h"
24 #include "cbs_h265.h"
25 #include "hevc.h"
26 #include "h265_profile_level.h"
27 
28 enum {
32 };
33 
34 enum {
36  LEVEL_AUTO = -1,
37 };
38 
39 typedef struct H265MetadataContext {
40  const AVClass *class;
41 
44 
46 
47  int aud;
48 
50 
56 
58 
62 
63  int crop_left;
65  int crop_top;
67 
68  int level;
72 
73 
75  const CodedBitstreamFragment *au)
76 {
80  const H265RawHRDParameters *hrd = NULL;
81  int64_t bit_rate = 0;
82  int width = 0, height = 0;
83  int tile_cols = 0, tile_rows = 0;
84  int max_dec_pic_buffering = 0;
85  int i;
86 
87  for (i = 0; i < au->nb_units; i++) {
88  const CodedBitstreamUnit *unit = &au->units[i];
89 
90  if (unit->type == HEVC_NAL_VPS) {
91  const H265RawVPS *vps = unit->content;
92 
93  ptl = &vps->profile_tier_level;
94  max_dec_pic_buffering = vps->vps_max_dec_pic_buffering_minus1[0] + 1;
95 
96  if (vps->vps_num_hrd_parameters > 0)
97  hrd = &vps->hrd_parameters[0];
98 
99  } else if (unit->type == HEVC_NAL_SPS) {
100  const H265RawSPS *sps = unit->content;
101 
102  ptl = &sps->profile_tier_level;
103  max_dec_pic_buffering = sps->sps_max_dec_pic_buffering_minus1[0] + 1;
104 
105  width = sps->pic_width_in_luma_samples;
107 
109  hrd = &sps->vui.hrd_parameters;
110 
111  } else if (unit->type == HEVC_NAL_PPS) {
112  const H265RawPPS *pps = unit->content;
113 
114  if (pps->tiles_enabled_flag) {
115  tile_cols = pps->num_tile_columns_minus1 + 1;
116  tile_rows = pps->num_tile_rows_minus1 + 1;
117  }
118  }
119  }
120 
121  if (hrd) {
123  bit_rate = (hrd->nal_sub_layer_hrd_parameters[0].bit_rate_value_minus1[0] + 1) *
124  (INT64_C(1) << hrd->bit_rate_scale + 6);
125  } else if (hrd->vcl_hrd_parameters_present_flag) {
126  bit_rate = (hrd->vcl_sub_layer_hrd_parameters[0].bit_rate_value_minus1[0] + 1) *
127  (INT64_C(1) << hrd->bit_rate_scale + 6);
128  // Adjust for VCL vs. NAL limits.
129  bit_rate = bit_rate * 11 / 10;
130  }
131  }
132 
133  desc = ff_h265_guess_level(ptl, bit_rate, width, height,
134  0, tile_cols, tile_rows,
135  max_dec_pic_buffering);
136  if (desc) {
137  av_log(bsf, AV_LOG_DEBUG, "Stream appears to conform to "
138  "level %s.\n", desc->name);
139  ctx->level_guess = desc->level_idc;
140  }
141 }
142 
145 {
147 
148  if (ctx->level != LEVEL_UNSET) {
149  if (ctx->level == LEVEL_AUTO) {
150  if (ctx->level_guess) {
151  *level_idc = ctx->level_guess;
152  } else {
153  if (!ctx->level_warned) {
154  av_log(bsf, AV_LOG_WARNING, "Unable to determine level "
155  "of stream: using level 8.5.\n");
156  ctx->level_warned = 1;
157  }
158  *level_idc = 255;
159  }
160  } else {
161  *level_idc = ctx->level;
162  }
163  }
164 }
165 
167  H265RawVPS *vps)
168 {
170 
171  if (ctx->tick_rate.num && ctx->tick_rate.den) {
172  int num, den;
173 
174  av_reduce(&num, &den, ctx->tick_rate.num, ctx->tick_rate.den,
175  UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
176 
177  vps->vps_time_scale = num;
178  vps->vps_num_units_in_tick = den;
179 
181 
182  if (ctx->num_ticks_poc_diff_one > 0) {
184  ctx->num_ticks_poc_diff_one - 1;
186  } else if (ctx->num_ticks_poc_diff_one == 0) {
188  }
189  }
190 
192 
193  return 0;
194 }
195 
197  H265RawSPS *sps)
198 {
200  int need_vui = 0;
201  int crop_unit_x, crop_unit_y;
202 
203  if (ctx->sample_aspect_ratio.num && ctx->sample_aspect_ratio.den) {
204  // Table E-1.
205  static const AVRational sar_idc[] = {
206  { 0, 0 }, // Unspecified (never written here).
207  { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
208  { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
209  { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
210  { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
211  };
212  int num, den, i;
213 
214  av_reduce(&num, &den, ctx->sample_aspect_ratio.num,
215  ctx->sample_aspect_ratio.den, 65535);
216 
217  for (i = 1; i < FF_ARRAY_ELEMS(sar_idc); i++) {
218  if (num == sar_idc[i].num &&
219  den == sar_idc[i].den)
220  break;
221  }
222  if (i == FF_ARRAY_ELEMS(sar_idc)) {
223  sps->vui.aspect_ratio_idc = 255;
224  sps->vui.sar_width = num;
225  sps->vui.sar_height = den;
226  } else {
227  sps->vui.aspect_ratio_idc = i;
228  }
230  need_vui = 1;
231  }
232 
233 #define SET_OR_INFER(field, value, present_flag, infer) do { \
234  if (value >= 0) { \
235  field = value; \
236  need_vui = 1; \
237  } else if (!present_flag) \
238  field = infer; \
239  } while (0)
240 
241  if (ctx->video_format >= 0 ||
242  ctx->video_full_range_flag >= 0 ||
243  ctx->colour_primaries >= 0 ||
244  ctx->transfer_characteristics >= 0 ||
245  ctx->matrix_coefficients >= 0) {
246 
249 
253 
254  if (ctx->colour_primaries >= 0 ||
255  ctx->transfer_characteristics >= 0 ||
256  ctx->matrix_coefficients >= 0) {
257 
259  ctx->colour_primaries,
261 
265 
267  ctx->matrix_coefficients,
269 
271  }
273  need_vui = 1;
274  }
275 
276  if (ctx->chroma_sample_loc_type >= 0) {
282  need_vui = 1;
283  }
284 
285  if (ctx->tick_rate.num && ctx->tick_rate.den) {
286  int num, den;
287 
288  av_reduce(&num, &den, ctx->tick_rate.num, ctx->tick_rate.den,
289  UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
290 
291  sps->vui.vui_time_scale = num;
292  sps->vui.vui_num_units_in_tick = den;
293 
295  need_vui = 1;
296 
297  if (ctx->num_ticks_poc_diff_one > 0) {
299  ctx->num_ticks_poc_diff_one - 1;
301  } else if (ctx->num_ticks_poc_diff_one == 0) {
303  }
304  }
305 
306  if (sps->separate_colour_plane_flag || sps->chroma_format_idc == 0) {
307  crop_unit_x = 1;
308  crop_unit_y = 1;
309  } else {
310  crop_unit_x = 1 + (sps->chroma_format_idc < 3);
311  crop_unit_y = 1 + (sps->chroma_format_idc < 2);
312  }
313 #define CROP(border, unit) do { \
314  if (ctx->crop_ ## border >= 0) { \
315  if (ctx->crop_ ## border % unit != 0) { \
316  av_log(bsf, AV_LOG_ERROR, "Invalid value for crop_%s: " \
317  "must be a multiple of %d.\n", #border, unit); \
318  return AVERROR(EINVAL); \
319  } \
320  sps->conf_win_ ## border ## _offset = \
321  ctx->crop_ ## border / unit; \
322  sps->conformance_window_flag = 1; \
323  } \
324  } while (0)
325  CROP(left, crop_unit_x);
326  CROP(right, crop_unit_x);
327  CROP(top, crop_unit_y);
328  CROP(bottom, crop_unit_y);
329 #undef CROP
330 
331  if (need_vui)
333 
335 
336  return 0;
337 }
338 
340 {
343  int err, i;
344 
345  err = ff_bsf_get_packet_ref(bsf, pkt);
346  if (err < 0)
347  return err;
348 
349  err = ff_cbs_read_packet(ctx->cbc, au, pkt);
350  if (err < 0) {
351  av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
352  goto fail;
353  }
354 
355  if (au->nb_units == 0) {
356  av_log(bsf, AV_LOG_ERROR, "No NAL units in packet.\n");
357  err = AVERROR_INVALIDDATA;
358  goto fail;
359  }
360 
361  // If an AUD is present, it must be the first NAL unit.
362  if (au->units[0].type == HEVC_NAL_AUD) {
363  if (ctx->aud == REMOVE)
364  ff_cbs_delete_unit(ctx->cbc, au, 0);
365  } else {
366  if (ctx->aud == INSERT) {
367  H265RawAUD *aud = &ctx->aud_nal;
368  int pic_type = 0, temporal_id = 8, layer_id = 0;
369 
370  for (i = 0; i < au->nb_units; i++) {
371  const H265RawNALUnitHeader *nal = au->units[i].content;
372  if (!nal)
373  continue;
374  if (nal->nuh_temporal_id_plus1 < temporal_id + 1)
375  temporal_id = nal->nuh_temporal_id_plus1 - 1;
376 
377  if (au->units[i].type <= HEVC_NAL_RSV_VCL31) {
378  const H265RawSlice *slice = au->units[i].content;
379  layer_id = nal->nuh_layer_id;
380  if (slice->header.slice_type == HEVC_SLICE_B &&
381  pic_type < 2)
382  pic_type = 2;
383  if (slice->header.slice_type == HEVC_SLICE_P &&
384  pic_type < 1)
385  pic_type = 1;
386  }
387  }
388 
391  .nuh_layer_id = layer_id,
392  .nuh_temporal_id_plus1 = temporal_id + 1,
393  };
394  aud->pic_type = pic_type;
395 
396  err = ff_cbs_insert_unit_content(ctx->cbc, au,
397  0, HEVC_NAL_AUD, aud, NULL);
398  if (err < 0) {
399  av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n");
400  goto fail;
401  }
402  }
403  }
404 
405  if (ctx->level == LEVEL_AUTO && !ctx->level_guess)
406  h265_metadata_guess_level(bsf, au);
407 
408  for (i = 0; i < au->nb_units; i++) {
409  if (au->units[i].type == HEVC_NAL_VPS) {
410  err = h265_metadata_update_vps(bsf, au->units[i].content);
411  if (err < 0)
412  goto fail;
413  }
414  if (au->units[i].type == HEVC_NAL_SPS) {
415  err = h265_metadata_update_sps(bsf, au->units[i].content);
416  if (err < 0)
417  goto fail;
418  }
419  }
420 
421  err = ff_cbs_write_packet(ctx->cbc, pkt, au);
422  if (err < 0) {
423  av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
424  goto fail;
425  }
426 
427  err = 0;
428 fail:
429  ff_cbs_fragment_reset(ctx->cbc, au);
430 
431  if (err < 0)
432  av_packet_unref(pkt);
433 
434  return err;
435 }
436 
438 {
441  int err, i;
442 
443  err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_HEVC, bsf);
444  if (err < 0)
445  return err;
446 
447  if (bsf->par_in->extradata) {
448  err = ff_cbs_read_extradata(ctx->cbc, au, bsf->par_in);
449  if (err < 0) {
450  av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
451  goto fail;
452  }
453 
454  if (ctx->level == LEVEL_AUTO)
455  h265_metadata_guess_level(bsf, au);
456 
457  for (i = 0; i < au->nb_units; i++) {
458  if (au->units[i].type == HEVC_NAL_VPS) {
459  err = h265_metadata_update_vps(bsf, au->units[i].content);
460  if (err < 0)
461  goto fail;
462  }
463  if (au->units[i].type == HEVC_NAL_SPS) {
464  err = h265_metadata_update_sps(bsf, au->units[i].content);
465  if (err < 0)
466  goto fail;
467  }
468  }
469 
470  err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, au);
471  if (err < 0) {
472  av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
473  goto fail;
474  }
475  }
476 
477  err = 0;
478 fail:
479  ff_cbs_fragment_reset(ctx->cbc, au);
480  return err;
481 }
482 
484 {
486 
487  ff_cbs_fragment_free(ctx->cbc, &ctx->access_unit);
488  ff_cbs_close(&ctx->cbc);
489 }
490 
491 #define OFFSET(x) offsetof(H265MetadataContext, x)
492 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
493 static const AVOption h265_metadata_options[] = {
494  { "aud", "Access Unit Delimiter NAL units",
496  { .i64 = PASS }, PASS, REMOVE, FLAGS, "aud" },
497  { "pass", NULL, 0, AV_OPT_TYPE_CONST,
498  { .i64 = PASS }, .flags = FLAGS, .unit = "aud" },
499  { "insert", NULL, 0, AV_OPT_TYPE_CONST,
500  { .i64 = INSERT }, .flags = FLAGS, .unit = "aud" },
501  { "remove", NULL, 0, AV_OPT_TYPE_CONST,
502  { .i64 = REMOVE }, .flags = FLAGS, .unit = "aud" },
503 
504  { "sample_aspect_ratio", "Set sample aspect ratio (table E-1)",
506  { .dbl = 0.0 }, 0, 65535, FLAGS },
507 
508  { "video_format", "Set video format (table E-2)",
510  { .i64 = -1 }, -1, 7, FLAGS },
511  { "video_full_range_flag", "Set video full range flag",
513  { .i64 = -1 }, -1, 1, FLAGS },
514  { "colour_primaries", "Set colour primaries (table E-3)",
516  { .i64 = -1 }, -1, 255, FLAGS },
517  { "transfer_characteristics", "Set transfer characteristics (table E-4)",
519  { .i64 = -1 }, -1, 255, FLAGS },
520  { "matrix_coefficients", "Set matrix coefficients (table E-5)",
522  { .i64 = -1 }, -1, 255, FLAGS },
523 
524  { "chroma_sample_loc_type", "Set chroma sample location type (figure E-1)",
526  { .i64 = -1 }, -1, 6, FLAGS },
527 
528  { "tick_rate",
529  "Set VPS and VUI tick rate (num_units_in_tick / time_scale)",
531  { .dbl = 0.0 }, 0, UINT_MAX, FLAGS },
532  { "num_ticks_poc_diff_one",
533  "Set VPS and VUI number of ticks per POC increment",
535  { .i64 = -1 }, -1, INT_MAX, FLAGS },
536 
537  { "crop_left", "Set left border crop offset",
539  { .i64 = -1 }, -1, HEVC_MAX_WIDTH, FLAGS },
540  { "crop_right", "Set right border crop offset",
542  { .i64 = -1 }, -1, HEVC_MAX_WIDTH, FLAGS },
543  { "crop_top", "Set top border crop offset",
545  { .i64 = -1 }, -1, HEVC_MAX_HEIGHT, FLAGS },
546  { "crop_bottom", "Set bottom border crop offset",
548  { .i64 = -1 }, -1, HEVC_MAX_HEIGHT, FLAGS },
549 
550  { "level", "Set level (tables A.6 and A.7)",
552  { .i64 = LEVEL_UNSET }, LEVEL_UNSET, 0xff, FLAGS, "level" },
553  { "auto", "Attempt to guess level from stream properties",
555  { .i64 = LEVEL_AUTO }, .flags = FLAGS, .unit = "level" },
556 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
557  { .i64 = value }, .flags = FLAGS, .unit = "level"
558  { LEVEL("1", 30) },
559  { LEVEL("2", 60) },
560  { LEVEL("2.1", 63) },
561  { LEVEL("3", 90) },
562  { LEVEL("3.1", 93) },
563  { LEVEL("4", 120) },
564  { LEVEL("4.1", 123) },
565  { LEVEL("5", 150) },
566  { LEVEL("5.1", 153) },
567  { LEVEL("5.2", 156) },
568  { LEVEL("6", 180) },
569  { LEVEL("6.1", 183) },
570  { LEVEL("6.2", 186) },
571  { LEVEL("8.5", 255) },
572 #undef LEVEL
573 
574  { NULL }
575 };
576 
577 static const AVClass h265_metadata_class = {
578  .class_name = "h265_metadata_bsf",
579  .item_name = av_default_item_name,
580  .option = h265_metadata_options,
581  .version = LIBAVUTIL_VERSION_INT,
582 };
583 
584 static const enum AVCodecID h265_metadata_codec_ids[] = {
586 };
587 
589  .name = "hevc_metadata",
590  .priv_data_size = sizeof(H265MetadataContext),
591  .priv_class = &h265_metadata_class,
593  .close = &h265_metadata_close,
596 };
uint32_t bit_rate_value_minus1[HEVC_MAX_CPB_CNT]
Definition: cbs_h265.h:101
#define NULL
Definition: coverity.c:32
static enum AVCodecID h265_metadata_codec_ids[]
int nb_units
Number of units in this fragment.
Definition: cbs.h:147
uint8_t transfer_characteristics
Definition: cbs_h265.h:149
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AVCodecParameters * par_out
Parameters of the output stream.
Definition: avcodec.h:5808
uint8_t vps_poc_proportional_to_timing_flag
Definition: cbs_h265.h:216
AVOption.
Definition: opt.h:246
static void h265_metadata_update_level(AVBSFContext *bsf, uint8_t *level_idc)
H265RawHRDParameters hrd_parameters
Definition: cbs_h265.h:172
uint8_t nal_hrd_parameters_present_flag
Definition: cbs_h265.h:109
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to a packet.
Definition: cbs.c:401
const char * desc
Definition: nvenc.c:68
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
uint8_t vui_timing_info_present_flag
Definition: cbs_h265.h:166
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:74
void ff_cbs_delete_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
Definition: cbs.c:796
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:68
int num
Numerator.
Definition: rational.h:59
The bitstream filter state.
Definition: avcodec.h:5774
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
uint8_t tiles_enabled_flag
Definition: cbs_h265.h:384
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:722
uint8_t bit_rate_scale
Definition: cbs_h265.h:118
H265RawProfileTierLevel profile_tier_level
Definition: cbs_h265.h:260
static AVPacket pkt
uint8_t vui_parameters_present_flag
Definition: cbs_h265.h:318
void * priv_data
Opaque filter-specific private data.
Definition: avcodec.h:5795
uint32_t vps_num_units_in_tick
Definition: cbs_h265.h:214
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:72
static int h265_metadata_update_sps(AVBSFContext *bsf, H265RawSPS *sps)
int tile_cols
Definition: h265_levels.c:218
uint16_t pic_height_in_luma_samples
Definition: cbs_h265.h:268
#define OFFSET(x)
uint8_t
H265RawSubLayerHRDParameters nal_sub_layer_hrd_parameters[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:131
static const AVOption h265_metadata_options[]
AVOptions.
uint8_t colour_primaries
Definition: cbs_h265.h:148
uint8_t video_format
Definition: cbs_h265.h:145
uint8_t vps_timing_info_present_flag
Definition: cbs_h265.h:213
int level_idc
Definition: h264_levels.c:25
int ff_cbs_read_packet(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
Read the data bitstream from a packet into a fragment, then split into units and decompose.
Definition: cbs.c:242
const H265RawProfileTierLevel * ptl
Definition: h265_levels.c:170
const char * name
Definition: avcodec.h:5824
#define height
uint8_t matrix_coefficients
Definition: cbs_h265.h:150
uint8_t aspect_ratio_info_present_flag
Definition: cbs_h265.h:136
uint8_t nuh_temporal_id_plus1
Definition: cbs_h265.h:40
Coded bitstream unit structure.
Definition: cbs.h:64
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
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:101
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:162
uint8_t video_full_range_flag
Definition: cbs_h265.h:146
#define av_log(a,...)
uint8_t chroma_sample_loc_type_bottom_field
Definition: cbs_h265.h:154
uint8_t video_signal_type_present_flag
Definition: cbs_h265.h:144
H265RawVUI vui
Definition: cbs_h265.h:319
void ff_cbs_fragment_free(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:157
uint32_t vui_num_ticks_poc_diff_one_minus1
Definition: cbs_h265.h:170
uint8_t vps_max_dec_pic_buffering_minus1[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:205
static void h265_metadata_close(AVBSFContext *bsf)
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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
uint8_t nuh_layer_id
Definition: cbs_h265.h:39
uint8_t chroma_loc_info_present_flag
Definition: cbs_h265.h:152
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
uint16_t sar_height
Definition: cbs_h265.h:139
#define fail()
Definition: checkasm.h:122
#define LEVEL(name, value)
uint8_t chroma_sample_loc_type_top_field
Definition: cbs_h265.h:153
uint32_t vui_time_scale
Definition: cbs_h265.h:168
H265RawHRDParameters hrd_parameters[HEVC_MAX_LAYER_SETS]
Definition: cbs_h265.h:221
H265RawNALUnitHeader nal_unit_header
Definition: cbs_h265.h:446
uint8_t slice_type
Definition: cbs_h265.h:462
H265RawProfileTierLevel profile_tier_level
Definition: cbs_h265.h:202
int ff_cbs_write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to the extradata in codec parameters.
Definition: cbs.c:376
uint8_t pic_type
Definition: cbs_h265.h:448
uint16_t sar_width
Definition: cbs_h265.h:138
#define width
uint8_t vui_hrd_parameters_present_flag
Definition: cbs_h265.h:171
AVFormatContext * ctx
Definition: movenc.c:48
uint16_t pic_width_in_luma_samples
Definition: cbs_h265.h:267
static int h265_metadata_init(AVBSFContext *bsf)
uint8_t vcl_hrd_parameters_present_flag
Definition: cbs_h265.h:110
H265RawSubLayerHRDParameters vcl_sub_layer_hrd_parameters[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:132
int tile_rows
Definition: h265_levels.c:217
#define FF_ARRAY_ELEMS(a)
uint16_t vps_num_hrd_parameters
Definition: cbs_h265.h:218
CodedBitstreamContext * cbc
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.
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:116
uint8_t general_level_idc
Definition: cbs_h265.h:68
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:599
uint32_t vui_num_units_in_tick
Definition: cbs_h265.h:167
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:206
CodedBitstreamFragment access_unit
Describe the class of an AVClass context structure.
Definition: log.h:67
void ff_cbs_fragment_reset(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment&#39;s own data buffer, but not the units a...
Definition: cbs.c:142
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Context structure for coded bitstream operations.
Definition: cbs.h:168
Rational number (pair of numerator and denominator).
Definition: rational.h:58
static void h265_metadata_guess_level(AVBSFContext *bsf, const CodedBitstreamFragment *au)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
uint8_t chroma_format_idc
Definition: cbs_h265.h:264
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:115
int ff_cbs_read_extradata(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecParameters *par)
Read the extradata bitstream found in codec parameters into a fragment, then split into units and dec...
Definition: cbs.c:224
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
#define CROP(border, unit)
uint8_t vui_poc_proportional_to_timing_flag
Definition: cbs_h265.h:169
const AVBitStreamFilter ff_hevc_metadata_bsf
static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
common internal and external API header
uint8_t num_tile_rows_minus1
Definition: cbs_h265.h:388
static enum AVCodecID codec_ids[]
uint8_t num_tile_columns_minus1
Definition: cbs_h265.h:387
static const AVClass h265_metadata_class
int den
Denominator.
Definition: rational.h:60
#define SET_OR_INFER(field, value, present_flag, infer)
static int h265_metadata_update_vps(AVBSFContext *bsf, H265RawVPS *vps)
H265RawSliceHeader header
Definition: cbs_h265.h:542
uint32_t vps_time_scale
Definition: cbs_h265.h:215
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3982
uint8_t aspect_ratio_idc
Definition: cbs_h265.h:137
uint8_t sps_max_dec_pic_buffering_minus1[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:282
AVRational sample_aspect_ratio
uint32_t vps_num_ticks_poc_diff_one_minus1
Definition: cbs_h265.h:217
uint8_t separate_colour_plane_flag
Definition: cbs_h265.h:265
uint8_t colour_description_present_flag
Definition: cbs_h265.h:147
#define FLAGS
This structure stores compressed data.
Definition: avcodec.h:1457
AVCodecParameters * par_in
Parameters of the input stream.
Definition: avcodec.h:5802
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition: bsf.c:239
uint8_t nal_unit_type
Definition: cbs_h265.h:38