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