FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h264_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/avstring.h"
20 #include "libavutil/common.h"
21 #include "libavutil/opt.h"
22 
23 #include "bsf.h"
24 #include "cbs.h"
25 #include "cbs_h264.h"
26 #include "h264.h"
27 #include "h264_sei.h"
28 
29 enum {
33 };
34 
35 typedef struct H264MetadataContext {
36  const AVClass *class;
37 
40 
43 
44  int aud;
45 
47 
53 
55 
58 
59  int crop_left;
61  int crop_top;
63 
64  const char *sei_user_data;
67 
68 
70  H264RawSPS *sps)
71 {
73  int need_vui = 0;
74  int crop_unit_x, crop_unit_y;
75 
77  // Table E-1.
78  static const AVRational sar_idc[] = {
79  { 0, 0 }, // Unspecified (never written here).
80  { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
81  { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
82  { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
83  { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
84  };
85  int num, den, i;
86 
87  av_reduce(&num, &den, ctx->sample_aspect_ratio.num,
88  ctx->sample_aspect_ratio.den, 65535);
89 
90  for (i = 1; i < FF_ARRAY_ELEMS(sar_idc); i++) {
91  if (num == sar_idc[i].num &&
92  den == sar_idc[i].den)
93  break;
94  }
95  if (i == FF_ARRAY_ELEMS(sar_idc)) {
96  sps->vui.aspect_ratio_idc = 255;
97  sps->vui.sar_width = num;
98  sps->vui.sar_height = den;
99  } else {
100  sps->vui.aspect_ratio_idc = i;
101  }
103  need_vui = 1;
104  }
105 
106 #define SET_OR_INFER(field, value, present_flag, infer) do { \
107  if (value >= 0) { \
108  field = value; \
109  need_vui = 1; \
110  } else if (!present_flag) \
111  field = infer; \
112  } while (0)
113 
114  if (ctx->video_format >= 0 ||
115  ctx->video_full_range_flag >= 0 ||
116  ctx->colour_primaries >= 0 ||
117  ctx->transfer_characteristics >= 0 ||
118  ctx->matrix_coefficients >= 0) {
119 
122 
126 
127  if (ctx->colour_primaries >= 0 ||
128  ctx->transfer_characteristics >= 0 ||
129  ctx->matrix_coefficients >= 0) {
130 
132  ctx->colour_primaries,
134 
138 
140  ctx->matrix_coefficients,
142 
144  }
146  need_vui = 1;
147  }
148 
149  if (ctx->chroma_sample_loc_type >= 0) {
155  need_vui = 1;
156  }
157 
158  if (ctx->tick_rate.num && ctx->tick_rate.den) {
159  int num, den;
160 
161  av_reduce(&num, &den, ctx->tick_rate.num, ctx->tick_rate.den,
162  UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
163 
164  sps->vui.time_scale = num;
165  sps->vui.num_units_in_tick = den;
166 
167  sps->vui.timing_info_present_flag = 1;
168  need_vui = 1;
169  }
172  sps->vui.timing_info_present_flag, 0);
173 
174  if (sps->separate_colour_plane_flag || sps->chroma_format_idc == 0) {
175  crop_unit_x = 1;
176  crop_unit_y = 2 - sps->frame_mbs_only_flag;
177  } else {
178  crop_unit_x = 1 + (sps->chroma_format_idc < 3);
179  crop_unit_y = (1 + (sps->chroma_format_idc < 2)) *
180  (2 - sps->frame_mbs_only_flag);
181  }
182 #define CROP(border, unit) do { \
183  if (ctx->crop_ ## border >= 0) { \
184  if (ctx->crop_ ## border % unit != 0) { \
185  av_log(bsf, AV_LOG_ERROR, "Invalid value for crop_%s: " \
186  "must be a multiple of %d.\n", #border, unit); \
187  return AVERROR(EINVAL); \
188  } \
189  sps->frame_crop_ ## border ## _offset = \
190  ctx->crop_ ## border / unit; \
191  sps->frame_cropping_flag = 1; \
192  } \
193  } while (0)
194  CROP(left, crop_unit_x);
195  CROP(right, crop_unit_x);
196  CROP(top, crop_unit_y);
197  CROP(bottom, crop_unit_y);
198 #undef CROP
199 
200  if (need_vui)
202 
203  return 0;
204 }
205 
207 {
209  AVPacket *in = NULL;
211  int err, i, j, has_sps;
212  char *sei_udu_string = NULL;
213 
214  err = ff_bsf_get_packet(bsf, &in);
215  if (err < 0)
216  goto fail;
217 
218  err = ff_cbs_read_packet(ctx->cbc, au, in);
219  if (err < 0) {
220  av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
221  goto fail;
222  }
223 
224  if (au->nb_units == 0) {
225  av_log(bsf, AV_LOG_ERROR, "No NAL units in packet.\n");
226  err = AVERROR_INVALIDDATA;
227  goto fail;
228  }
229 
230  // If an AUD is present, it must be the first NAL unit.
231  if (au->units[0].type == H264_NAL_AUD) {
232  if (ctx->aud == REMOVE)
233  ff_cbs_delete_unit(ctx->cbc, au, 0);
234  } else {
235  if (ctx->aud == INSERT) {
236  static const int primary_pic_type_table[] = {
237  0x084, // 2, 7
238  0x0a5, // 0, 2, 5, 7
239  0x0e7, // 0, 1, 2, 5, 6, 7
240  0x210, // 4, 9
241  0x318, // 3, 4, 8, 9
242  0x294, // 2, 4, 7, 9
243  0x3bd, // 0, 2, 3, 4, 5, 7, 8, 9
244  0x3ff, // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
245  };
246  int primary_pic_type_mask = 0xff;
247  H264RawAUD *aud = &ctx->aud_nal;
248 
249  for (i = 0; i < au->nb_units; i++) {
250  if (au->units[i].type == H264_NAL_SLICE ||
251  au->units[i].type == H264_NAL_IDR_SLICE) {
252  H264RawSlice *slice = au->units[i].content;
253  for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++) {
254  if (!(primary_pic_type_table[j] &
255  (1 << slice->header.slice_type)))
256  primary_pic_type_mask &= ~(1 << j);
257  }
258  }
259  }
260  for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++)
261  if (primary_pic_type_mask & (1 << j))
262  break;
263  if (j >= FF_ARRAY_ELEMS(primary_pic_type_table)) {
264  av_log(bsf, AV_LOG_ERROR, "No usable primary_pic_type: "
265  "invalid slice types?\n");
266  err = AVERROR_INVALIDDATA;
267  goto fail;
268  }
269 
271  aud->primary_pic_type = j;
272 
273  err = ff_cbs_insert_unit_content(ctx->cbc, au,
274  0, H264_NAL_AUD, aud);
275  if (err < 0) {
276  av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n");
277  goto fail;
278  }
279  }
280  }
281 
282  has_sps = 0;
283  for (i = 0; i < au->nb_units; i++) {
284  if (au->units[i].type == H264_NAL_SPS) {
285  err = h264_metadata_update_sps(bsf, au->units[i].content);
286  if (err < 0)
287  goto fail;
288  has_sps = 1;
289  }
290  }
291 
292  // Insert the SEI in access units containing SPSs, and also
293  // unconditionally in the first access unit we ever see.
294  if (ctx->sei_user_data && (has_sps || !ctx->sei_first_au)) {
295  H264RawSEI *sei;
296  H264RawSEIPayload *payload;
298  int sei_pos, sei_new;
299 
300  ctx->sei_first_au = 1;
301 
302  for (i = 0; i < au->nb_units; i++) {
303  if (au->units[i].type == H264_NAL_SEI ||
304  au->units[i].type == H264_NAL_SLICE ||
305  au->units[i].type == H264_NAL_IDR_SLICE)
306  break;
307  }
308  sei_pos = i;
309 
310  if (sei_pos < au->nb_units &&
311  au->units[sei_pos].type == H264_NAL_SEI) {
312  sei_new = 0;
313  sei = au->units[sei_pos].content;
314  } else {
315  sei_new = 1;
316  sei = &ctx->sei_nal;
317  memset(sei, 0, sizeof(*sei));
318 
320 
321  err = ff_cbs_insert_unit_content(ctx->cbc, au,
322  sei_pos, H264_NAL_SEI, sei);
323  if (err < 0) {
324  av_log(bsf, AV_LOG_ERROR, "Failed to insert SEI.\n");
325  goto fail;
326  }
327  }
328 
329  payload = &sei->payload[sei->payload_count];
330 
332  udu = &payload->payload.user_data_unregistered;
333 
334  for (i = j = 0; j < 32 && ctx->sei_user_data[i]; i++) {
335  int c, v;
336  c = ctx->sei_user_data[i];
337  if (c == '-') {
338  continue;
339  } else if (av_isxdigit(c)) {
340  c = av_tolower(c);
341  v = (c <= '9' ? c - '0' : c - 'a' + 10);
342  } else {
343  goto invalid_user_data;
344  }
345  if (i & 1)
346  udu->uuid_iso_iec_11578[j / 2] |= v;
347  else
348  udu->uuid_iso_iec_11578[j / 2] = v << 4;
349  ++j;
350  }
351  if (j == 32 && ctx->sei_user_data[i] == '+') {
352  sei_udu_string = av_strdup(ctx->sei_user_data + i + 1);
353  if (!sei_udu_string) {
354  err = AVERROR(ENOMEM);
355  goto sei_fail;
356  }
357 
358  udu->data = sei_udu_string;
359  udu->data_length = strlen(sei_udu_string);
360 
361  payload->payload_size = 16 + udu->data_length;
362 
363  if (!sei_new) {
364  // This will be freed by the existing internal
365  // reference in fragment_uninit().
366  sei_udu_string = NULL;
367  }
368 
369  } else {
370  invalid_user_data:
371  av_log(bsf, AV_LOG_ERROR, "Invalid user data: "
372  "must be \"UUID+string\".\n");
373  err = AVERROR(EINVAL);
374  sei_fail:
375  memset(payload, 0, sizeof(*payload));
376  goto fail;
377  }
378 
379  ++sei->payload_count;
380  }
381 
382  err = ff_cbs_write_packet(ctx->cbc, out, au);
383  if (err < 0) {
384  av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
385  goto fail;
386  }
387 
388  err = av_packet_copy_props(out, in);
389  if (err < 0)
390  goto fail;
391 
392  err = 0;
393 fail:
394  ff_cbs_fragment_uninit(ctx->cbc, au);
395  av_freep(&sei_udu_string);
396 
397  av_packet_free(&in);
398 
399  return err;
400 }
401 
403 {
406  int err, i;
407 
408  err = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_H264, bsf);
409  if (err < 0)
410  return err;
411 
412  if (bsf->par_in->extradata) {
413  err = ff_cbs_read_extradata(ctx->cbc, au, bsf->par_in);
414  if (err < 0) {
415  av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
416  goto fail;
417  }
418 
419  for (i = 0; i < au->nb_units; i++) {
420  if (au->units[i].type == H264_NAL_SPS) {
421  err = h264_metadata_update_sps(bsf, au->units[i].content);
422  if (err < 0)
423  goto fail;
424  }
425  }
426 
427  err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, au);
428  if (err < 0) {
429  av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
430  goto fail;
431  }
432  }
433 
434  err = 0;
435 fail:
436  ff_cbs_fragment_uninit(ctx->cbc, au);
437  return err;
438 }
439 
441 {
443  ff_cbs_close(&ctx->cbc);
444 }
445 
446 #define OFFSET(x) offsetof(H264MetadataContext, x)
447 static const AVOption h264_metadata_options[] = {
448  { "aud", "Access Unit Delimiter NAL units",
450  { .i64 = PASS }, PASS, REMOVE, 0, "aud" },
451  { "pass", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PASS }, .unit = "aud" },
452  { "insert", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = INSERT }, .unit = "aud" },
453  { "remove", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = REMOVE }, .unit = "aud" },
454 
455  { "sample_aspect_ratio", "Set sample aspect ratio (table E-1)",
456  OFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL,
457  { .dbl = 0.0 }, 0, 65535 },
458 
459  { "video_format", "Set video format (table E-2)",
460  OFFSET(video_format), AV_OPT_TYPE_INT,
461  { .i64 = -1 }, -1, 7 },
462  { "video_full_range_flag", "Set video full range flag",
463  OFFSET(video_full_range_flag), AV_OPT_TYPE_INT,
464  { .i64 = -1 }, -1, 1 },
465  { "colour_primaries", "Set colour primaries (table E-3)",
466  OFFSET(colour_primaries), AV_OPT_TYPE_INT,
467  { .i64 = -1 }, -1, 255 },
468  { "transfer_characteristics", "Set transfer characteristics (table E-4)",
470  { .i64 = -1 }, -1, 255 },
471  { "matrix_coefficients", "Set matrix coefficients (table E-5)",
472  OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
473  { .i64 = -1 }, -1, 255 },
474 
475  { "chroma_sample_loc_type", "Set chroma sample location type (figure E-1)",
476  OFFSET(chroma_sample_loc_type), AV_OPT_TYPE_INT,
477  { .i64 = -1 }, -1, 6 },
478 
479  { "tick_rate", "Set VUI tick rate (num_units_in_tick / time_scale)",
480  OFFSET(tick_rate), AV_OPT_TYPE_RATIONAL,
481  { .dbl = 0.0 }, 0, UINT_MAX },
482  { "fixed_frame_rate_flag", "Set VUI fixed frame rate flag",
483  OFFSET(fixed_frame_rate_flag), AV_OPT_TYPE_INT,
484  { .i64 = -1 }, -1, 1 },
485 
486  { "crop_left", "Set left border crop offset",
487  OFFSET(crop_left), AV_OPT_TYPE_INT,
488  { .i64 = -1 }, -1, H264_MAX_WIDTH },
489  { "crop_right", "Set right border crop offset",
490  OFFSET(crop_right), AV_OPT_TYPE_INT,
491  { .i64 = -1 }, -1, H264_MAX_WIDTH },
492  { "crop_top", "Set top border crop offset",
493  OFFSET(crop_top), AV_OPT_TYPE_INT,
494  { .i64 = -1 }, -1, H264_MAX_HEIGHT },
495  { "crop_bottom", "Set bottom border crop offset",
496  OFFSET(crop_bottom), AV_OPT_TYPE_INT,
497  { .i64 = -1 }, -1, H264_MAX_HEIGHT },
498 
499  { "sei_user_data", "Insert SEI user data (UUID+string)",
500  OFFSET(sei_user_data), AV_OPT_TYPE_STRING, { .str = NULL } },
501 
502  { NULL }
503 };
504 
505 static const AVClass h264_metadata_class = {
506  .class_name = "h264_metadata_bsf",
507  .item_name = av_default_item_name,
508  .option = h264_metadata_options,
509  .version = LIBAVUTIL_VERSION_INT,
510 };
511 
512 static const enum AVCodecID h264_metadata_codec_ids[] = {
514 };
515 
517  .name = "h264_metadata",
518  .priv_data_size = sizeof(H264MetadataContext),
519  .priv_class = &h264_metadata_class,
521  .close = &h264_metadata_close,
524 };
static int h264_metadata_update_sps(AVBSFContext *bsf, H264RawSPS *sps)
uint32_t payload_type
Definition: cbs_h264.h:294
#define NULL
Definition: coverity.c:32
int nb_units
Number of units in this fragment.
Definition: cbs.h:133
const char * sei_user_data
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AVCodecParameters * par_out
Parameters of the output stream.
Definition: avcodec.h:5591
uint8_t aspect_ratio_idc
Definition: cbs_h264.h:69
uint8_t video_format
Definition: cbs_h264.h:77
static const AVOption h264_metadata_options[]
AVOption.
Definition: opt.h:246
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
uint8_t chroma_sample_loc_type_bottom_field
Definition: cbs_h264.h:86
int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to a packet.
Definition: cbs.c:267
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
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:42
H264RawNALUnitHeader nal_unit_header
Definition: cbs_h264.h:312
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:65
int num
Numerator.
Definition: rational.h:59
The bitstream filter state.
Definition: avcodec.h:5557
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:193
const AVBitStreamFilter ff_h264_metadata_bsf
void * priv_data
Opaque filter-specific private data.
Definition: avcodec.h:5578
uint8_t fixed_frame_rate_flag
Definition: cbs_h264.h:91
H264RawVUI vui
Definition: cbs_h264.h:163
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 void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhd.c:97
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:62
AVOptions.
uint32_t num_units_in_tick
Definition: cbs_h264.h:89
unregistered user data
Definition: h264_sei.h:32
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:172
const char * name
Definition: avcodec.h:5607
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:92
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units.
Definition: cbs.h:139
H264RawNALUnitHeader nal_unit_header
Definition: cbs_h264.h:226
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:422
#define av_log(a,...)
uint8_t primary_pic_type
Definition: cbs_h264.h:228
H.264 common definitions.
static av_const int av_tolower(int c)
Locale-independent conversion of ASCII characters to lowercase.
Definition: avstring.h:241
uint8_t chroma_sample_loc_type_top_field
Definition: cbs_h264.h:85
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
CodedBitstreamContext * cbc
uint8_t aspect_ratio_info_present_flag
Definition: cbs_h264.h:68
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
Definition: cbs.c:106
#define AVERROR(e)
Definition: error.h:43
uint8_t transfer_characteristics
Definition: cbs_h264.h:81
uint16_t sar_width
Definition: cbs_h264.h:70
uint8_t slice_type
Definition: cbs_h264.h:322
uint8_t frame_mbs_only_flag
Definition: cbs_h264.h:152
#define fail()
Definition: checkasm.h:113
uint8_t timing_info_present_flag
Definition: cbs_h264.h:88
uint8_t video_full_range_flag
Definition: cbs_h264.h:78
H264RawSEIUserDataUnregistered user_data_unregistered
Definition: cbs_h264.h:301
static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
Definition: avpacket.c:558
uint8_t colour_primaries
Definition: cbs_h264.h:80
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:242
uint16_t sar_height
Definition: cbs_h264.h:71
uint8_t separate_colour_plane_flag
Definition: cbs_h264.h:127
CodedBitstreamFragment access_unit
uint8_t vui_parameters_present_flag
Definition: cbs_h264.h:162
#define CROP(border, unit)
AVFormatContext * ctx
Definition: movenc.c:48
uint8_t colour_description_present_flag
Definition: cbs_h264.h:79
uint8_t video_signal_type_present_flag
Definition: cbs_h264.h:76
int 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:468
union H264RawSEIPayload::@56 payload
uint8_t chroma_format_idc
Definition: cbs_h264.h:126
#define FF_ARRAY_ELEMS(a)
#define SET_OR_INFER(field, value, present_flag, infer)
uint8_t chroma_loc_info_present_flag
Definition: cbs_h264.h:84
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:251
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:108
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
Describe the class of an AVClass context structure.
Definition: log.h:67
Context structure for coded bitstream operations.
Definition: cbs.h:145
uint8_t matrix_coefficients
Definition: cbs_h264.h:82
Rational number (pair of numerator and denominator).
Definition: rational.h:58
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:81
static av_const int av_isxdigit(int c)
Locale-independent conversion of ASCII isxdigit.
Definition: avstring.h:251
H264RawSEIPayload payload[H264_MAX_SEI_PAYLOADS]
Definition: cbs_h264.h:314
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:151
static enum AVCodecID h264_metadata_codec_ids[]
static int h264_metadata_init(AVBSFContext *bsf)
common internal and external API header
static const AVClass h264_metadata_class
static double c[64]
static void h264_metadata_close(AVBSFContext *bsf)
static enum AVCodecID codec_ids[]
int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
Called by the bitstream filters to get the next packet for filtering.
Definition: bsf.c:201
#define OFFSET(x)
uint32_t time_scale
Definition: cbs_h264.h:90
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
int den
Denominator.
Definition: rational.h:60
H264RawSliceHeader header
Definition: cbs_h264.h:397
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3826
AVRational sample_aspect_ratio
FILE * out
Definition: movenc.c:54
uint32_t payload_size
Definition: cbs_h264.h:295
#define av_freep(p)
uint8_t nal_unit_type
Definition: cbs_h264.h:42
This structure stores compressed data.
Definition: avcodec.h:1377
AVCodecParameters * par_in
Parameters of the input stream.
Definition: avcodec.h:5585
uint8_t payload_count
Definition: cbs_h264.h:315
static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out)