FFmpeg
avidec.c
Go to the documentation of this file.
1 /*
2  * AVI demuxer
3  * Copyright (c) 2001 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config_components.h"
23 
24 #include <inttypes.h>
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/avstring.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/mathematics.h"
33 #include "avformat.h"
34 #include "avi.h"
35 #include "demux.h"
36 #include "dv.h"
37 #include "internal.h"
38 #include "isom.h"
39 #include "riff.h"
40 #include "libavcodec/bytestream.h"
41 #include "libavcodec/exif.h"
42 #include "libavcodec/startcode.h"
43 
44 typedef struct AVIStream {
45  int64_t frame_offset; /* current frame (video) or byte (audio) counter
46  * (used to compute the pts) */
47  int remaining;
49 
50  uint32_t handler;
51  uint32_t scale;
52  uint32_t rate;
53  int sample_size; /* size of one sample (or packet)
54  * (in the rate/scale sense) in bytes */
55 
56  int64_t cum_len; /* temporary storage (used during seek) */
57  int prefix; /* normally 'd'<<8 + 'c' or 'w'<<8 + 'b' */
59  uint32_t pal[256];
60  int has_pal;
61  int dshow_block_align; /* block align variable used to emulate bugs in
62  * the MS dshow demuxer */
63 
67 
68  int64_t seek_pos;
69 } AVIStream;
70 
71 typedef struct AVIContext {
72  const AVClass *class;
73  int64_t riff_end;
74  int64_t movi_end;
75  int64_t fsize;
76  int64_t io_fsize;
77  int64_t movi_list;
78  int64_t last_pkt_pos;
80  int is_odml;
85  int use_odml;
86 #define MAX_ODML_DEPTH 1000
87  int64_t dts_max;
88 } AVIContext;
89 
90 
91 static const AVOption options[] = {
92  { "use_odml", "use odml index", offsetof(AVIContext, use_odml), AV_OPT_TYPE_BOOL, {.i64 = 1}, -1, 1, AV_OPT_FLAG_DECODING_PARAM},
93  { NULL },
94 };
95 
96 static const AVClass demuxer_class = {
97  .class_name = "avi",
98  .item_name = av_default_item_name,
99  .option = options,
100  .version = LIBAVUTIL_VERSION_INT,
101  .category = AV_CLASS_CATEGORY_DEMUXER,
102 };
103 
104 
105 static const char avi_headers[][8] = {
106  { 'R', 'I', 'F', 'F', 'A', 'V', 'I', ' ' },
107  { 'R', 'I', 'F', 'F', 'A', 'V', 'I', 'X' },
108  { 'R', 'I', 'F', 'F', 'A', 'V', 'I', 0x19 },
109  { 'O', 'N', '2', ' ', 'O', 'N', '2', 'f' },
110  { 'R', 'I', 'F', 'F', 'A', 'M', 'V', ' ' },
111  { 0 }
112 };
113 
115  { "strn", "title" },
116  { "isbj", "subject" },
117  { "inam", "title" },
118  { "iart", "artist" },
119  { "icop", "copyright" },
120  { "icmt", "comment" },
121  { "ignr", "genre" },
122  { "iprd", "product" },
123  { "isft", "software" },
124 
125  { 0 },
126 };
127 
128 static int avi_load_index(AVFormatContext *s);
129 static int guess_ni_flag(AVFormatContext *s);
130 
131 #define print_tag(s, str, tag, size) \
132  av_log(s, AV_LOG_TRACE, "pos:%"PRIX64" %s: tag=%s size=0x%x\n", \
133  avio_tell(pb), str, av_fourcc2str(tag), size) \
134 
135 static inline int get_duration(AVIStream *ast, int len)
136 {
137  if (ast->sample_size)
138  return len;
139  else if (ast->dshow_block_align)
140  return (len + (int64_t)ast->dshow_block_align - 1) / ast->dshow_block_align;
141  else
142  return 1;
143 }
144 
146 {
147  AVIContext *avi = s->priv_data;
148  char header[8] = {0};
149  int i;
150 
151  /* check RIFF header */
152  avio_read(pb, header, 4);
153  avi->riff_end = avio_rl32(pb); /* RIFF chunk size */
154  avi->riff_end += avio_tell(pb); /* RIFF chunk end */
155  avio_read(pb, header + 4, 4);
156 
157  for (i = 0; avi_headers[i][0]; i++)
158  if (!memcmp(header, avi_headers[i], 8))
159  break;
160  if (!avi_headers[i][0])
161  return AVERROR_INVALIDDATA;
162 
163  if (header[7] == 0x19)
165  "This file has been generated by a totally broken muxer.\n");
166 
167  return 0;
168 }
169 
170 static int read_odml_index(AVFormatContext *s, int64_t frame_num)
171 {
172  AVIContext *avi = s->priv_data;
173  AVIOContext *pb = s->pb;
174  int longs_per_entry = avio_rl16(pb);
175  int index_sub_type = avio_r8(pb);
176  int index_type = avio_r8(pb);
177  int entries_in_use = avio_rl32(pb);
178  int chunk_id = avio_rl32(pb);
179  int64_t base = avio_rl64(pb);
180  int stream_id = ((chunk_id & 0xFF) - '0') * 10 +
181  ((chunk_id >> 8 & 0xFF) - '0');
182  AVStream *st;
183  AVIStream *ast;
184  int i;
185  int64_t last_pos = -1;
186  int64_t filesize = avi->fsize;
187 
189  "longs_per_entry:%d index_type:%d entries_in_use:%d "
190  "chunk_id:%X base:%16"PRIX64" frame_num:%"PRId64"\n",
191  longs_per_entry,
192  index_type,
193  entries_in_use,
194  chunk_id,
195  base,
196  frame_num);
197 
198  if (stream_id >= s->nb_streams || stream_id < 0)
199  return AVERROR_INVALIDDATA;
200  st = s->streams[stream_id];
201  ast = st->priv_data;
202 
203  if (index_sub_type)
204  return AVERROR_INVALIDDATA;
205 
206  avio_rl32(pb);
207 
208  if (index_type && longs_per_entry != 2)
209  return AVERROR_INVALIDDATA;
210  if (index_type > 1)
211  return AVERROR_INVALIDDATA;
212 
213  if (filesize > 0 && base >= filesize) {
214  av_log(s, AV_LOG_ERROR, "ODML index invalid\n");
215  if (base >> 32 == (base & 0xFFFFFFFF) &&
216  (base & 0xFFFFFFFF) < filesize &&
217  filesize <= 0xFFFFFFFF)
218  base &= 0xFFFFFFFF;
219  else
220  return AVERROR_INVALIDDATA;
221  }
222 
223  for (i = 0; i < entries_in_use; i++) {
224  if (index_type) {
225  int64_t pos = avio_rl32(pb) + base - 8;
226  int len = avio_rl32(pb);
227  int key = len >= 0;
228  len &= 0x7FFFFFFF;
229 
230  av_log(s, AV_LOG_TRACE, "pos:%"PRId64", len:%X\n", pos, len);
231 
232  if (avio_feof(pb))
233  return AVERROR_INVALIDDATA;
234 
235  if (last_pos == pos || pos == base - 8)
236  avi->non_interleaved = 1;
237  if (last_pos != pos && len)
238  av_add_index_entry(st, pos, ast->cum_len, len, 0,
239  key ? AVINDEX_KEYFRAME : 0);
240 
241  ast->cum_len += get_duration(ast, len);
242  last_pos = pos;
243  } else {
244  int64_t offset, pos;
245  int duration;
246  int ret;
247 
248  offset = avio_rl64(pb);
249  avio_rl32(pb); /* size */
250  duration = avio_rl32(pb);
251 
252  if (avio_feof(pb) || offset > INT64_MAX - 8)
253  return AVERROR_INVALIDDATA;
254 
255  pos = avio_tell(pb);
256 
257  if (avi->odml_depth > MAX_ODML_DEPTH) {
258  av_log(s, AV_LOG_ERROR, "Too deeply nested ODML indexes\n");
259  return AVERROR_INVALIDDATA;
260  }
261 
262  if (avio_seek(pb, offset + 8, SEEK_SET) < 0)
263  return -1;
264  avi->odml_depth++;
265  ret = read_odml_index(s, frame_num);
266  avi->odml_depth--;
267  frame_num += duration;
268 
269  if (avio_seek(pb, pos, SEEK_SET) < 0) {
270  av_log(s, AV_LOG_ERROR, "Failed to restore position after reading index\n");
271  return -1;
272  }
273  if (ret < 0)
274  return ret;
275  }
276  }
277  avi->index_loaded = 2;
278  return 0;
279 }
280 
282 {
283  int i;
284  int64_t j;
285 
286  for (i = 0; i < s->nb_streams; i++) {
287  AVStream *st = s->streams[i];
288  FFStream *const sti = ffstream(st);
289  AVIStream *ast = st->priv_data;
290  int n = sti->nb_index_entries;
291  int max = ast->sample_size;
292  int64_t pos, size, ts;
293 
294  if (n != 1 || ast->sample_size == 0)
295  continue;
296 
297  while (max < 1024)
298  max += max;
299 
300  pos = sti->index_entries[0].pos;
301  size = sti->index_entries[0].size;
302  ts = sti->index_entries[0].timestamp;
303 
304  for (j = 0; j < size; j += max)
305  av_add_index_entry(st, pos + j, ts + j, FFMIN(max, size - j), 0,
307  }
308 }
309 
310 static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag,
311  uint32_t size)
312 {
313  AVIOContext *pb = s->pb;
314  char key[5] = { 0 };
315  char *value;
316 
317  size += (size & 1);
318 
319  if (size == UINT_MAX)
320  return AVERROR(EINVAL);
321  value = av_malloc(size + 1);
322  if (!value)
323  return AVERROR(ENOMEM);
324  if (avio_read(pb, value, size) != size) {
325  av_freep(&value);
326  return AVERROR_INVALIDDATA;
327  }
328  value[size] = 0;
329 
330  AV_WL32(key, tag);
331 
332  return av_dict_set(st ? &st->metadata : &s->metadata, key, value,
334 }
335 
336 static const char months[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
337  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
338 
339 static void avi_metadata_creation_time(AVDictionary **metadata, char *date)
340 {
341  char month[4], time[9], buffer[64];
342  int i, day, year;
343  /* parse standard AVI date format (ie. "Mon Mar 10 15:04:43 2003") */
344  if (sscanf(date, "%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d",
345  month, &day, time, &year) == 4) {
346  for (i = 0; i < 12; i++)
347  if (!av_strcasecmp(month, months[i])) {
348  snprintf(buffer, sizeof(buffer), "%.4d-%.2d-%.2d %s",
349  year, i + 1, day, time);
350  av_dict_set(metadata, "creation_time", buffer, 0);
351  }
352  } else if (date[4] == '/' && date[7] == '/') {
353  date[4] = date[7] = '-';
354  av_dict_set(metadata, "creation_time", date, 0);
355  }
356 }
357 
358 static void avi_read_nikon(AVFormatContext *s, uint64_t end)
359 {
360  while (avio_tell(s->pb) < end && !avio_feof(s->pb)) {
361  uint32_t tag = avio_rl32(s->pb);
362  uint32_t size = avio_rl32(s->pb);
363  switch (tag) {
364  case MKTAG('n', 'c', 't', 'g'): /* Nikon Tags */
365  {
366  uint64_t tag_end = avio_tell(s->pb) + size;
367  while (avio_tell(s->pb) < tag_end && !avio_feof(s->pb)) {
368  uint16_t tag = avio_rl16(s->pb);
369  uint16_t size = avio_rl16(s->pb);
370  const char *name = NULL;
371  char buffer[64] = { 0 };
372  uint64_t remaining = tag_end - avio_tell(s->pb);
373  size = FFMIN(size, remaining);
374  size -= avio_read(s->pb, buffer,
375  FFMIN(size, sizeof(buffer) - 1));
376  switch (tag) {
377  case 0x03:
378  name = "maker";
379  break;
380  case 0x04:
381  name = "model";
382  break;
383  case 0x13:
384  name = "creation_time";
385  if (buffer[4] == ':' && buffer[7] == ':')
386  buffer[4] = buffer[7] = '-';
387  break;
388  }
389  if (name)
390  av_dict_set(&s->metadata, name, buffer, 0);
391  avio_skip(s->pb, size);
392  }
393  break;
394  }
395  default:
396  avio_skip(s->pb, size);
397  break;
398  }
399  }
400 }
401 
403 {
404  GetByteContext gb;
405  uint8_t *data = st->codecpar->extradata;
406  int data_size = st->codecpar->extradata_size;
407  int tag, offset;
408 
409  if (!data || data_size < 8) {
410  return AVERROR_INVALIDDATA;
411  }
412 
413  bytestream2_init(&gb, data, data_size);
414 
415  tag = bytestream2_get_le32(&gb);
416 
417  switch (tag) {
418  case MKTAG('A', 'V', 'I', 'F'):
419  // skip 4 byte padding
420  bytestream2_skip(&gb, 4);
421  offset = bytestream2_tell(&gb);
422 
423  // decode EXIF tags from IFD, AVI is always little-endian
424  return avpriv_exif_decode_ifd(s, data + offset, data_size - offset,
425  1, 0, &st->metadata);
426  break;
427  case MKTAG('C', 'A', 'S', 'I'):
428  avpriv_request_sample(s, "RIFF stream data tag type CASI (%u)", tag);
429  break;
430  case MKTAG('Z', 'o', 'r', 'a'):
431  avpriv_request_sample(s, "RIFF stream data tag type Zora (%u)", tag);
432  break;
433  default:
434  break;
435  }
436 
437  return 0;
438 }
439 
441 {
442  AVIContext *avi = s->priv_data;
443  int i, j;
444  int64_t lensum = 0;
445  int64_t maxpos = 0;
446 
447  for (i = 0; i<s->nb_streams; i++) {
448  int64_t len = 0;
449  FFStream *const sti = ffstream(s->streams[i]);
450 
451  if (!sti->nb_index_entries)
452  continue;
453 
454  for (j = 0; j < sti->nb_index_entries; j++)
455  len += sti->index_entries[j].size;
456  maxpos = FFMAX(maxpos, sti->index_entries[j-1].pos);
457  lensum += len;
458  }
459  if (maxpos < av_rescale(avi->io_fsize, 9, 10)) // index does not cover the whole file
460  return 0;
461  if (lensum*9/10 > maxpos || lensum < maxpos*9/10) // frame sum and filesize mismatch
462  return 0;
463 
464  for (i = 0; i<s->nb_streams; i++) {
465  int64_t len = 0;
466  AVStream *st = s->streams[i];
467  FFStream *const sti = ffstream(st);
468  int64_t duration;
469  int64_t bitrate;
470 
471  for (j = 0; j < sti->nb_index_entries; j++)
472  len += sti->index_entries[j].size;
473 
474  if (sti->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
475  continue;
478  if (bitrate > 0) {
479  st->codecpar->bit_rate = bitrate;
480  }
481  }
482  return 1;
483 }
484 
486 {
487  AVIContext *avi = s->priv_data;
488  AVIOContext *pb = s->pb;
489  unsigned int tag, tag1, handler;
490  int codec_type, stream_index, frame_period;
491  unsigned int size;
492  int i;
493  AVStream *st;
494  AVIStream *ast = NULL;
495  int avih_width = 0, avih_height = 0;
496  int amv_file_format = 0;
497  uint64_t list_end = 0;
498  int64_t pos;
499  int ret;
500  AVDictionaryEntry *dict_entry;
501 
502  avi->stream_index = -1;
503 
504  ret = get_riff(s, pb);
505  if (ret < 0)
506  return ret;
507 
508  av_log(avi, AV_LOG_DEBUG, "use odml:%d\n", avi->use_odml);
509 
510  avi->io_fsize = avi->fsize = avio_size(pb);
511  if (avi->fsize <= 0 || avi->fsize < avi->riff_end)
512  avi->fsize = avi->riff_end == 8 ? INT64_MAX : avi->riff_end;
513 
514  /* first list tag */
515  stream_index = -1;
516  codec_type = -1;
517  frame_period = 0;
518  for (;;) {
519  if (avio_feof(pb))
520  return AVERROR_INVALIDDATA;
521  tag = avio_rl32(pb);
522  size = avio_rl32(pb);
523 
524  print_tag(s, "tag", tag, size);
525 
526  switch (tag) {
527  case MKTAG('L', 'I', 'S', 'T'):
528  list_end = avio_tell(pb) + size;
529  /* Ignored, except at start of video packets. */
530  tag1 = avio_rl32(pb);
531 
532  print_tag(s, "list", tag1, 0);
533 
534  if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
535  avi->movi_list = avio_tell(pb) - 4;
536  if (size)
537  avi->movi_end = avi->movi_list + size + (size & 1);
538  else
539  avi->movi_end = avi->fsize;
540  av_log(s, AV_LOG_TRACE, "movi end=%"PRIx64"\n", avi->movi_end);
541  goto end_of_header;
542  } else if (tag1 == MKTAG('I', 'N', 'F', 'O'))
543  ff_read_riff_info(s, size - 4);
544  else if (tag1 == MKTAG('n', 'c', 'd', 't'))
545  avi_read_nikon(s, list_end);
546 
547  break;
548  case MKTAG('I', 'D', 'I', 'T'):
549  {
550  unsigned char date[64] = { 0 };
551  size += (size & 1);
552  size -= avio_read(pb, date, FFMIN(size, sizeof(date) - 1));
553  avio_skip(pb, size);
554  avi_metadata_creation_time(&s->metadata, date);
555  break;
556  }
557  case MKTAG('d', 'm', 'l', 'h'):
558  avi->is_odml = 1;
559  avio_skip(pb, size + (size & 1));
560  break;
561  case MKTAG('a', 'm', 'v', 'h'):
562  amv_file_format = 1;
563  case MKTAG('a', 'v', 'i', 'h'):
564  /* AVI header */
565  /* using frame_period is bad idea */
566  frame_period = avio_rl32(pb);
567  avio_rl32(pb); /* max. bytes per second */
568  avio_rl32(pb);
570 
571  avio_skip(pb, 2 * 4);
572  avio_rl32(pb);
573  avio_rl32(pb);
574  avih_width = avio_rl32(pb);
575  avih_height = avio_rl32(pb);
576 
577  avio_skip(pb, size - 10 * 4);
578  break;
579  case MKTAG('s', 't', 'r', 'h'):
580  /* stream header */
581 
582  tag1 = avio_rl32(pb);
583  handler = avio_rl32(pb); /* codec tag */
584 
585  if (tag1 == MKTAG('p', 'a', 'd', 's')) {
586  avio_skip(pb, size - 8);
587  break;
588  } else {
589  stream_index++;
590  st = avformat_new_stream(s, NULL);
591  if (!st)
592  return AVERROR(ENOMEM);
593 
594  st->id = stream_index;
595  ast = av_mallocz(sizeof(AVIStream));
596  if (!ast)
597  return AVERROR(ENOMEM);
598  st->priv_data = ast;
599  }
600  if (amv_file_format)
601  tag1 = stream_index ? MKTAG('a', 'u', 'd', 's')
602  : MKTAG('v', 'i', 'd', 's');
603 
604  print_tag(s, "strh", tag1, -1);
605 
606  if (tag1 == MKTAG('i', 'a', 'v', 's') ||
607  tag1 == MKTAG('i', 'v', 'a', 's')) {
608  int64_t dv_dur;
609 
610  /* After some consideration -- I don't think we
611  * have to support anything but DV in type1 AVIs. */
612  if (s->nb_streams != 1)
613  return AVERROR_INVALIDDATA;
614 
615  if (handler != MKTAG('d', 'v', 's', 'd') &&
616  handler != MKTAG('d', 'v', 'h', 'd') &&
617  handler != MKTAG('d', 'v', 's', 'l'))
618  return AVERROR_INVALIDDATA;
619 
620  if (!CONFIG_DV_DEMUXER)
622 
623  ast = s->streams[0]->priv_data;
624  st->priv_data = NULL;
625  ff_remove_stream(s, st);
626 
628  if (!avi->dv_demux) {
629  av_free(ast);
630  return AVERROR(ENOMEM);
631  }
632 
633  s->streams[0]->priv_data = ast;
634  avio_skip(pb, 3 * 4);
635  ast->scale = avio_rl32(pb);
636  ast->rate = avio_rl32(pb);
637  avio_skip(pb, 4); /* start time */
638 
639  dv_dur = avio_rl32(pb);
640  if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) {
641  dv_dur *= AV_TIME_BASE;
642  s->duration = av_rescale(dv_dur, ast->scale, ast->rate);
643  }
644  /* else, leave duration alone; timing estimation in utils.c
645  * will make a guess based on bitrate. */
646 
647  stream_index = s->nb_streams - 1;
648  avio_skip(pb, size - 9 * 4);
649  break;
650  }
651 
652  av_assert0(stream_index < s->nb_streams);
653  ast->handler = handler;
654 
655  avio_rl32(pb); /* flags */
656  avio_rl16(pb); /* priority */
657  avio_rl16(pb); /* language */
658  avio_rl32(pb); /* initial frame */
659  ast->scale = avio_rl32(pb);
660  ast->rate = avio_rl32(pb);
661  if (!(ast->scale && ast->rate)) {
663  "scale/rate is %"PRIu32"/%"PRIu32" which is invalid. "
664  "(This file has been generated by broken software.)\n",
665  ast->scale,
666  ast->rate);
667  if (frame_period) {
668  ast->rate = 1000000;
669  ast->scale = frame_period;
670  } else {
671  ast->rate = 25;
672  ast->scale = 1;
673  }
674  }
675  avpriv_set_pts_info(st, 64, ast->scale, ast->rate);
676 
677  ast->cum_len = avio_rl32(pb); /* start */
678  st->nb_frames = avio_rl32(pb);
679 
680  st->start_time = 0;
681  avio_rl32(pb); /* buffer size */
682  avio_rl32(pb); /* quality */
683  if (ast->cum_len > 3600LL * ast->rate / ast->scale) {
684  av_log(s, AV_LOG_ERROR, "crazy start time, iam scared, giving up\n");
685  ast->cum_len = 0;
686  }
687  ast->sample_size = avio_rl32(pb);
688  ast->cum_len *= FFMAX(1, ast->sample_size);
689  av_log(s, AV_LOG_TRACE, "%"PRIu32" %"PRIu32" %d\n",
690  ast->rate, ast->scale, ast->sample_size);
691 
692  switch (tag1) {
693  case MKTAG('v', 'i', 'd', 's'):
695 
696  ast->sample_size = 0;
697  st->avg_frame_rate = av_inv_q(st->time_base);
698  break;
699  case MKTAG('a', 'u', 'd', 's'):
701  break;
702  case MKTAG('t', 'x', 't', 's'):
704  break;
705  case MKTAG('d', 'a', 't', 's'):
707  break;
708  default:
709  av_log(s, AV_LOG_INFO, "unknown stream type %X\n", tag1);
710  }
711 
712  if (ast->sample_size < 0) {
713  if (s->error_recognition & AV_EF_EXPLODE) {
715  "Invalid sample_size %d at stream %d\n",
716  ast->sample_size,
717  stream_index);
718  return AVERROR_INVALIDDATA;
719  }
721  "Invalid sample_size %d at stream %d "
722  "setting it to 0\n",
723  ast->sample_size,
724  stream_index);
725  ast->sample_size = 0;
726  }
727 
728  if (ast->sample_size == 0) {
729  st->duration = st->nb_frames;
730  if (st->duration > 0 && avi->io_fsize > 0 && avi->riff_end > avi->io_fsize) {
731  av_log(s, AV_LOG_DEBUG, "File is truncated adjusting duration\n");
732  st->duration = av_rescale(st->duration, avi->io_fsize, avi->riff_end);
733  }
734  }
735  ast->frame_offset = ast->cum_len;
736  avio_skip(pb, size - 12 * 4);
737  break;
738  case MKTAG('s', 't', 'r', 'f'):
739  /* stream header */
740  if (!size && (codec_type == AVMEDIA_TYPE_AUDIO ||
742  break;
743  if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {
744  avio_skip(pb, size);
745  } else {
746  uint64_t cur_pos = avio_tell(pb);
747  FFStream *sti;
748  unsigned esize;
749  if (cur_pos < list_end)
750  size = FFMIN(size, list_end - cur_pos);
751  st = s->streams[stream_index];
752  sti = ffstream(st);
754  avio_skip(pb, size);
755  break;
756  }
757  switch (codec_type) {
758  case AVMEDIA_TYPE_VIDEO:
759  if (amv_file_format) {
760  st->codecpar->width = avih_width;
761  st->codecpar->height = avih_height;
764  avio_skip(pb, size);
765  break;
766  }
767  tag1 = ff_get_bmp_header(pb, st, &esize);
768 
769  if (tag1 == MKTAG('D', 'X', 'S', 'B') ||
770  tag1 == MKTAG('D', 'X', 'S', 'A')) {
772  st->codecpar->codec_tag = tag1;
774  break;
775  }
776 
777  if (size > 10 * 4 && size < (1 << 30) && size < avi->fsize) {
778  if (esize == size-1 && (esize&1)) {
779  st->codecpar->extradata_size = esize - 10 * 4;
780  } else
781  st->codecpar->extradata_size = size - 10 * 4;
782  if (st->codecpar->extradata) {
783  av_log(s, AV_LOG_WARNING, "New extradata in strf chunk, freeing previous one.\n");
784  }
785  ret = ff_get_extradata(s, st->codecpar, pb,
786  st->codecpar->extradata_size);
787  if (ret < 0)
788  return ret;
789  }
790 
791  // FIXME: check if the encoder really did this correctly
792  if (st->codecpar->extradata_size & 1)
793  avio_r8(pb);
794 
795  /* Extract palette from extradata if bpp <= 8.
796  * This code assumes that extradata contains only palette.
797  * This is true for all paletted codecs implemented in
798  * FFmpeg. */
799  if (st->codecpar->extradata_size &&
800  (st->codecpar->bits_per_coded_sample <= 8)) {
801  int pal_size = (1 << st->codecpar->bits_per_coded_sample) << 2;
802  const uint8_t *pal_src;
803 
804  pal_size = FFMIN(pal_size, st->codecpar->extradata_size);
805  pal_src = st->codecpar->extradata +
806  st->codecpar->extradata_size - pal_size;
807  /* Exclude the "BottomUp" field from the palette */
808  if (pal_src - st->codecpar->extradata >= 9 &&
809  !memcmp(st->codecpar->extradata + st->codecpar->extradata_size - 9, "BottomUp", 9))
810  pal_src -= 9;
811  for (i = 0; i < pal_size / 4; i++)
812  ast->pal[i] = 0xFFU<<24 | AV_RL32(pal_src + 4 * i);
813  ast->has_pal = 1;
814  }
815 
816  print_tag(s, "video", tag1, 0);
817 
819  st->codecpar->codec_tag = tag1;
821  tag1);
822  /* If codec is not found yet, try with the mov tags. */
823  if (!st->codecpar->codec_id) {
824  st->codecpar->codec_id =
826  if (st->codecpar->codec_id)
828  "mov tag found in avi (fourcc %s)\n",
829  av_fourcc2str(tag1));
830  }
831  if (!st->codecpar->codec_id)
833 
834  /* This is needed to get the pict type which is necessary
835  * for generating correct pts. */
837 
838  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 &&
839  ast->handler == MKTAG('X', 'V', 'I', 'D'))
840  st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D');
841 
842  if (st->codecpar->codec_tag == MKTAG('V', 'S', 'S', 'H'))
844  if (st->codecpar->codec_id == AV_CODEC_ID_RV40)
846  if (st->codecpar->codec_id == AV_CODEC_ID_HEVC &&
847  st->codecpar->codec_tag == MKTAG('H', '2', '6', '5'))
849 
850  if (st->codecpar->codec_id == AV_CODEC_ID_AVRN &&
851  st->codecpar->codec_tag == MKTAG('A', 'V', 'R', 'n') &&
852  (st->codecpar->extradata_size < 31 ||
853  memcmp(&st->codecpar->extradata[28], "1:1", 3)))
855 
856  if (st->codecpar->codec_tag == 0 && st->codecpar->height > 0 &&
857  st->codecpar->extradata_size < 1U << 30) {
858  st->codecpar->extradata_size += 9;
859  if ((ret = av_reallocp(&st->codecpar->extradata,
860  st->codecpar->extradata_size +
862  st->codecpar->extradata_size = 0;
863  return ret;
864  } else
865  memcpy(st->codecpar->extradata + st->codecpar->extradata_size - 9,
866  "BottomUp", 9);
867  }
868  if (st->codecpar->height == INT_MIN)
869  return AVERROR_INVALIDDATA;
870  st->codecpar->height = FFABS(st->codecpar->height);
871 
872 // avio_skip(pb, size - 5 * 4);
873  break;
874  case AVMEDIA_TYPE_AUDIO:
875  ret = ff_get_wav_header(s, pb, st->codecpar, size, 0);
876  if (ret < 0)
877  return ret;
879  if (ast->sample_size && st->codecpar->block_align &&
880  ast->sample_size != st->codecpar->block_align) {
881  av_log(s,
883  "sample size (%d) != block align (%d)\n",
884  ast->sample_size,
885  st->codecpar->block_align);
886  ast->sample_size = st->codecpar->block_align;
887  }
888  /* 2-aligned
889  * (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
890  if (size & 1)
891  avio_skip(pb, 1);
892  /* Force parsing as several audio frames can be in
893  * one packet and timestamps refer to packet start. */
895  /* ADTS header is in extradata, AAC without header must be
896  * stored as exact frames. Parser not needed and it will
897  * fail. */
898  if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
901  // The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS
902  if (st->codecpar->codec_id == AV_CODEC_ID_FLAC)
904  /* AVI files with Xan DPCM audio (wrongly) declare PCM
905  * audio in the header but have Axan as stream_code_tag. */
906  if (ast->handler == AV_RL32("Axan")) {
908  st->codecpar->codec_tag = 0;
909  ast->dshow_block_align = 0;
910  }
911  if (amv_file_format) {
913  ast->dshow_block_align = 0;
914  }
915  if ((st->codecpar->codec_id == AV_CODEC_ID_AAC ||
917  st->codecpar->codec_id == AV_CODEC_ID_MP2 ) && ast->dshow_block_align <= 4 && ast->dshow_block_align) {
918  av_log(s, AV_LOG_DEBUG, "overriding invalid dshow_block_align of %d\n", ast->dshow_block_align);
919  ast->dshow_block_align = 0;
920  }
921  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 1024 && ast->sample_size == 1024 ||
922  st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 4096 && ast->sample_size == 4096 ||
923  st->codecpar->codec_id == AV_CODEC_ID_MP3 && ast->dshow_block_align == 1152 && ast->sample_size == 1152) {
924  av_log(s, AV_LOG_DEBUG, "overriding sample_size\n");
925  ast->sample_size = 0;
926  }
927  break;
930  sti->request_probe = 1;
931  avio_skip(pb, size);
932  break;
933  default:
936  st->codecpar->codec_tag = 0;
937  avio_skip(pb, size);
938  break;
939  }
940  }
941  break;
942  case MKTAG('s', 't', 'r', 'd'):
943  if (stream_index >= (unsigned)s->nb_streams
944  || s->streams[stream_index]->codecpar->extradata_size
945  || s->streams[stream_index]->codecpar->codec_tag == MKTAG('H','2','6','4')) {
946  avio_skip(pb, size);
947  } else {
948  uint64_t cur_pos = avio_tell(pb);
949  if (cur_pos < list_end)
950  size = FFMIN(size, list_end - cur_pos);
951  st = s->streams[stream_index];
952 
953  if (size<(1<<30)) {
954  if (st->codecpar->extradata) {
955  av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n");
956  }
957  if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0)
958  return ret;
959  }
960 
961  if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly
962  avio_r8(pb);
963 
965  if (ret < 0) {
966  av_log(s, AV_LOG_WARNING, "could not decoding EXIF data in stream header.\n");
967  }
968  }
969  break;
970  case MKTAG('i', 'n', 'd', 'x'):
971  pos = avio_tell(pb);
972  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !(s->flags & AVFMT_FLAG_IGNIDX) &&
973  avi->use_odml &&
974  read_odml_index(s, 0) < 0 &&
975  (s->error_recognition & AV_EF_EXPLODE))
976  return AVERROR_INVALIDDATA;
977  avio_seek(pb, pos + size, SEEK_SET);
978  break;
979  case MKTAG('v', 'p', 'r', 'p'):
980  if (stream_index < (unsigned)s->nb_streams && size > 9 * 4) {
981  AVRational active, active_aspect;
982 
983  st = s->streams[stream_index];
984  avio_rl32(pb);
985  avio_rl32(pb);
986  avio_rl32(pb);
987  avio_rl32(pb);
988  avio_rl32(pb);
989 
990  active_aspect.den = avio_rl16(pb);
991  active_aspect.num = avio_rl16(pb);
992  active.num = avio_rl32(pb);
993  active.den = avio_rl32(pb);
994  avio_rl32(pb); // nbFieldsPerFrame
995 
996  if (active_aspect.num && active_aspect.den &&
997  active.num && active.den) {
998  st->sample_aspect_ratio = av_div_q(active_aspect, active);
999  av_log(s, AV_LOG_TRACE, "vprp %d/%d %d/%d\n",
1000  active_aspect.num, active_aspect.den,
1001  active.num, active.den);
1002  }
1003  size -= 9 * 4;
1004  }
1005  avio_skip(pb, size);
1006  break;
1007  case MKTAG('s', 't', 'r', 'n'):
1008  case MKTAG('i', 's', 'b', 'j'):
1009  case MKTAG('i', 'n', 'a', 'm'):
1010  case MKTAG('i', 'a', 'r', 't'):
1011  case MKTAG('i', 'c', 'o', 'p'):
1012  case MKTAG('i', 'c', 'm', 't'):
1013  case MKTAG('i', 'g', 'n', 'r'):
1014  case MKTAG('i', 'p', 'o', 'd'):
1015  case MKTAG('i', 's', 'o', 'f'):
1016  if (s->nb_streams) {
1017  ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
1018  if (ret < 0)
1019  return ret;
1020  break;
1021  }
1022  default:
1023  if (size > 1000000) {
1025  "Something went wrong during header parsing, "
1026  "tag %s has size %u, "
1027  "I will ignore it and try to continue anyway.\n",
1028  av_fourcc2str(tag), size);
1029  if (s->error_recognition & AV_EF_EXPLODE)
1030  return AVERROR_INVALIDDATA;
1031  avi->movi_list = avio_tell(pb) - 4;
1032  avi->movi_end = avi->fsize;
1033  goto end_of_header;
1034  }
1035  /* Do not fail for very large idx1 tags */
1036  case MKTAG('i', 'd', 'x', '1'):
1037  /* skip tag */
1038  size += (size & 1);
1039  avio_skip(pb, size);
1040  break;
1041  }
1042  }
1043 
1044 end_of_header:
1045  /* check stream number */
1046  if (stream_index != s->nb_streams - 1)
1047  return AVERROR_INVALIDDATA;
1048 
1049  if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))
1050  avi_load_index(s);
1052  avi->index_loaded |= 1;
1053 
1054  if ((ret = guess_ni_flag(s)) < 0)
1055  return ret;
1056 
1057  avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS);
1058 
1059  dict_entry = av_dict_get(s->metadata, "ISFT", NULL, 0);
1060  if (dict_entry && !strcmp(dict_entry->value, "PotEncoder"))
1061  for (i = 0; i < s->nb_streams; i++) {
1062  AVStream *st = s->streams[i];
1066  }
1067 
1068  for (i = 0; i < s->nb_streams; i++) {
1069  AVStream *st = s->streams[i];
1070  if (ffstream(st)->nb_index_entries)
1071  break;
1072  }
1073  // DV-in-AVI cannot be non-interleaved, if set this must be
1074  // a mis-detection.
1075  if (avi->dv_demux)
1076  avi->non_interleaved = 0;
1077  if (i == s->nb_streams && avi->non_interleaved) {
1079  "Non-interleaved AVI without index, switching to interleaved\n");
1080  avi->non_interleaved = 0;
1081  }
1082 
1083  if (avi->non_interleaved) {
1084  av_log(s, AV_LOG_INFO, "non-interleaved AVI\n");
1085  clean_index(s);
1086  }
1087 
1090 
1091  return 0;
1092 }
1093 
1095 {
1096  if (pkt->size >= 7 &&
1097  pkt->size < INT_MAX - AVPROBE_PADDING_SIZE &&
1098  !strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data + 5) == 2) {
1099  uint8_t desc[256];
1100  int score = AVPROBE_SCORE_EXTENSION, ret;
1101  AVIStream *ast = st->priv_data;
1102  const AVInputFormat *sub_demuxer;
1103  AVRational time_base;
1104  int size;
1105  AVProbeData pd;
1106  unsigned int desc_len;
1108  pkt->size - 7,
1109  0, NULL, NULL, NULL, NULL);
1110  if (!pb)
1111  goto error;
1112 
1113  desc_len = avio_rl32(pb);
1114 
1115  if (desc_len > pb->buf_end - pb->buf_ptr)
1116  goto error;
1117 
1118  ret = avio_get_str16le(pb, desc_len, desc, sizeof(desc));
1119  avio_skip(pb, desc_len - ret);
1120  if (*desc)
1121  av_dict_set(&st->metadata, "title", desc, 0);
1122 
1123  avio_rl16(pb); /* flags? */
1124  avio_rl32(pb); /* data size */
1125 
1126  size = pb->buf_end - pb->buf_ptr;
1128  .buf_size = size };
1129  if (!pd.buf)
1130  goto error;
1131  memcpy(pd.buf, pb->buf_ptr, size);
1132  sub_demuxer = av_probe_input_format2(&pd, 1, &score);
1133  av_freep(&pd.buf);
1134  if (!sub_demuxer)
1135  goto error;
1136 
1137  if (strcmp(sub_demuxer->name, "srt") && strcmp(sub_demuxer->name, "ass"))
1138  goto error;
1139 
1140  if (!(ast->sub_pkt = av_packet_alloc()))
1141  goto error;
1142 
1143  if (!(ast->sub_ctx = avformat_alloc_context()))
1144  goto error;
1145 
1146  ast->sub_ctx->pb = pb;
1147 
1148  if (ff_copy_whiteblacklists(ast->sub_ctx, s) < 0)
1149  goto error;
1150 
1151  if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) {
1152  if (ast->sub_ctx->nb_streams != 1)
1153  goto error;
1154  ff_read_packet(ast->sub_ctx, ast->sub_pkt);
1156  time_base = ast->sub_ctx->streams[0]->time_base;
1157  avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
1158  }
1159  ast->sub_buffer = pkt->buf;
1160  pkt->buf = NULL;
1162  return 1;
1163 
1164 error:
1165  av_packet_free(&ast->sub_pkt);
1166  av_freep(&ast->sub_ctx);
1167  avio_context_free(&pb);
1168  }
1169  return 0;
1170 }
1171 
1173  AVPacket *pkt)
1174 {
1175  AVIStream *ast, *next_ast = next_st->priv_data;
1176  int64_t ts, next_ts, ts_min = INT64_MAX;
1177  AVStream *st, *sub_st = NULL;
1178  int i;
1179 
1180  next_ts = av_rescale_q(next_ast->frame_offset, next_st->time_base,
1181  AV_TIME_BASE_Q);
1182 
1183  for (i = 0; i < s->nb_streams; i++) {
1184  st = s->streams[i];
1185  ast = st->priv_data;
1186  if (st->discard < AVDISCARD_ALL && ast && ast->sub_pkt && ast->sub_pkt->data) {
1187  ts = av_rescale_q(ast->sub_pkt->dts, st->time_base, AV_TIME_BASE_Q);
1188  if (ts <= next_ts && ts < ts_min) {
1189  ts_min = ts;
1190  sub_st = st;
1191  }
1192  }
1193  }
1194 
1195  if (sub_st) {
1196  ast = sub_st->priv_data;
1198  pkt->stream_index = sub_st->index;
1199 
1200  if (ff_read_packet(ast->sub_ctx, ast->sub_pkt) < 0)
1201  ast->sub_pkt->data = NULL;
1202  }
1203  return sub_st;
1204 }
1205 
1206 static int get_stream_idx(const unsigned *d)
1207 {
1208  if (d[0] >= '0' && d[0] <= '9' &&
1209  d[1] >= '0' && d[1] <= '9') {
1210  return (d[0] - '0') * 10 + (d[1] - '0');
1211  } else {
1212  return 100; // invalid stream ID
1213  }
1214 }
1215 
1216 /**
1217  *
1218  * @param exit_early set to 1 to just gather packet position without making the changes needed to actually read & return the packet
1219  */
1220 static int avi_sync(AVFormatContext *s, int exit_early)
1221 {
1222  AVIContext *avi = s->priv_data;
1223  AVIOContext *pb = s->pb;
1224  int n;
1225  unsigned int d[8];
1226  unsigned int size;
1227  int64_t i, sync;
1228 
1229 start_sync:
1230  memset(d, -1, sizeof(d));
1231  for (i = sync = avio_tell(pb); !avio_feof(pb); i++) {
1232  int j;
1233 
1234  for (j = 0; j < 7; j++)
1235  d[j] = d[j + 1];
1236  d[7] = avio_r8(pb);
1237 
1238  size = d[4] + (d[5] << 8) + (d[6] << 16) + (d[7] << 24);
1239 
1240  n = get_stream_idx(d + 2);
1241  ff_tlog(s, "%X %X %X %X %X %X %X %X %"PRId64" %u %d\n",
1242  d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
1243  if (i*(avi->io_fsize>0) + (uint64_t)size > avi->fsize || d[0] > 127)
1244  continue;
1245 
1246  // parse ix##
1247  if ((d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) ||
1248  // parse JUNK
1249  (d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') ||
1250  (d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1') ||
1251  (d[0] == 'i' && d[1] == 'n' && d[2] == 'd' && d[3] == 'x')) {
1252  avio_skip(pb, size);
1253  goto start_sync;
1254  }
1255 
1256  // parse stray LIST
1257  if (d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T') {
1258  avio_skip(pb, 4);
1259  goto start_sync;
1260  }
1261 
1262  n = get_stream_idx(d);
1263 
1264  if (!((i - avi->last_pkt_pos) & 1) &&
1265  get_stream_idx(d + 1) < s->nb_streams)
1266  continue;
1267 
1268  // detect ##ix chunk and skip
1269  if (d[2] == 'i' && d[3] == 'x' && n < s->nb_streams) {
1270  avio_skip(pb, size);
1271  goto start_sync;
1272  }
1273 
1274  if (d[2] == 'w' && d[3] == 'c' && n < s->nb_streams) {
1275  avio_skip(pb, 16 * 3 + 8);
1276  goto start_sync;
1277  }
1278 
1279  if (avi->dv_demux && n != 0)
1280  continue;
1281 
1282  // parse ##dc/##wb
1283  if (n < s->nb_streams) {
1284  AVStream *st;
1285  AVIStream *ast;
1286  st = s->streams[n];
1287  ast = st->priv_data;
1288 
1289  if (!ast) {
1290  av_log(s, AV_LOG_WARNING, "Skipping foreign stream %d packet\n", n);
1291  continue;
1292  }
1293 
1294  if (s->nb_streams >= 2) {
1295  AVStream *st1 = s->streams[1];
1296  AVIStream *ast1 = st1->priv_data;
1297  // workaround for broken small-file-bug402.avi
1298  if (ast1 && d[2] == 'w' && d[3] == 'b'
1299  && n == 0
1300  && st ->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
1302  && ast->prefix == 'd'*256+'c'
1303  && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count)
1304  ) {
1305  n = 1;
1306  st = st1;
1307  ast = ast1;
1309  "Invalid stream + prefix combination, assuming audio.\n");
1310  }
1311  }
1312 
1313  if (d[2] == 'p' && d[3] == 'c' && size <= 4 * 256 + 4) {
1314  int k = avio_r8(pb);
1315  int last = (k + avio_r8(pb) - 1) & 0xFF;
1316 
1317  avio_rl16(pb); // flags
1318 
1319  // b + (g << 8) + (r << 16);
1320  for (; k <= last; k++)
1321  ast->pal[k] = 0xFFU<<24 | avio_rb32(pb)>>8;
1322 
1323  ast->has_pal = 1;
1324  goto start_sync;
1325  } else if (((ast->prefix_count < 5 || sync + 9 > i) &&
1326  d[2] < 128 && d[3] < 128) ||
1327  d[2] * 256 + d[3] == ast->prefix /* ||
1328  (d[2] == 'd' && d[3] == 'c') ||
1329  (d[2] == 'w' && d[3] == 'b') */) {
1330  if (exit_early)
1331  return 0;
1332  if (d[2] * 256 + d[3] == ast->prefix)
1333  ast->prefix_count++;
1334  else {
1335  ast->prefix = d[2] * 256 + d[3];
1336  ast->prefix_count = 0;
1337  }
1338 
1339  if (!avi->dv_demux &&
1340  ((st->discard >= AVDISCARD_DEFAULT && size == 0) /* ||
1341  // FIXME: needs a little reordering
1342  (st->discard >= AVDISCARD_NONKEY &&
1343  !(pkt->flags & AV_PKT_FLAG_KEY)) */
1344  || st->discard >= AVDISCARD_ALL)) {
1345 
1346  ast->frame_offset += get_duration(ast, size);
1347  avio_skip(pb, size);
1348  goto start_sync;
1349  }
1350 
1351  avi->stream_index = n;
1352  ast->packet_size = size + 8;
1353  ast->remaining = size;
1354 
1355  if (size) {
1356  FFStream *const sti = ffstream(st);
1357  uint64_t pos = avio_tell(pb) - 8;
1358  if (!sti->index_entries || !sti->nb_index_entries ||
1359  sti->index_entries[sti->nb_index_entries - 1].pos < pos) {
1361  0, AVINDEX_KEYFRAME);
1362  }
1363  }
1364  return 0;
1365  }
1366  }
1367  }
1368 
1369  if (pb->error)
1370  return pb->error;
1371  return AVERROR_EOF;
1372 }
1373 
1375 {
1376  AVIContext *avi = s->priv_data;
1377  int best_stream_index = 0;
1378  AVStream *best_st = NULL;
1379  FFStream *best_sti;
1380  AVIStream *best_ast;
1381  int64_t best_ts = INT64_MAX;
1382  int i;
1383 
1384  for (i = 0; i < s->nb_streams; i++) {
1385  AVStream *st = s->streams[i];
1386  FFStream *const sti = ffstream(st);
1387  AVIStream *ast = st->priv_data;
1388  int64_t ts = ast->frame_offset;
1389  int64_t last_ts;
1390 
1391  if (!sti->nb_index_entries)
1392  continue;
1393 
1394  last_ts = sti->index_entries[sti->nb_index_entries - 1].timestamp;
1395  if (!ast->remaining && ts > last_ts)
1396  continue;
1397 
1398  ts = av_rescale_q(ts, st->time_base,
1399  (AVRational) { FFMAX(1, ast->sample_size),
1400  AV_TIME_BASE });
1401 
1402  av_log(s, AV_LOG_TRACE, "%"PRId64" %d/%d %"PRId64"\n", ts,
1403  st->time_base.num, st->time_base.den, ast->frame_offset);
1404  if (ts < best_ts) {
1405  best_ts = ts;
1406  best_st = st;
1407  best_stream_index = i;
1408  }
1409  }
1410  if (!best_st)
1411  return AVERROR_EOF;
1412 
1413  best_sti = ffstream(best_st);
1414  best_ast = best_st->priv_data;
1415  best_ts = best_ast->frame_offset;
1416  if (best_ast->remaining) {
1417  i = av_index_search_timestamp(best_st,
1418  best_ts,
1419  AVSEEK_FLAG_ANY |
1421  } else {
1422  i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
1423  if (i >= 0)
1424  best_ast->frame_offset = best_sti->index_entries[i].timestamp;
1425  }
1426 
1427  if (i >= 0) {
1428  int64_t pos = best_sti->index_entries[i].pos;
1429  pos += best_ast->packet_size - best_ast->remaining;
1430  if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
1431  return AVERROR_EOF;
1432 
1433  av_assert0(best_ast->remaining <= best_ast->packet_size);
1434 
1435  avi->stream_index = best_stream_index;
1436  if (!best_ast->remaining)
1437  best_ast->packet_size =
1438  best_ast->remaining = best_sti->index_entries[i].size;
1439  }
1440  else
1441  return AVERROR_EOF;
1442 
1443  return 0;
1444 }
1445 
1447 {
1448  AVIContext *avi = s->priv_data;
1449  AVIOContext *pb = s->pb;
1450  int err;
1451 
1452  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1453  int size = avpriv_dv_get_packet(avi->dv_demux, pkt);
1454  if (size >= 0)
1455  return size;
1456  else
1457  goto resync;
1458  }
1459 
1460  if (avi->non_interleaved) {
1461  err = ni_prepare_read(s);
1462  if (err < 0)
1463  return err;
1464  }
1465 
1466 resync:
1467  if (avi->stream_index >= 0) {
1468  AVStream *st = s->streams[avi->stream_index];
1469  FFStream *const sti = ffstream(st);
1470  AVIStream *ast = st->priv_data;
1471  int dv_demux = CONFIG_DV_DEMUXER && avi->dv_demux;
1472  int size, err;
1473 
1474  if (get_subtitle_pkt(s, st, pkt))
1475  return 0;
1476 
1477  // minorityreport.AVI block_align=1024 sample_size=1 IMA-ADPCM
1478  if (ast->sample_size <= 1)
1479  size = INT_MAX;
1480  else if (ast->sample_size < 32)
1481  // arbitrary multiplier to avoid tiny packets for raw PCM data
1482  size = 1024 * ast->sample_size;
1483  else
1484  size = ast->sample_size;
1485 
1486  if (size > ast->remaining)
1487  size = ast->remaining;
1488  avi->last_pkt_pos = avio_tell(pb);
1489  err = av_get_packet(pb, pkt, size);
1490  if (err < 0)
1491  return err;
1492  size = err;
1493 
1494  if (ast->has_pal && pkt->size < (unsigned)INT_MAX / 2 && !dv_demux) {
1495  uint8_t *pal;
1498  AVPALETTE_SIZE);
1499  if (!pal) {
1501  "Failed to allocate data for palette\n");
1502  } else {
1503  memcpy(pal, ast->pal, AVPALETTE_SIZE);
1504  ast->has_pal = 0;
1505  }
1506  }
1507 
1508  if (CONFIG_DV_DEMUXER && dv_demux) {
1510  pkt->data, pkt->size, pkt->pos);
1512  if (size < 0)
1514  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
1515  !st->codecpar->codec_tag && read_gab2_sub(s, st, pkt)) {
1516  ast->frame_offset++;
1517  avi->stream_index = -1;
1518  ast->remaining = 0;
1519  goto resync;
1520  } else {
1521  /* XXX: How to handle B-frames in AVI? */
1522  pkt->dts = ast->frame_offset;
1523 // pkt->dts += ast->start;
1524  if (ast->sample_size)
1525  pkt->dts /= ast->sample_size;
1526  pkt->stream_index = avi->stream_index;
1527 
1528  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->index_entries) {
1529  AVIndexEntry *e;
1530  int index;
1531 
1533  e = &sti->index_entries[index];
1534 
1535  if (index >= 0 && e->timestamp == ast->frame_offset) {
1536  if (index == sti->nb_index_entries-1) {
1537  int key=1;
1538  uint32_t state=-1;
1539  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1540  const uint8_t *ptr = pkt->data, *end = ptr + FFMIN(size, 256);
1541  while (ptr < end) {
1542  ptr = avpriv_find_start_code(ptr, end, &state);
1543  if (state == 0x1B6 && ptr < end) {
1544  key = !(*ptr & 0xC0);
1545  break;
1546  }
1547  }
1548  }
1549  if (!key)
1550  e->flags &= ~AVINDEX_KEYFRAME;
1551  }
1552  if (e->flags & AVINDEX_KEYFRAME)
1554  }
1555  } else {
1557  }
1558  ast->frame_offset += get_duration(ast, pkt->size);
1559  }
1560  ast->remaining -= err;
1561  if (!ast->remaining) {
1562  avi->stream_index = -1;
1563  ast->packet_size = 0;
1564  }
1565 
1566  if (!avi->non_interleaved && pkt->pos >= 0 && ast->seek_pos > pkt->pos) {
1568  goto resync;
1569  }
1570  ast->seek_pos= 0;
1571 
1572  if (!avi->non_interleaved && sti->nb_index_entries > 1 && avi->index_loaded > 1) {
1573  int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q);
1574 
1575  if (avi->dts_max < dts) {
1576  avi->dts_max = dts;
1577  } else if (avi->dts_max - (uint64_t)dts > 2*AV_TIME_BASE) {
1578  avi->non_interleaved= 1;
1579  av_log(s, AV_LOG_INFO, "Switching to NI mode, due to poor interleaving\n");
1580  }
1581  }
1582 
1583  return 0;
1584  }
1585 
1586  if ((err = avi_sync(s, 0)) < 0)
1587  return err;
1588  goto resync;
1589 }
1590 
1591 /* XXX: We make the implicit supposition that the positions are sorted
1592  * for each stream. */
1594 {
1595  AVIContext *avi = s->priv_data;
1596  AVIOContext *pb = s->pb;
1597  int nb_index_entries, i;
1598  AVStream *st;
1599  AVIStream *ast;
1600  int64_t pos;
1601  unsigned int index, tag, flags, len, first_packet = 1;
1602  int64_t last_pos = -1;
1603  unsigned last_idx = -1;
1604  int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1605  int anykey = 0;
1606 
1607  nb_index_entries = size / 16;
1608  if (nb_index_entries <= 0)
1609  return AVERROR_INVALIDDATA;
1610 
1611  idx1_pos = avio_tell(pb);
1612  avio_seek(pb, avi->movi_list + 4, SEEK_SET);
1613  if (avi_sync(s, 1) == 0)
1614  first_packet_pos = avio_tell(pb) - 8;
1615  avi->stream_index = -1;
1616  avio_seek(pb, idx1_pos, SEEK_SET);
1617 
1618  if (s->nb_streams == 1 && s->streams[0]->codecpar->codec_tag == AV_RL32("MMES")) {
1619  first_packet_pos = 0;
1620  data_offset = avi->movi_list;
1621  }
1622 
1623  /* Read the entries and sort them in each stream component. */
1624  for (i = 0; i < nb_index_entries; i++) {
1625  if (avio_feof(pb))
1626  return -1;
1627 
1628  tag = avio_rl32(pb);
1629  flags = avio_rl32(pb);
1630  pos = avio_rl32(pb);
1631  len = avio_rl32(pb);
1632  av_log(s, AV_LOG_TRACE, "%d: tag=0x%x flags=0x%x pos=0x%"PRIx64" len=%d/",
1633  i, tag, flags, pos, len);
1634 
1635  index = ((tag & 0xff) - '0') * 10;
1636  index += (tag >> 8 & 0xff) - '0';
1637  if (index >= s->nb_streams)
1638  continue;
1639  st = s->streams[index];
1640  ast = st->priv_data;
1641 
1642  /* Skip 'xxpc' palette change entries in the index until a logic
1643  * to process these is properly implemented. */
1644  if ((tag >> 16 & 0xff) == 'p' && (tag >> 24 & 0xff) == 'c')
1645  continue;
1646 
1647  if (first_packet && first_packet_pos) {
1648  if (avi->movi_list + 4 != pos || pos + 500 > first_packet_pos)
1649  data_offset = first_packet_pos - pos;
1650  first_packet = 0;
1651  }
1652  pos += data_offset;
1653 
1654  av_log(s, AV_LOG_TRACE, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
1655 
1656  // even if we have only a single stream, we should
1657  // switch to non-interleaved to get correct timestamps
1658  if (last_pos == pos)
1659  avi->non_interleaved = 1;
1660  if (last_idx != pos && len) {
1661  av_add_index_entry(st, pos, ast->cum_len, len, 0,
1662  (flags & AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);
1663  last_idx= pos;
1664  }
1665  ast->cum_len += get_duration(ast, len);
1666  last_pos = pos;
1667  anykey |= flags&AVIIF_INDEX;
1668  }
1669  if (!anykey) {
1670  for (index = 0; index < s->nb_streams; index++) {
1671  FFStream *const sti = ffstream(s->streams[index]);
1672  if (sti->nb_index_entries)
1674  }
1675  }
1676  return 0;
1677 }
1678 
1679 /* Scan the index and consider any file with streams more than
1680  * 2 seconds or 64MB apart non-interleaved. */
1682 {
1683  int64_t min_pos, pos;
1684  int i;
1685  int *idx = av_calloc(s->nb_streams, sizeof(*idx));
1686  if (!idx)
1687  return AVERROR(ENOMEM);
1688  for (min_pos = pos = 0; min_pos != INT64_MAX; pos = min_pos + 1LU) {
1689  int64_t max_dts = INT64_MIN / 2;
1690  int64_t min_dts = INT64_MAX / 2;
1691  int64_t max_buffer = 0;
1692 
1693  min_pos = INT64_MAX;
1694 
1695  for (i = 0; i < s->nb_streams; i++) {
1696  AVStream *st = s->streams[i];
1697  AVIStream *ast = st->priv_data;
1698  FFStream *const sti = ffstream(st);
1699  int n = sti->nb_index_entries;
1700  while (idx[i] < n && sti->index_entries[idx[i]].pos < pos)
1701  idx[i]++;
1702  if (idx[i] < n) {
1703  int64_t dts;
1704  dts = av_rescale_q(sti->index_entries[idx[i]].timestamp /
1705  FFMAX(ast->sample_size, 1),
1706  st->time_base, AV_TIME_BASE_Q);
1707  min_dts = FFMIN(min_dts, dts);
1708  min_pos = FFMIN(min_pos, sti->index_entries[idx[i]].pos);
1709  }
1710  }
1711  for (i = 0; i < s->nb_streams; i++) {
1712  AVStream *st = s->streams[i];
1713  FFStream *const sti = ffstream(st);
1714  AVIStream *ast = st->priv_data;
1715 
1716  if (idx[i] && min_dts != INT64_MAX / 2) {
1717  int64_t dts, delta_dts;
1718  dts = av_rescale_q(sti->index_entries[idx[i] - 1].timestamp /
1719  FFMAX(ast->sample_size, 1),
1720  st->time_base, AV_TIME_BASE_Q);
1721  delta_dts = av_sat_sub64(dts, min_dts);
1722  max_dts = FFMAX(max_dts, dts);
1723  max_buffer = FFMAX(max_buffer,
1724  av_rescale(delta_dts,
1725  st->codecpar->bit_rate,
1726  AV_TIME_BASE));
1727  }
1728  }
1729  if (av_sat_sub64(max_dts, min_dts) > 2 * AV_TIME_BASE ||
1730  max_buffer > 1024 * 1024 * 8 * 8) {
1731  av_free(idx);
1732  return 1;
1733  }
1734  }
1735  av_free(idx);
1736  return 0;
1737 }
1738 
1740 {
1741  int i;
1742  int64_t last_start = 0;
1743  int64_t first_end = INT64_MAX;
1744  int64_t oldpos = avio_tell(s->pb);
1745 
1746  for (i = 0; i < s->nb_streams; i++) {
1747  AVStream *st = s->streams[i];
1748  FFStream *const sti = ffstream(st);
1749  int n = sti->nb_index_entries;
1750  unsigned int size;
1751 
1752  if (n <= 0)
1753  continue;
1754 
1755  if (n >= 2) {
1756  int64_t pos = sti->index_entries[0].pos;
1757  unsigned tag[2];
1758  avio_seek(s->pb, pos, SEEK_SET);
1759  tag[0] = avio_r8(s->pb);
1760  tag[1] = avio_r8(s->pb);
1761  avio_rl16(s->pb);
1762  size = avio_rl32(s->pb);
1763  if (get_stream_idx(tag) == i && pos + size > sti->index_entries[1].pos)
1764  last_start = INT64_MAX;
1765  if (get_stream_idx(tag) == i && size == sti->index_entries[0].size + 8)
1766  last_start = INT64_MAX;
1767  }
1768 
1769  if (sti->index_entries[0].pos > last_start)
1770  last_start = sti->index_entries[0].pos;
1771  if (sti->index_entries[n - 1].pos < first_end)
1772  first_end = sti->index_entries[n - 1].pos;
1773  }
1774  avio_seek(s->pb, oldpos, SEEK_SET);
1775 
1776  if (last_start > first_end)
1777  return 1;
1778 
1779  return check_stream_max_drift(s);
1780 }
1781 
1783 {
1784  AVIContext *avi = s->priv_data;
1785  AVIOContext *pb = s->pb;
1786  uint32_t tag, size;
1787  int64_t pos = avio_tell(pb);
1788  int64_t next;
1789  int ret = -1;
1790 
1791  if (avio_seek(pb, avi->movi_end, SEEK_SET) < 0)
1792  goto the_end; // maybe truncated file
1793  av_log(s, AV_LOG_TRACE, "movi_end=0x%"PRIx64"\n", avi->movi_end);
1794  for (;;) {
1795  tag = avio_rl32(pb);
1796  size = avio_rl32(pb);
1797  if (avio_feof(pb))
1798  break;
1799  next = avio_tell(pb);
1800  if (next < 0 || next > INT64_MAX - size - (size & 1))
1801  break;
1802  next += size + (size & 1LL);
1803 
1804  if (tag == MKTAG('i', 'd', 'x', '1') &&
1805  avi_read_idx1(s, size) >= 0) {
1806  avi->index_loaded=2;
1807  ret = 0;
1808  }else if (tag == MKTAG('L', 'I', 'S', 'T')) {
1809  uint32_t tag1 = avio_rl32(pb);
1810 
1811  if (tag1 == MKTAG('I', 'N', 'F', 'O'))
1812  ff_read_riff_info(s, size - 4);
1813  }else if (!ret)
1814  break;
1815 
1816  if (avio_seek(pb, next, SEEK_SET) < 0)
1817  break; // something is wrong here
1818  }
1819 
1820 the_end:
1821  avio_seek(pb, pos, SEEK_SET);
1822  return ret;
1823 }
1824 
1825 static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
1826 {
1827  AVIStream *ast2 = st2->priv_data;
1828  int64_t ts2 = av_rescale_q(timestamp, st->time_base, st2->time_base);
1829  av_packet_unref(ast2->sub_pkt);
1830  if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 ||
1831  avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
1832  ff_read_packet(ast2->sub_ctx, ast2->sub_pkt);
1833 }
1834 
1835 static int avi_read_seek(AVFormatContext *s, int stream_index,
1836  int64_t timestamp, int flags)
1837 {
1838  AVIContext *avi = s->priv_data;
1839  AVStream *st;
1840  FFStream *sti;
1841  int i, index;
1842  int64_t pos, pos_min;
1843  AVIStream *ast;
1844 
1845  /* Does not matter which stream is requested dv in avi has the
1846  * stream information in the first video stream.
1847  */
1848  if (avi->dv_demux)
1849  stream_index = 0;
1850 
1851  if (!avi->index_loaded) {
1852  /* we only load the index on demand */
1853  avi_load_index(s);
1854  avi->index_loaded |= 1;
1855  }
1856  av_assert0(stream_index >= 0);
1857 
1858  st = s->streams[stream_index];
1859  sti = ffstream(st);
1860  ast = st->priv_data;
1862  timestamp * FFMAX(ast->sample_size, 1),
1863  flags);
1864  if (index < 0) {
1865  if (sti->nb_index_entries > 0)
1866  av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n",
1867  timestamp * FFMAX(ast->sample_size, 1),
1868  sti->index_entries[0].timestamp,
1869  sti->index_entries[sti->nb_index_entries - 1].timestamp);
1870  return AVERROR_INVALIDDATA;
1871  }
1872 
1873  /* find the position */
1874  pos = sti->index_entries[index].pos;
1875  timestamp = sti->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
1876 
1877  av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n",
1878  timestamp, index, sti->index_entries[index].timestamp);
1879 
1880  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1881  /* One and only one real stream for DV in AVI, and it has video */
1882  /* offsets. Calling with other stream indexes should have failed */
1883  /* the av_index_search_timestamp call above. */
1884 
1885  if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1886  return -1;
1887 
1888  /* Feed the DV video stream version of the timestamp to the */
1889  /* DV demux so it can synthesize correct timestamps. */
1890  ff_dv_offset_reset(avi->dv_demux, timestamp);
1891 
1892  avi->stream_index = -1;
1893  return 0;
1894  }
1895 
1896  pos_min = pos;
1897  for (i = 0; i < s->nb_streams; i++) {
1898  AVStream *st2 = s->streams[i];
1899  FFStream *const sti2 = ffstream(st2);
1900  AVIStream *ast2 = st2->priv_data;
1901 
1902  ast2->packet_size =
1903  ast2->remaining = 0;
1904 
1905  if (ast2->sub_ctx) {
1906  seek_subtitle(st, st2, timestamp);
1907  continue;
1908  }
1909 
1910  if (sti2->nb_index_entries <= 0)
1911  continue;
1912 
1913 // av_assert1(st2->codecpar->block_align);
1915  av_rescale_q(timestamp,
1916  st->time_base,
1917  st2->time_base) *
1918  FFMAX(ast2->sample_size, 1),
1919  flags |
1922  if (index < 0)
1923  index = 0;
1924  ast2->seek_pos = sti2->index_entries[index].pos;
1925  pos_min = FFMIN(pos_min,ast2->seek_pos);
1926  }
1927  for (i = 0; i < s->nb_streams; i++) {
1928  AVStream *st2 = s->streams[i];
1929  FFStream *const sti2 = ffstream(st2);
1930  AVIStream *ast2 = st2->priv_data;
1931 
1932  if (ast2->sub_ctx || sti2->nb_index_entries <= 0)
1933  continue;
1934 
1936  st2,
1937  av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
1939  if (index < 0)
1940  index = 0;
1941  while (!avi->non_interleaved && index > 0 && sti2->index_entries[index-1].pos >= pos_min)
1942  index--;
1943  ast2->frame_offset = sti2->index_entries[index].timestamp;
1944  }
1945 
1946  /* do the seek */
1947  if (avio_seek(s->pb, pos_min, SEEK_SET) < 0) {
1948  av_log(s, AV_LOG_ERROR, "Seek failed\n");
1949  return -1;
1950  }
1951  avi->stream_index = -1;
1952  avi->dts_max = INT_MIN;
1953  return 0;
1954 }
1955 
1957 {
1958  int i;
1959  AVIContext *avi = s->priv_data;
1960 
1961  for (i = 0; i < s->nb_streams; i++) {
1962  AVStream *st = s->streams[i];
1963  AVIStream *ast = st->priv_data;
1964  if (ast) {
1965  if (ast->sub_ctx) {
1966  av_freep(&ast->sub_ctx->pb);
1968  }
1969  av_buffer_unref(&ast->sub_buffer);
1970  av_packet_free(&ast->sub_pkt);
1971  }
1972  }
1973 
1974  av_freep(&avi->dv_demux);
1975 
1976  return 0;
1977 }
1978 
1979 static int avi_probe(const AVProbeData *p)
1980 {
1981  int i;
1982 
1983  /* check file header */
1984  for (i = 0; avi_headers[i][0]; i++)
1985  if (AV_RL32(p->buf ) == AV_RL32(avi_headers[i] ) &&
1986  AV_RL32(p->buf + 8) == AV_RL32(avi_headers[i] + 4))
1987  return AVPROBE_SCORE_MAX;
1988 
1989  return 0;
1990 }
1991 
1993  .name = "avi",
1994  .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
1995  .priv_data_size = sizeof(AVIContext),
1996  .flags_internal = FF_FMT_INIT_CLEANUP,
1997  .extensions = "avi",
1998  .read_probe = avi_probe,
2003  .priv_class = &demuxer_class,
2004 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:422
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:75
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
FF_FMT_INIT_CLEANUP
#define FF_FMT_INIT_CLEANUP
For an AVInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition: internal.h:48
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
opt.h
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: options.c:237
options
static const AVOption options[]
Definition: avidec.c:91
ni_prepare_read
static int ni_prepare_read(AVFormatContext *s)
Definition: avidec.c:1374
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:57
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
AVIStream::sub_ctx
AVFormatContext * sub_ctx
Definition: avidec.c:64
avi_read_idx1
static int avi_read_idx1(AVFormatContext *s, int size)
Definition: avidec.c:1593
GetByteContext
Definition: bytestream.h:33
demuxer_class
static const AVClass demuxer_class
Definition: avidec.c:96
AVFMT_FLAG_IGNIDX
#define AVFMT_FLAG_IGNIDX
Ignore index.
Definition: avformat.h:1333
AVStream::priv_data
void * priv_data
Definition: avformat.h:964
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:1010
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
avio_context_free
void avio_context_free(AVIOContext **s)
Free the supplied IO context and everything associated with it.
Definition: aviobuf.c:152
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
AVIStream
Definition: avidec.c:44
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:218
AVIContext::is_odml
int is_odml
Definition: avidec.c:80
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:62
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1281
MAX_ODML_DEPTH
#define MAX_ODML_DEPTH
Definition: avidec.c:86
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVOption
AVOption.
Definition: opt.h:251
avi_read_close
static int avi_read_close(AVFormatContext *s)
Definition: avidec.c:1956
AV_PKT_DATA_PALETTE
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition: packet.h:47
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:1028
data
const char data[16]
Definition: mxf.c:146
AVIOContext::error
int error
contains the error code or 0 if no error happened
Definition: avio.h:241
AVMetadataConv
Definition: metadata.h:34
base
uint8_t base
Definition: vp3data.h:141
avi_read_nikon
static void avi_read_nikon(AVFormatContext *s, uint64_t end)
Definition: avidec.c:358
ff_codec_bmp_tags_unofficial
const AVCodecTag ff_codec_bmp_tags_unofficial[]
Definition: riff.c:505
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:65
max
#define max(a, b)
Definition: cuda_runtime.h:33
mathematics.h
AVDictionary
Definition: dict.c:30
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: codec_id.h:441
avi_metadata_creation_time
static void avi_metadata_creation_time(AVDictionary **metadata, char *date)
Definition: avidec.c:339
avpriv_exif_decode_ifd
int avpriv_exif_decode_ifd(void *logctx, const uint8_t *buf, int size, int le, int depth, AVDictionary **metadata)
Recursively decodes all IFD's and adds included TAGS into the metadata dictionary.
Definition: exif.c:265
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
read_gab2_sub
static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition: avidec.c:1094
codec_type
enum AVMediaType codec_type
Definition: rtp.c:37
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:352
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:73
AVIndexEntry
Definition: avformat.h:807
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:815
AVIContext::riff_end
int64_t riff_end
Definition: avidec.c:73
ff_get_extradata
int ff_get_extradata(void *logctx, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
Definition: demux_utils.c:355
check_stream_max_drift
static int check_stream_max_drift(AVFormatContext *s)
Definition: avidec.c:1681
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:465
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: demux.c:368
AVIF_MUSTUSEINDEX
#define AVIF_MUSTUSEINDEX
Definition: avi.h:25
ff_remove_stream
void ff_remove_stream(AVFormatContext *s, AVStream *st)
Remove a stream from its AVFormatContext and free it.
Definition: avformat.c:76
avpriv_dv_produce_packet
int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, uint8_t *buf, int buf_size, int64_t pos)
Definition: dv.c:393
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:697
calculate_bitrate
static int calculate_bitrate(AVFormatContext *s)
Definition: avidec.c:440
ff_get_bmp_header
int ff_get_bmp_header(AVIOContext *pb, AVStream *st, uint32_t *size)
Read BITMAPINFOHEADER structure and set AVStream codec width, height and bits_per_encoded_sample fiel...
Definition: riffdec.c:216
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:407
AVIStream::has_pal
int has_pal
Definition: avidec.c:60
AVSEEK_FLAG_ANY
#define AVSEEK_FLAG_ANY
seek to any frame, even non-keyframes
Definition: avformat.h:2291
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:151
av_add_index_entry
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: seek.c:118
AV_CODEC_ID_XAN_DPCM
@ AV_CODEC_ID_XAN_DPCM
Definition: codec_id.h:422
clean_index
static void clean_index(AVFormatContext *s)
Definition: avidec.c:281
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:143
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:505
dv.h
avi_read_seek
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: avidec.c:1835
AVPROBE_PADDING_SIZE
#define AVPROBE_PADDING_SIZE
extra allocated bytes at the end of the probe buffer
Definition: avformat.h:467
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:430
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:998
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:743
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVIStream::handler
uint32_t handler
Definition: avidec.c:50
AV_DICT_DONT_STRDUP_VAL
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition: dict.h:72
seek_subtitle
static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
Definition: avidec.c:1825
AVIStream::pal
uint32_t pal[256]
Definition: avidec.c:59
avassert.h
avi_read_tag
static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag, uint32_t size)
Definition: avidec.c:310
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:790
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
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
AVInputFormat
Definition: avformat.h:656
duration
int64_t duration
Definition: movenc.c:64
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: demux.c:220
avi_sync
static int avi_sync(AVFormatContext *s, int exit_early)
Definition: avidec.c:1220
avio_get_str16le
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a UTF-16 string from pb and convert it to UTF-8.
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
AVIContext
Definition: avidec.c:71
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
print_tag
#define print_tag(s, str, tag, size)
Definition: avidec.c:131
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:661
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:455
AVIContext::movi_list
int64_t movi_list
Definition: avidec.c:77
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:127
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:429
AVIndexEntry::size
int size
Definition: avformat.h:818
AVIStream::dshow_block_align
int dshow_block_align
Definition: avidec.c:61
AVIndexEntry::timestamp
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
Definition: avformat.h:809
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVIContext::dts_max
int64_t dts_max
Definition: avidec.c:87
AVIStream::remaining
int remaining
Definition: avidec.c:47
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AVIStream::cum_len
int64_t cum_len
Definition: avidec.c:56
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
nb_streams
static int nb_streams
Definition: ffprobe.c:307
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
ff_read_riff_info
int ff_read_riff_info(AVFormatContext *s, int64_t size)
Definition: riffdec.c:235
key
const char * key
Definition: hwcontext_opencl.c:174
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
AVIStream::sub_pkt
AVPacket * sub_pkt
Definition: avidec.c:65
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:29
handler
static void handler(vbi_event *ev, void *user_data)
Definition: libzvbi-teletextdec.c:508
AV_CLASS_CATEGORY_DEMUXER
@ AV_CLASS_CATEGORY_DEMUXER
Definition: log.h:33
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:64
if
if(ret)
Definition: filter_design.txt:179
av_probe_input_format2
const AVInputFormat * av_probe_input_format2(const AVProbeData *pd, int is_opened, int *score_max)
Guess the file format.
Definition: format.c:209
AVERROR_DEMUXER_NOT_FOUND
#define AVERROR_DEMUXER_NOT_FOUND
Demuxer not found.
Definition: error.h:55
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:380
AV_CODEC_ID_AVRN
@ AV_CODEC_ID_AVRN
Definition: codec_id.h:259
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:54
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
internal.h
ff_metadata_conv_ctx
void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:59
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:357
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1108
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVSEEK_FLAG_BACKWARD
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2289
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:532
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
avpriv_dv_get_packet
int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
Definition: dv.c:369
AVIContext::movi_end
int64_t movi_end
Definition: avidec.c:74
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:978
NULL
#define NULL
Definition: coverity.c:32
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
read_probe
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
state
static struct @334 state
AVIIF_INDEX
#define AVIIF_INDEX
Definition: avi.h:38
isom.h
avi_metadata_conv
static const AVMetadataConv avi_metadata_conv[]
Definition: avidec.c:114
get_stream_idx
static int get_stream_idx(const unsigned *d)
Definition: avidec.c:1206
AVIContext::odml_depth
int odml_depth
Definition: avidec.c:84
AVIStream::sub_buffer
AVBufferRef * sub_buffer
Definition: avidec.c:66
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
get_riff
static int get_riff(AVFormatContext *s, AVIOContext *pb)
Definition: avidec.c:145
ff_copy_whiteblacklists
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition: avformat.c:741
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
AVSTREAM_PARSE_NONE
@ AVSTREAM_PARSE_NONE
Definition: avformat.h:797
AVIndexEntry::flags
int flags
Definition: avformat.h:817
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1255
avi_read_packet
static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: avidec.c:1446
FFStream::nb_index_entries
int nb_index_entries
Definition: internal.h:254
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:453
AVIStream::packet_size
int packet_size
Definition: avidec.c:48
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:1019
avpriv_find_start_code
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
AV_CODEC_ID_ADPCM_IMA_AMV
@ AV_CODEC_ID_ADPCM_IMA_AMV
Definition: codec_id.h:378
ff_codec_movvideo_tags
const AVCodecTag ff_codec_movvideo_tags[]
Definition: isom_tags.c:29
get_duration
static int get_duration(AVIStream *ast, int len)
Definition: avidec.c:135
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1364
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:479
guess_ni_flag
static int guess_ni_flag(AVFormatContext *s)
Definition: avidec.c:1739
AVIStream::prefix_count
int prefix_count
Definition: avidec.c:58
index
int index
Definition: gxfenc.c:89
AVPROBE_SCORE_EXTENSION
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:463
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:51
AVStream::nb_frames
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:1000
bytestream2_tell
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:192
avi.h
AVIStream::frame_offset
int64_t frame_offset
Definition: avidec.c:45
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:79
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1269
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:431
startcode.h
av_sat_sub64
#define av_sat_sub64
Definition: common.h:140
ff_dv_offset_reset
void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset)
Definition: dv.c:462
ff_avi_demuxer
const AVInputFormat ff_avi_demuxer
Definition: avidec.c:1992
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:759
AVIOContext
Bytestream IO Context.
Definition: avio.h:162
AVIContext::last_pkt_pos
int64_t last_pkt_pos
Definition: avidec.c:78
AVPacket::size
int size
Definition: packet.h:375
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:144
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:164
AVDISCARD_DEFAULT
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition: defs.h:49
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:263
AVIOContext::buf_end
unsigned char * buf_end
End of the data, may be less than buffer+buffer_size if the read function returned less data than req...
Definition: avio.h:230
FFStream
Definition: internal.h:197
months
static const char months[12][4]
Definition: avidec.c:336
size
int size
Definition: twinvq_data.h:10344
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:186
avformat_seek_file
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
Definition: seek.c:657
ff_riff_info_conv
const AVMetadataConv ff_riff_info_conv[]
Definition: riff.c:609
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
avi_probe
static int avi_probe(const AVProbeData *p)
Definition: avidec.c:1979
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:1017
header
static const uint8_t header[24]
Definition: sdr2.c:67
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:373
DVDemuxContext
Definition: dv.c:54
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:632
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:62
bitrate
int64_t bitrate
Definition: h264_levels.c:131
read_odml_index
static int read_odml_index(AVFormatContext *s, int64_t frame_num)
Definition: avidec.c:170
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
filesize
static int64_t filesize(AVIOContext *pb)
Definition: ffmpeg_mux.c:77
get_subtitle_pkt
static AVStream * get_subtitle_pkt(AVFormatContext *s, AVStream *next_st, AVPacket *pkt)
Definition: avidec.c:1172
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:74
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:57
avi_extract_stream_metadata
static int avi_extract_stream_metadata(AVFormatContext *s, AVStream *st)
Definition: avidec.c:402
AV_CODEC_ID_RV40
@ AV_CODEC_ID_RV40
Definition: codec_id.h:119
AVIContext::non_interleaved
int non_interleaved
Definition: avidec.c:81
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
ff_read_packet
int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
Read a transport packet from a media file.
Definition: demux.c:537
AVIContext::stream_index
int stream_index
Definition: avidec.c:82
internal.h
AVCodecParameters::height
int height
Definition: codec_par.h:128
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
resync
static int resync(AVFormatContext *s)
Definition: flvdec.c:972
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:184
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:224
AVIStream::sample_size
int sample_size
Definition: avidec.c:53
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:282
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
avio_alloc_context
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
Definition: aviobuf.c:135
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:264
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
demux.h
len
int len
Definition: vorbis_enc_data.h:426
exif.h
ff_get_wav_header
int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian)
Definition: riffdec.c:94
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
avi_load_index
static int avi_load_index(AVFormatContext *s)
Definition: avidec.c:1782
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:272
AVIStream::rate
uint32_t rate
Definition: avidec.c:52
av_get_packet
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:102
AVIStream::prefix
int prefix
Definition: avidec.c:57
AV_CODEC_ID_XSUB
@ AV_CODEC_ID_XSUB
Definition: codec_id.h:532
tag
uint32_t tag
Definition: movenc.c:1646
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:962
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:948
AVIContext::dv_demux
DVDemuxContext * dv_demux
Definition: avidec.c:83
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
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
AVFMT_FLAG_SORT_DTS
#define AVFMT_FLAG_SORT_DTS
try to interleave outputted packets by dts (using this flag can slow demuxing down)
Definition: avformat.h:1349
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:799
pos
unsigned int pos
Definition: spdifenc.c:412
avformat.h
dict.h
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
AVIStream::scale
uint32_t scale
Definition: avidec.c:51
U
#define U(x)
Definition: vpx_arith.h:37
AV_CODEC_ID_AMV
@ AV_CODEC_ID_AMV
Definition: codec_id.h:157
AVIStream::seek_pos
int64_t seek_pos
Definition: avidec.c:68
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:956
avpriv_dv_init_demux
DVDemuxContext * avpriv_dv_init_demux(AVFormatContext *s)
Definition: dv.c:353
ff_codec_bmp_tags
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:36
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition: avpacket.c:230
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVIContext::fsize
int64_t fsize
Definition: avidec.c:75
AVRational::den
int den
Denominator.
Definition: rational.h:60
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:641
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:808
AVPacket::stream_index
int stream_index
Definition: packet.h:376
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:347
AVIContext::io_fsize
int64_t io_fsize
Definition: avidec.c:76
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:252
AVIContext::use_odml
int use_odml
Definition: avidec.c:85
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:103
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVIContext::index_loaded
int index_loaded
Definition: avidec.c:79
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
avi_read_header
static int avi_read_header(AVFormatContext *s)
Definition: avidec.c:485
FFStream::request_probe
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
Definition: internal.h:266
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:79
ff_tlog
#define ff_tlog(ctx,...)
Definition: internal.h:207
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:61
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
riff.h
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:394
avio_rl64
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:767
d
d
Definition: ffmpeg_filter.c:155
bytestream.h
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:798
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:90
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
AVDictionaryEntry::value
char * value
Definition: dict.h:81
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:988
avstring.h
AVSTREAM_PARSE_TIMESTAMPS
@ AVSTREAM_PARSE_TIMESTAMPS
full parsing and interpolation of timestamps for frames not starting on a packet boundary
Definition: avformat.h:800
AVIOContext::buf_ptr
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:229
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:52
snprintf
#define snprintf
Definition: snprintf.h:34
avi_headers
static const char avi_headers[][8]
Definition: avidec.c:105
av_fourcc2str
#define av_fourcc2str(fourcc)
Definition: avutil.h:354
av_index_search_timestamp
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: seek.c:238
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:375