FFmpeg
extract_extradata.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 <stdint.h>
20 
21 #include "libavutil/log.h"
22 #include "libavutil/mem.h"
23 #include "libavutil/opt.h"
24 
25 #include "av1.h"
26 #include "av1_parse.h"
27 #include "bsf.h"
28 #include "bsf_internal.h"
29 #include "bytestream.h"
30 #include "h2645_parse.h"
31 #include "h264.h"
32 #include "lcevc.h"
33 #include "startcode.h"
34 #include "vc1_common.h"
35 #include "vvc.h"
36 
37 #include "hevc/hevc.h"
38 
39 typedef struct ExtractExtradataContext {
40  const AVClass *class;
41 
43  uint8_t **data, int *size);
44 
45  /* AV1 specific fields */
47 
48  /* H264/HEVC specific fields */
50 
51  /* AVOptions */
52  int remove;
54 
55 static int val_in_array(const int *arr, size_t len, int val)
56 {
57  for (size_t i = 0; i < len; i++)
58  if (arr[i] == val)
59  return 1;
60  return 0;
61 }
62 
63 static int metadata_is_global(const AV1OBU *obu)
64 {
65  static const int metadata_obu_types[] = {
67  };
68  GetBitContext gb;
69  int metadata_type;
70 
71  if (init_get_bits(&gb, obu->data, obu->size_bits) < 0)
72  return 0;
73 
74  metadata_type = get_leb(&gb);
75 
76  return val_in_array(metadata_obu_types, FF_ARRAY_ELEMS(metadata_obu_types),
77  metadata_type);
78 }
79 
80 static int obu_is_global(const AV1OBU *obu)
81 {
82  static const int extradata_obu_types[] = {
84  };
85 
86  if (!val_in_array(extradata_obu_types, FF_ARRAY_ELEMS(extradata_obu_types),
87  obu->type))
88  return 0;
89  if (obu->type != AV1_OBU_METADATA)
90  return 1;
91 
92  return metadata_is_global(obu);
93 }
94 
96  uint8_t **data, int *size)
97 {
98 
100 
101  int extradata_size = 0, filtered_size = 0;
102  int i, has_seq = 0, ret = 0;
103 
104  ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);
105  if (ret < 0)
106  return ret;
107 
108  for (i = 0; i < s->av1_pkt.nb_obus; i++) {
109  AV1OBU *obu = &s->av1_pkt.obus[i];
110  if (obu_is_global(obu)) {
111  extradata_size += obu->raw_size;
112  if (obu->type == AV1_OBU_SEQUENCE_HEADER)
113  has_seq = 1;
114  } else if (s->remove) {
115  filtered_size += obu->raw_size;
116  }
117  }
118 
119  if (extradata_size && has_seq) {
120  AVBufferRef *filtered_buf = NULL;
121  PutByteContext pb_filtered_data, pb_extradata;
122  uint8_t *extradata;
123 
124  if (s->remove) {
125  filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
126  if (!filtered_buf) {
127  return AVERROR(ENOMEM);
128  }
129  memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
130  }
131 
132  extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
133  if (!extradata) {
134  av_buffer_unref(&filtered_buf);
135  return AVERROR(ENOMEM);
136  }
137 
138  *data = extradata;
139  *size = extradata_size;
140 
141  bytestream2_init_writer(&pb_extradata, extradata, extradata_size);
142  if (s->remove)
143  bytestream2_init_writer(&pb_filtered_data, filtered_buf->data, filtered_size);
144 
145  for (i = 0; i < s->av1_pkt.nb_obus; i++) {
146  AV1OBU *obu = &s->av1_pkt.obus[i];
147  if (obu_is_global(obu)) {
148  bytestream2_put_bufferu(&pb_extradata, obu->raw_data, obu->raw_size);
149  } else if (s->remove) {
150  bytestream2_put_bufferu(&pb_filtered_data, obu->raw_data, obu->raw_size);
151  }
152  }
153 
154  if (s->remove) {
156  pkt->buf = filtered_buf;
157  pkt->data = filtered_buf->data;
158  pkt->size = filtered_size;
159  }
160  }
161 
162  return 0;
163 }
164 
166  uint8_t **data, int *size)
167 {
168  static const int extradata_nal_types_vvc[] = {
170  };
171  static const int extradata_nal_types_hevc[] = {
173  };
174  static const int extradata_nal_types_h264[] = {
176  };
177 
179 
180  int extradata_size = 0, filtered_size = 0;
181  const int *extradata_nal_types;
182  size_t nb_extradata_nal_types;
183  int i, has_sps = 0, has_vps = 0, ret = 0;
184 
185  if (ctx->par_in->codec_id == AV_CODEC_ID_VVC) {
186  extradata_nal_types = extradata_nal_types_vvc;
187  nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_vvc);
188  } else if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {
189  extradata_nal_types = extradata_nal_types_hevc;
190  nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_hevc);
191  } else {
192  extradata_nal_types = extradata_nal_types_h264;
193  nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_h264);
194  }
195 
196  ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size,
197  ctx, 0, ctx->par_in->codec_id, H2645_FLAG_SMALL_PADDING);
198  if (ret < 0)
199  return ret;
200 
201  for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
202  H2645NAL *nal = &s->h2645_pkt.nals[i];
203  if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) {
204  extradata_size += nal->raw_size + 3;
205  if (ctx->par_in->codec_id == AV_CODEC_ID_VVC) {
206  if (nal->type == VVC_SPS_NUT) has_sps = 1;
207  if (nal->type == VVC_VPS_NUT) has_vps = 1;
208  } else if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {
209  if (nal->type == HEVC_NAL_SPS) has_sps = 1;
210  if (nal->type == HEVC_NAL_VPS) has_vps = 1;
211  } else {
212  if (nal->type == H264_NAL_SPS) has_sps = 1;
213  }
214  } else if (s->remove) {
215  filtered_size += nal->raw_size + 3;
216  }
217  }
218 
219  if (extradata_size &&
220  ((ctx->par_in->codec_id == AV_CODEC_ID_VVC && has_sps) ||
221  (ctx->par_in->codec_id == AV_CODEC_ID_HEVC && has_sps && has_vps) ||
222  (ctx->par_in->codec_id == AV_CODEC_ID_H264 && has_sps))) {
223  AVBufferRef *filtered_buf = NULL;
224  PutByteContext pb_filtered_data, pb_extradata;
225  uint8_t *extradata;
226 
227  if (s->remove) {
228  filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
229  if (!filtered_buf) {
230  return AVERROR(ENOMEM);
231  }
232  memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
233  }
234 
235  extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
236  if (!extradata) {
237  av_buffer_unref(&filtered_buf);
238  return AVERROR(ENOMEM);
239  }
240 
241  *data = extradata;
242  *size = extradata_size;
243 
244  bytestream2_init_writer(&pb_extradata, extradata, extradata_size);
245  if (s->remove)
246  bytestream2_init_writer(&pb_filtered_data, filtered_buf->data, filtered_size);
247 
248  for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
249  H2645NAL *nal = &s->h2645_pkt.nals[i];
250  if (val_in_array(extradata_nal_types, nb_extradata_nal_types,
251  nal->type)) {
252  bytestream2_put_be24u(&pb_extradata, 1); //startcode
253  bytestream2_put_bufferu(&pb_extradata, nal->raw_data, nal->raw_size);
254  } else if (s->remove) {
255  bytestream2_put_be24u(&pb_filtered_data, 1); // startcode
256  bytestream2_put_bufferu(&pb_filtered_data, nal->raw_data, nal->raw_size);
257  }
258  }
259 
260  if (s->remove) {
262  pkt->buf = filtered_buf;
263  pkt->data = filtered_buf->data;
264  pkt->size = filtered_size;
265  }
266  }
267 
268  return 0;
269 }
270 
271 static inline uint64_t get_mb(GetBitContext *s) {
272  int more, i = 0;
273  uint64_t mb = 0;
274 
275  do {
276  int byte = get_bits(s, 8);
277  unsigned bits = byte & 0x7f;
278  more = byte & 0x80;
279  mb = (mb << 7) | bits;
280  if (++i == 10)
281  break;
282  } while (more);
283 
284  return mb;
285 }
286 
287 /**
288  * Rewrite the NALu stripping the unneeded blocks.
289  * Given that length fields coded inside the NALu are not aware of any emulation_3bytes
290  * present in the bitstream, we need to keep track of the raw buffer as we navigate
291  * the stripped buffer.
292  */
294  int remove)
295 {
296  GetByteContext gbc, raw_gbc;
297  int sc = 0, gc = 0;
298  int skipped_byte_pos = 0;
299 
300  bytestream2_init(&gbc, nal->data, nal->size);
301  bytestream2_init(&raw_gbc, nal->raw_data, nal->raw_size);
302  bytestream2_put_be16(pbc, bytestream2_get_be16(&gbc));
303  bytestream2_skip(&raw_gbc, 2);
304 
305  while (bytestream2_get_bytes_left(&gbc) > 1) {
306  GetBitContext gb;
307  int payload_size_type, payload_type;
308  uint64_t payload_size;
309  int block_size, raw_block_size, block_end;
310 
312 
313  payload_size_type = get_bits(&gb, 3);
314  payload_type = get_bits(&gb, 5);
315  payload_size = payload_size_type;
316  if (payload_size_type == 6)
317  return AVERROR_PATCHWELCOME;
318  if (payload_size_type == 7)
319  payload_size = get_mb(&gb);
320 
321  if (payload_size > INT_MAX - (get_bits_count(&gb) >> 3))
322  return AVERROR_INVALIDDATA;
323 
324  block_size = raw_block_size = payload_size + (get_bits_count(&gb) >> 3);
325  if (block_size >= bytestream2_get_bytes_left(&gbc))
326  return AVERROR_INVALIDDATA;
327 
328  block_end = bytestream2_tell(&gbc) + block_size;
329  // Take into account removed emulation 3bytes, as payload_size in
330  // the bitstream is not aware of them.
331  for (; skipped_byte_pos < nal->skipped_bytes; skipped_byte_pos++) {
332  if (nal->skipped_bytes_pos[skipped_byte_pos] >= block_end)
333  break;
334  raw_block_size++;
335  }
336 
337  switch (payload_type) {
341  if (remove)
342  break;
343  bytestream2_put_buffer(pbc, raw_gbc.buffer, raw_block_size);
344  sc |= payload_type == LCEVC_PAYLOAD_TYPE_SEQUENCE_CONFIG;
345  gc |= payload_type == LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG;
346  break;
347  default:
348  if (!remove)
349  break;
350  bytestream2_put_buffer(pbc, raw_gbc.buffer, raw_block_size);
351  break;
352  }
353 
354  bytestream2_skip(&gbc, block_size);
355  bytestream2_skip(&raw_gbc, raw_block_size);
356  }
357 
358  if (!remove && !sc && !gc)
359  return AVERROR_INVALIDDATA;
360 
361  bytestream2_put_byte(pbc, 0x80); // rbsp_alignment bits
362 
363  return bytestream2_tell_p(pbc);
364 }
365 
367  uint8_t **data, int *size)
368 {
369  static const int extradata_nal_types[] = {
371  };
372 
374  PutByteContext pb_extradata;
375  int extradata_size = 0, filtered_size = 0;
376  size_t nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types);
377  int i, ret = 0;
378 
379  ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size,
380  ctx, 0, ctx->par_in->codec_id, H2645_FLAG_SMALL_PADDING);
381  if (ret < 0)
382  return ret;
383 
384  for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
385  H2645NAL *nal = &s->h2645_pkt.nals[i];
386  if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) {
387  bytestream2_init_writer(&pb_extradata, NULL, 0);
388  // dummy pass to find sc, gc or ai
389  if (!write_lcevc_nalu(ctx, &pb_extradata, nal, 0))
390  extradata_size += nal->raw_size + 3;
391  }
392  filtered_size += nal->raw_size + 3;
393  }
394 
395  if (extradata_size) {
396  AVBufferRef *filtered_buf = NULL;
397  PutByteContext pb_filtered_data;
398  uint8_t *extradata;
399 
400  if (s->remove) {
401  filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
402  if (!filtered_buf) {
403  return AVERROR(ENOMEM);
404  }
405  memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
406  }
407 
408  extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
409  if (!extradata) {
410  av_buffer_unref(&filtered_buf);
411  return AVERROR(ENOMEM);
412  }
413 
414  *data = extradata;
415  *size = 0;
416 
417  bytestream2_init_writer(&pb_extradata, extradata, extradata_size);
418  if (s->remove)
419  bytestream2_init_writer(&pb_filtered_data, filtered_buf->data, filtered_size);
420 
421  filtered_size = 0;
422  for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
423  H2645NAL *nal = &s->h2645_pkt.nals[i];
424  if (val_in_array(extradata_nal_types, nb_extradata_nal_types,
425  nal->type)) {
426  bytestream2_put_be24(&pb_extradata, 1); //startcode
427  ret = write_lcevc_nalu(ctx, &pb_extradata, nal, 0);
428  if (ret < 0) {
429  av_freep(data);
430  av_buffer_unref(&filtered_buf);
431  return ret;
432  }
433  *size += ret;
434  if (s->remove) {
435  bytestream2_put_be24(&pb_filtered_data, 1); //startcode
436  ret = write_lcevc_nalu(ctx, &pb_filtered_data, nal, 1);
437  if (ret < 0) {
438  av_freep(data);
439  av_buffer_unref(&filtered_buf);
440  return ret;
441  }
442  filtered_size += ret;
443  }
444  } else if (s->remove) {
445  bytestream2_put_be24(&pb_filtered_data, 1); //startcode
446  bytestream2_put_bufferu(&pb_filtered_data, nal->raw_data, nal->raw_size);
447  filtered_size += nal->raw_size;
448  }
449  }
450 
451  if (s->remove) {
453  pkt->buf = filtered_buf;
454  pkt->data = filtered_buf->data;
455  pkt->size = filtered_size;
456  }
457  }
458 
459  return 0;
460 }
461 
463  uint8_t **data, int *size)
464 {
466  const uint8_t *ptr = pkt->data, *end = pkt->data + pkt->size;
467  uint32_t state = UINT32_MAX;
468  int has_extradata = 0, extradata_size = 0;
469 
470  while (ptr < end) {
471  ptr = avpriv_find_start_code(ptr, end, &state);
473  has_extradata = 1;
474  } else if (has_extradata && IS_MARKER(state)) {
475  extradata_size = ptr - 4 - pkt->data;
476  break;
477  }
478  }
479 
480  if (extradata_size) {
481  *data = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
482  if (!*data)
483  return AVERROR(ENOMEM);
484 
485  memcpy(*data, pkt->data, extradata_size);
486  *size = extradata_size;
487 
488  if (s->remove) {
489  pkt->data += extradata_size;
490  pkt->size -= extradata_size;
491  }
492  }
493 
494  return 0;
495 }
496 
498  uint8_t **data, int *size)
499 {
501  uint32_t state = UINT32_MAX;
502  int i, found = 0;
503 
504  for (i = 0; i < pkt->size; i++) {
505  state = (state << 8) | pkt->data[i];
506  if (state == 0x1B3)
507  found = 1;
508  else if (found && state != 0x1B5 && state < 0x200 && state >= 0x100) {
509  *size = i - 3;
511  if (!*data)
512  return AVERROR(ENOMEM);
513 
514  memcpy(*data, pkt->data, *size);
515 
516  if (s->remove) {
517  pkt->data += *size;
518  pkt->size -= *size;
519  }
520  break;
521  }
522  }
523  return 0;
524 }
525 
527  uint8_t **data, int *size)
528 {
530  const uint8_t *ptr = pkt->data, *end = pkt->data + pkt->size;
531  uint32_t state = UINT32_MAX;
532 
533  while (ptr < end) {
534  ptr = avpriv_find_start_code(ptr, end, &state);
535  if (state == 0x1B3 || state == 0x1B6) {
536  if (ptr - pkt->data > 4) {
537  *size = ptr - 4 - pkt->data;
539  if (!*data)
540  return AVERROR(ENOMEM);
541 
542  memcpy(*data, pkt->data, *size);
543 
544  if (s->remove) {
545  pkt->data += *size;
546  pkt->size -= *size;
547  }
548  }
549  break;
550  }
551  }
552  return 0;
553 }
554 
555 static const struct {
556  enum AVCodecID id;
558  uint8_t **data, int *size);
559 } extract_tab[] = {
572 };
573 
575 {
577  int i;
578 
579  for (i = 0; i < FF_ARRAY_ELEMS(extract_tab); i++) {
580  if (extract_tab[i].id == ctx->par_in->codec_id) {
581  s->extract = extract_tab[i].extract;
582  break;
583  }
584  }
585  if (!s->extract)
586  return AVERROR_BUG;
587 
588  return 0;
589 }
590 
592 {
594  uint8_t *extradata = NULL;
595  int extradata_size;
596  int ret = 0;
597 
599  if (ret < 0)
600  return ret;
601 
602  ret = s->extract(ctx, pkt, &extradata, &extradata_size);
603  if (ret < 0)
604  goto fail;
605 
606  if (extradata) {
607  memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
609  extradata, extradata_size);
610  if (ret < 0) {
611  av_freep(&extradata);
612  goto fail;
613  }
614  }
615 
616  return 0;
617 
618 fail:
620  return ret;
621 }
622 
624 {
626  ff_av1_packet_uninit(&s->av1_pkt);
627  ff_h2645_packet_uninit(&s->h2645_pkt);
628 }
629 
630 static const enum AVCodecID codec_ids[] = {
644 };
645 
646 #define OFFSET(x) offsetof(ExtractExtradataContext, x)
647 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
648 static const AVOption options[] = {
649  { "remove", "remove the extradata from the bitstream", OFFSET(remove), AV_OPT_TYPE_INT,
650  { .i64 = 0 }, 0, 1, FLAGS },
651  { NULL },
652 };
653 
655  .class_name = "extract_extradata",
656  .item_name = av_default_item_name,
657  .option = options,
658  .version = LIBAVUTIL_VERSION_INT,
659 };
660 
662  .p.name = "extract_extradata",
663  .p.codec_ids = codec_ids,
664  .p.priv_class = &extract_extradata_class,
665  .priv_data_size = sizeof(ExtractExtradataContext),
669 };
H264_NAL_PPS
@ H264_NAL_PPS
Definition: h264.h:42
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
ExtractExtradataContext::h2645_pkt
H2645Packet h2645_pkt
Definition: extract_extradata.c:49
h2645_parse.h
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
bsf_internal.h
opt.h
extract_extradata_lcevc
static int extract_extradata_lcevc(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:366
extract_extradata_h2645
static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:165
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition: bytestream.h:158
OFFSET
#define OFFSET(x)
Definition: extract_extradata.c:646
GetByteContext
Definition: bytestream.h:33
bytestream2_tell
static av_always_inline int bytestream2_tell(const GetByteContext *g)
Definition: bytestream.h:192
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
extract_extradata_vc1
static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:462
AVBitStreamFilter::name
const char * name
Definition: bsf.h:112
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:254
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
extract_extradata_class
static const AVClass extract_extradata_class
Definition: extract_extradata.c:654
state
static struct @560 state
AVPacket::data
uint8_t * data
Definition: packet.h:588
AVOption
AVOption.
Definition: opt.h:429
ff_h2645_packet_uninit
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
Definition: h2645_parse.c:667
AV_CODEC_ID_AVS2
@ AV_CODEC_ID_AVS2
Definition: codec_id.h:248
data
const char data[16]
Definition: mxf.c:149
AV1OBU
Definition: av1_parse.h:38
id
enum AVCodecID id
Definition: extract_extradata.c:556
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
extract_extradata_mpeg12
static int extract_extradata_mpeg12(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:497
ExtractExtradataContext::av1_pkt
AV1Packet av1_pkt
Definition: extract_extradata.c:46
obu_is_global
static int obu_is_global(const AV1OBU *obu)
Definition: extract_extradata.c:80
extract
int(* extract)(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:557
ExtractExtradataContext::remove
int remove
Definition: extract_extradata.c:52
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:517
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
AV1OBU::data
const uint8_t * data
Definition: av1_parse.h:41
ff_av1_packet_split
int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, int length, void *logctx)
Split an input packet into OBUs.
Definition: av1_parse.c:56
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:197
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:337
av1_parse.h
bsf.h
av_packet_add_side_data
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
Definition: packet.c:197
AV1Packet
An input packet split into OBUs.
Definition: av1_parse.h:60
fail
#define fail()
Definition: checkasm.h:220
LCEVC_PAYLOAD_TYPE_SEQUENCE_CONFIG
@ LCEVC_PAYLOAD_TYPE_SEQUENCE_CONFIG
Definition: lcevc.h:70
ExtractExtradataContext::extract
int(* extract)(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:42
extract_extradata_close
static void extract_extradata_close(AVBSFContext *ctx)
Definition: extract_extradata.c:623
GetBitContext
Definition: get_bits.h:109
val
static double val(void *priv, double ch)
Definition: aeval.c:77
extract_extradata_mpeg4
static int extract_extradata_mpeg4(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:526
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:544
bytestream2_init_writer
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:147
s
#define s(width, name)
Definition: cbs_vp9.c:198
bytestream2_tell_p
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
Definition: bytestream.h:197
bytestream2_put_buffer
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:286
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
HEVC_NAL_VPS
@ HEVC_NAL_VPS
Definition: hevc.h:61
bits
uint8_t bits
Definition: vp3data.h:128
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
hevc.h
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AV1_METADATA_TYPE_HDR_MDCV
@ AV1_METADATA_TYPE_HDR_MDCV
Definition: av1.h:45
if
if(ret)
Definition: filter_design.txt:179
LCEVC_IDR_NUT
@ LCEVC_IDR_NUT
Definition: lcevc.h:61
AV_CODEC_ID_AVS3
@ AV_CODEC_ID_AVS3
Definition: codec_id.h:250
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:571
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
get_leb
static unsigned get_leb(GetBitContext *s)
Read a unsigned integer coded as a variable number of up to eight little-endian bytes,...
Definition: leb.h:35
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
FFBitStreamFilter
Definition: bsf_internal.h:27
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
LCEVC_PAYLOAD_TYPE_ADDITIONAL_INFO
@ LCEVC_PAYLOAD_TYPE_ADDITIONAL_INFO
Definition: lcevc.h:75
write_lcevc_nalu
static int write_lcevc_nalu(AVBSFContext *ctx, PutByteContext *pbc, const H2645NAL *nal, int remove)
Rewrite the NALu stripping the unneeded blocks.
Definition: extract_extradata.c:293
VC1_CODE_SEQHDR
@ VC1_CODE_SEQHDR
Definition: vc1_common.h:40
codec_ids
static enum AVCodecID codec_ids[]
Definition: extract_extradata.c:630
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
IS_MARKER
#define IS_MARKER(state)
Definition: dca_parser.c:52
options
Definition: swscale.c:43
VC1_CODE_ENTRYPOINT
@ VC1_CODE_ENTRYPOINT
Definition: vc1_common.h:39
extract_extradata_filter
static int extract_extradata_filter(AVBSFContext *ctx, AVPacket *pkt)
Definition: extract_extradata.c:591
avpriv_find_start_code
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
ff_extract_extradata_bsf
const FFBitStreamFilter ff_extract_extradata_bsf
Definition: extract_extradata.c:661
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:53
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
PutByteContext
Definition: bytestream.h:37
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition: bsf_internal.h:31
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:550
extract_extradata_init
static int extract_extradata_init(AVBSFContext *ctx)
Definition: extract_extradata.c:574
AVPacket::size
int size
Definition: packet.h:589
VVC_VPS_NUT
@ VVC_VPS_NUT
Definition: vvc.h:43
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
HEVC_NAL_SPS
@ HEVC_NAL_SPS
Definition: hevc.h:62
size
int size
Definition: twinvq_data.h:10344
H2645NAL
Definition: h2645_parse.h:34
mb
#define mb(name)
Definition: cbs_lcevc.c:95
AV1_OBU_SEQUENCE_HEADER
@ AV1_OBU_SEQUENCE_HEADER
Definition: av1.h:30
options
static const AVOption options[]
Definition: extract_extradata.c:648
val_in_array
static int val_in_array(const int *arr, size_t len, int val)
Definition: extract_extradata.c:55
HEVC_NAL_PPS
@ HEVC_NAL_PPS
Definition: hevc.h:63
LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG
@ LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG
Definition: lcevc.h:71
AV_CODEC_ID_VVC
@ AV_CODEC_ID_VVC
Definition: codec_id.h:252
AV1OBU::raw_size
int raw_size
Size of entire OBU, including header.
Definition: av1_parse.h:50
AV_CODEC_ID_LCEVC
@ AV_CODEC_ID_LCEVC
Definition: codec_id.h:615
av_buffer_alloc
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:77
VVC_SPS_NUT
@ VVC_SPS_NUT
Definition: vvc.h:44
vc1_common.h
AV1OBU::size_bits
int size_bits
Size, in bits, of just the data, excluding the trailing_one_bit and any trailing padding.
Definition: av1_parse.h:47
H2645_FLAG_SMALL_PADDING
@ H2645_FLAG_SMALL_PADDING
Definition: h2645_parse.h:98
FLAGS
#define FLAGS
Definition: extract_extradata.c:647
log.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
nal
static int FUNC() nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
Definition: cbs_lcevc_syntax_template.c:655
extract_tab
static const struct @73 extract_tab[]
AV_CODEC_ID_CAVS
@ AV_CODEC_ID_CAVS
Definition: codec_id.h:139
AV1OBU::raw_data
const uint8_t * raw_data
Definition: av1_parse.h:51
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
AV1_METADATA_TYPE_HDR_CLL
@ AV1_METADATA_TYPE_HDR_CLL
Definition: av1.h:44
ff_av1_packet_uninit
void ff_av1_packet_uninit(AV1Packet *pkt)
Free all the allocated memory in the packet.
Definition: av1_parse.c:104
AV_CODEC_ID_VC1
@ AV_CODEC_ID_VC1
Definition: codec_id.h:122
len
int len
Definition: vorbis_enc_data.h:426
extract_extradata_av1
static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:95
ret
ret
Definition: filter_design.txt:187
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:81
av_malloc
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:98
VVC_PPS_NUT
@ VVC_PPS_NUT
Definition: vvc.h:45
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
H264_NAL_SPS
@ H264_NAL_SPS
Definition: h264.h:41
ExtractExtradataContext
Definition: extract_extradata.c:39
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
lcevc.h
AV1OBU::type
int type
Definition: av1_parse.h:53
LCEVC_NON_IDR_NUT
@ LCEVC_NON_IDR_NUT
Definition: lcevc.h:60
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
bytestream2_put_bufferu
static av_always_inline unsigned int bytestream2_put_bufferu(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:301
AVPacket
This structure stores compressed data.
Definition: packet.h:565
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
bytestream.h
h264.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
metadata_is_global
static int metadata_is_global(const AV1OBU *obu)
Definition: extract_extradata.c:63
ff_bsf_get_packet_ref
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition: bsf.c:256
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ff_h2645_packet_split
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int nal_length_size, enum AVCodecID codec_id, int flags)
Split an input packet into NAL units.
Definition: h2645_parse.c:527
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
H2645Packet
Definition: h2645_parse.h:82
get_mb
static uint64_t get_mb(GetBitContext *s)
Definition: extract_extradata.c:271
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1291
AV1_OBU_METADATA
@ AV1_OBU_METADATA
Definition: av1.h:34