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 
71 } AVIStream;
72 
73 typedef struct AVIContext {
74  const AVClass *class;
82  int is_odml;
89  int use_odml;
90 #define MAX_ODML_DEPTH 1000
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 
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  AVExifMetadata ifd = { 0 };
432  int ret;
433  // skip 4 byte padding
434  bytestream2_skip(&gb, 4);
435  offset = bytestream2_tell(&gb);
436 
437  // decode EXIF tags from IFD, AVI is always little-endian
438  ret = av_exif_parse_buffer(s, data + offset, data_size - offset, &ifd, AV_EXIF_ASSUME_LE);
439  if (ret < 0)
440  return ret;
441  ret = av_exif_ifd_to_dict(s, &ifd, &st->metadata);
442  av_exif_free(&ifd);
443  return ret;
444  }
445  case MKTAG('C', 'A', 'S', 'I'):
446  avpriv_request_sample(s, "RIFF stream data tag type CASI (%u)", tag);
447  break;
448  case MKTAG('Z', 'o', 'r', 'a'):
449  avpriv_request_sample(s, "RIFF stream data tag type Zora (%u)", tag);
450  break;
451  default:
452  break;
453  }
454 
455  return 0;
456 }
457 
459 {
460  AVIContext *avi = s->priv_data;
461  int i, j;
462  int64_t lensum = 0;
463  int64_t maxpos = 0;
464 
465  for (i = 0; i<s->nb_streams; i++) {
466  int64_t len = 0;
467  FFStream *const sti = ffstream(s->streams[i]);
468 
469  if (!sti->nb_index_entries)
470  continue;
471 
472  for (j = 0; j < sti->nb_index_entries; j++)
473  len += sti->index_entries[j].size;
474  maxpos = FFMAX(maxpos, sti->index_entries[j-1].pos);
475  lensum += len;
476  }
477  if (maxpos < av_rescale(avi->io_fsize, 9, 10)) // index does not cover the whole file
478  return 0;
479  if (lensum*9/10 > maxpos || lensum < maxpos*9/10) // frame sum and filesize mismatch
480  return 0;
481 
482  for (i = 0; i<s->nb_streams; i++) {
483  int64_t len = 0;
484  AVStream *st = s->streams[i];
485  FFStream *const sti = ffstream(st);
487  AVInteger bitrate_i, den_i, num_i;
488 
489  for (j = 0; j < sti->nb_index_entries; j++)
490  len += sti->index_entries[j].size;
491 
492  if (sti->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
493  continue;
496  num_i = av_add_i(av_mul_i(av_int2i(8*len), av_int2i(st->time_base.den)), av_shr_i(den_i, 1));
497  bitrate_i = av_div_i(num_i, den_i);
498  if (av_cmp_i(bitrate_i, av_int2i(INT64_MAX)) <= 0) {
499  int64_t bitrate = av_i2int(bitrate_i);
500  if (bitrate > 0) {
501  st->codecpar->bit_rate = bitrate;
502  }
503  }
504  }
505  return 1;
506 }
507 
509 {
510  AVIContext *avi = s->priv_data;
511  AVIOContext *pb = s->pb;
512  unsigned int tag, tag1, handler;
513  int codec_type, stream_index, frame_period;
514  unsigned int size;
515  int i;
516  AVStream *st;
517  AVIStream *ast = NULL;
518  int avih_width = 0, avih_height = 0;
519  int amv_file_format = 0;
520  uint64_t list_end = 0;
521  int64_t pos;
522  int ret;
523  AVDictionaryEntry *dict_entry;
524 
525  avi->stream_index = -1;
526 
527  ret = get_riff(s, pb);
528  if (ret < 0)
529  return ret;
530 
531  av_log(avi, AV_LOG_DEBUG, "use odml:%d\n", avi->use_odml);
532 
533  avi->io_fsize = avi->fsize = avio_size(pb);
534  if (avi->fsize <= 0 || avi->fsize < avi->riff_end)
535  avi->fsize = avi->riff_end == 8 ? INT64_MAX : avi->riff_end;
536 
537  /* first list tag */
538  stream_index = -1;
539  codec_type = -1;
540  frame_period = 0;
541  for (;;) {
542  if (avio_feof(pb))
543  return AVERROR_INVALIDDATA;
544  tag = avio_rl32(pb);
545  size = avio_rl32(pb);
546 
547  print_tag(s, "tag", tag, size);
548 
549  switch (tag) {
550  case MKTAG('L', 'I', 'S', 'T'):
551  list_end = avio_tell(pb) + size;
552  /* Ignored, except at start of video packets. */
553  tag1 = avio_rl32(pb);
554 
555  print_tag(s, "list", tag1, 0);
556 
557  if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
558  avi->movi_list = avio_tell(pb) - 4;
559  if (size)
560  avi->movi_end = avi->movi_list + size + (size & 1);
561  else
562  avi->movi_end = avi->fsize;
563  av_log(s, AV_LOG_TRACE, "movi end=%"PRIx64"\n", avi->movi_end);
564  goto end_of_header;
565  } else if (tag1 == MKTAG('I', 'N', 'F', 'O')) {
566  if (size < 4)
567  return AVERROR_INVALIDDATA;
568  ff_read_riff_info(s, size - 4);
569  } else if (tag1 == MKTAG('n', 'c', 'd', 't'))
570  avi_read_nikon(s, list_end);
571 
572  break;
573  case MKTAG('I', 'D', 'I', 'T'):
574  {
575  unsigned char date[64] = { 0 };
576  size += (size & 1);
577  size -= avio_read(pb, date, FFMIN(size, sizeof(date) - 1));
578  avio_skip(pb, size);
579  avi_metadata_creation_time(&s->metadata, date);
580  break;
581  }
582  case MKTAG('d', 'm', 'l', 'h'):
583  avi->is_odml = 1;
584  avio_skip(pb, size + (size & 1));
585  break;
586  case MKTAG('a', 'm', 'v', 'h'):
587  amv_file_format = 1;
588  case MKTAG('a', 'v', 'i', 'h'):
589  /* AVI header */
590  /* using frame_period is bad idea */
591  frame_period = avio_rl32(pb);
592  avio_rl32(pb); /* max. bytes per second */
593  avio_rl32(pb);
595 
596  avio_skip(pb, 2 * 4);
597  avio_rl32(pb);
598  avio_rl32(pb);
599  avih_width = avio_rl32(pb);
600  avih_height = avio_rl32(pb);
601 
602  avio_skip(pb, size - 10 * 4);
603  break;
604  case MKTAG('s', 't', 'r', 'h'):
605  /* stream header */
606 
607  tag1 = avio_rl32(pb);
608  handler = avio_rl32(pb); /* codec tag */
609 
610  if (tag1 == MKTAG('p', 'a', 'd', 's')) {
611  avio_skip(pb, size - 8);
612  break;
613  } else {
614  stream_index++;
615  st = avformat_new_stream(s, NULL);
616  if (!st)
617  return AVERROR(ENOMEM);
618 
619  st->id = stream_index;
620  ast = av_mallocz(sizeof(AVIStream));
621  if (!ast)
622  return AVERROR(ENOMEM);
623  st->priv_data = ast;
624  }
625  if (amv_file_format)
626  tag1 = stream_index ? MKTAG('a', 'u', 'd', 's')
627  : MKTAG('v', 'i', 'd', 's');
628 
629  print_tag(s, "strh", tag1, -1);
630 
631  if (tag1 == MKTAG('i', 'a', 'v', 's') ||
632  tag1 == MKTAG('i', 'v', 'a', 's')) {
633  int64_t dv_dur;
634 
635  /* After some consideration -- I don't think we
636  * have to support anything but DV in type1 AVIs. */
637  if (s->nb_streams != 1)
638  return AVERROR_INVALIDDATA;
639 
640  if (handler != MKTAG('d', 'v', 's', 'd') &&
641  handler != MKTAG('d', 'v', 'h', 'd') &&
642  handler != MKTAG('d', 'v', 's', 'l'))
643  return AVERROR_INVALIDDATA;
644 
645  if (!CONFIG_DV_DEMUXER)
647 
648  ast = s->streams[0]->priv_data;
649  st->priv_data = NULL;
650  ff_remove_stream(s, st);
651 
653  if (!avi->dv_demux) {
654  av_free(ast);
655  return AVERROR(ENOMEM);
656  }
657 
658  s->streams[0]->priv_data = ast;
659  avio_skip(pb, 3 * 4);
660  ast->scale = avio_rl32(pb);
661  ast->rate = avio_rl32(pb);
662  avio_skip(pb, 4); /* start time */
663 
664  dv_dur = avio_rl32(pb);
665  if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) {
666  dv_dur *= AV_TIME_BASE;
667  s->duration = av_rescale(dv_dur, ast->scale, ast->rate);
668  }
669  /* else, leave duration alone; timing estimation in utils.c
670  * will make a guess based on bitrate. */
671 
672  stream_index = s->nb_streams - 1;
673  avio_skip(pb, size - 9 * 4);
674  break;
675  }
676 
677  av_assert0(stream_index < s->nb_streams);
678  ast->handler = handler;
679 
680  avio_rl32(pb); /* flags */
681  avio_rl16(pb); /* priority */
682  avio_rl16(pb); /* language */
683  avio_rl32(pb); /* initial frame */
684  ast->scale = avio_rl32(pb);
685  ast->rate = avio_rl32(pb);
686  if (!(ast->scale && ast->rate)) {
688  "scale/rate is %"PRIu32"/%"PRIu32" which is invalid. "
689  "(This file has been generated by broken software.)\n",
690  ast->scale,
691  ast->rate);
692  if (frame_period) {
693  ast->rate = 1000000;
694  ast->scale = frame_period;
695  } else {
696  ast->rate = 25;
697  ast->scale = 1;
698  }
699  }
700  avpriv_set_pts_info(st, 64, ast->scale, ast->rate);
701 
702  ast->cum_len = avio_rl32(pb); /* start */
703  st->nb_frames = avio_rl32(pb);
704 
705  st->start_time = 0;
706  avio_rl32(pb); /* buffer size */
707  avio_rl32(pb); /* quality */
708  if (ast->cum_len > 3600LL * ast->rate / ast->scale) {
709  av_log(s, AV_LOG_ERROR, "crazy start time, iam scared, giving up\n");
710  ast->cum_len = 0;
711  }
712  ast->sample_size = avio_rl32(pb);
713  ast->cum_len *= FFMAX(1, ast->sample_size);
714  av_log(s, AV_LOG_TRACE, "%"PRIu32" %"PRIu32" %d\n",
715  ast->rate, ast->scale, ast->sample_size);
716 
717  switch (tag1) {
718  case MKTAG('v', 'i', 'd', 's'):
720 
721  ast->sample_size = 0;
722  st->avg_frame_rate = av_inv_q(st->time_base);
723  break;
724  case MKTAG('a', 'u', 'd', 's'):
726  break;
727  case MKTAG('t', 'x', 't', 's'):
729  break;
730  case MKTAG('d', 'a', 't', 's'):
732  break;
733  default:
734  av_log(s, AV_LOG_INFO, "unknown stream type %X\n", tag1);
735  }
736 
737  if (ast->sample_size < 0) {
738  if (s->error_recognition & AV_EF_EXPLODE) {
740  "Invalid sample_size %d at stream %d\n",
741  ast->sample_size,
742  stream_index);
743  return AVERROR_INVALIDDATA;
744  }
746  "Invalid sample_size %d at stream %d "
747  "setting it to 0\n",
748  ast->sample_size,
749  stream_index);
750  ast->sample_size = 0;
751  }
752 
753  if (ast->sample_size == 0) {
754  st->duration = st->nb_frames;
755  if (st->duration > 0 && avi->io_fsize > 0 && avi->riff_end > avi->io_fsize) {
756  av_log(s, AV_LOG_DEBUG, "File is truncated adjusting duration\n");
757  st->duration = av_rescale(st->duration, avi->io_fsize, avi->riff_end);
758  }
759  }
760  ast->frame_offset = ast->cum_len;
761  avio_skip(pb, size - 12 * 4);
762  break;
763  case MKTAG('s', 't', 'r', 'f'):
764  /* stream header */
765  if (!size && (codec_type == AVMEDIA_TYPE_AUDIO ||
767  break;
768  if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {
769  avio_skip(pb, size);
770  } else {
771  uint64_t cur_pos = avio_tell(pb);
772  FFStream *sti;
773  unsigned esize;
774  if (cur_pos < list_end)
775  size = FFMIN(size, list_end - cur_pos);
776  st = s->streams[stream_index];
777  sti = ffstream(st);
779  avio_skip(pb, size);
780  break;
781  }
782  switch (codec_type) {
783  case AVMEDIA_TYPE_VIDEO:
784  if (amv_file_format) {
785  st->codecpar->width = avih_width;
786  st->codecpar->height = avih_height;
789  avio_skip(pb, size);
790  break;
791  }
792  tag1 = ff_get_bmp_header(pb, st, &esize);
793 
794  if (tag1 == MKTAG('D', 'X', 'S', 'B') ||
795  tag1 == MKTAG('D', 'X', 'S', 'A')) {
797  st->codecpar->codec_tag = tag1;
799  break;
800  }
801 
802  if (size > 10 * 4 && size < (1 << 30) && size < avi->fsize) {
803  if (esize == size-1 && (esize&1)) {
804  st->codecpar->extradata_size = esize - 10 * 4;
805  } else
806  st->codecpar->extradata_size = size - 10 * 4;
807  if (st->codecpar->extradata) {
808  av_log(s, AV_LOG_WARNING, "New extradata in strf chunk, freeing previous one.\n");
809  }
810  ret = ff_get_extradata(s, st->codecpar, pb,
811  st->codecpar->extradata_size);
812  if (ret < 0)
813  return ret;
814  }
815 
816  // FIXME: check if the encoder really did this correctly
817  if (st->codecpar->extradata_size & 1)
818  avio_r8(pb);
819 
820  /* Extract palette from extradata if bpp <= 8.
821  * This code assumes that extradata contains only palette.
822  * This is true for all paletted codecs implemented in
823  * FFmpeg. */
824  if (st->codecpar->extradata_size &&
825  (st->codecpar->bits_per_coded_sample <= 8)) {
826  int pal_size = (1 << st->codecpar->bits_per_coded_sample) << 2;
827  const uint8_t *pal_src;
828 
829  pal_size = FFMIN(pal_size, st->codecpar->extradata_size);
830  pal_src = st->codecpar->extradata +
831  st->codecpar->extradata_size - pal_size;
832  /* Exclude the "BottomUp" field from the palette */
833  if (pal_src - st->codecpar->extradata >= 9 &&
834  !memcmp(st->codecpar->extradata + st->codecpar->extradata_size - 9, "BottomUp", 9))
835  pal_src -= 9;
836  for (i = 0; i < pal_size / 4; i++)
837  ast->pal[i] = 0xFFU<<24 | AV_RL32(pal_src + 4 * i);
838  ast->has_pal = 1;
839  }
840 
841  print_tag(s, "video", tag1, 0);
842 
844  st->codecpar->codec_tag = tag1;
846  tag1);
847  /* If codec is not found yet, try with the mov tags. */
848  if (!st->codecpar->codec_id) {
849  st->codecpar->codec_id =
851  if (st->codecpar->codec_id)
853  "mov tag found in avi (fourcc %s)\n",
854  av_fourcc2str(tag1));
855  }
856  if (!st->codecpar->codec_id)
858 
859  /* This is needed to get the pict type which is necessary
860  * for generating correct pts. */
862 
863  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 &&
864  ast->handler == MKTAG('X', 'V', 'I', 'D'))
865  st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D');
866 
867  if (st->codecpar->codec_tag == MKTAG('V', 'S', 'S', 'H'))
869  if (st->codecpar->codec_id == AV_CODEC_ID_RV40)
871  if (st->codecpar->codec_id == AV_CODEC_ID_HEVC &&
872  st->codecpar->codec_tag == MKTAG('H', '2', '6', '5'))
874 
875  if (st->codecpar->codec_id == AV_CODEC_ID_AVRN &&
876  st->codecpar->codec_tag == MKTAG('A', 'V', 'R', 'n') &&
877  (st->codecpar->extradata_size < 31 ||
878  memcmp(&st->codecpar->extradata[28], "1:1", 3)))
880 
881  if (st->codecpar->codec_tag == 0 && st->codecpar->height > 0 &&
882  st->codecpar->extradata_size < 1U << 30) {
883  st->codecpar->extradata_size += 9;
884  if ((ret = av_reallocp(&st->codecpar->extradata,
885  st->codecpar->extradata_size +
887  st->codecpar->extradata_size = 0;
888  return ret;
889  } else
890  memcpy(st->codecpar->extradata + st->codecpar->extradata_size - 9,
891  "BottomUp", 9);
892  }
893  if (st->codecpar->height == INT_MIN)
894  return AVERROR_INVALIDDATA;
895  st->codecpar->height = FFABS(st->codecpar->height);
896 
897 // avio_skip(pb, size - 5 * 4);
898  break;
899  case AVMEDIA_TYPE_AUDIO:
900  ret = ff_get_wav_header(s, pb, st->codecpar, size, 0);
901  if (ret < 0)
902  return ret;
904  if (ast->sample_size && st->codecpar->block_align &&
905  ast->sample_size != st->codecpar->block_align) {
906  av_log(s,
908  "sample size (%d) != block align (%d)\n",
909  ast->sample_size,
910  st->codecpar->block_align);
911  ast->sample_size = st->codecpar->block_align;
912  }
913  /* 2-aligned
914  * (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
915  if (size & 1)
916  avio_skip(pb, 1);
917  /* Force parsing as several audio frames can be in
918  * one packet and timestamps refer to packet start. */
920  /* ADTS header is in extradata, AAC without header must be
921  * stored as exact frames. Parser not needed and it will
922  * fail. */
923  if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
926  // The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS
927  if (st->codecpar->codec_id == AV_CODEC_ID_FLAC)
929  /* AVI files with Xan DPCM audio (wrongly) declare PCM
930  * audio in the header but have Axan as stream_code_tag. */
931  if (ast->handler == AV_RL32("Axan")) {
933  st->codecpar->codec_tag = 0;
934  ast->dshow_block_align = 0;
935  }
936  if (amv_file_format) {
938  ast->dshow_block_align = 0;
939  }
940  if ((st->codecpar->codec_id == AV_CODEC_ID_AAC ||
943  st->codecpar->codec_id == AV_CODEC_ID_MP2 ) && ast->dshow_block_align <= 4 && ast->dshow_block_align) {
944  av_log(s, AV_LOG_DEBUG, "overriding invalid dshow_block_align of %d\n", ast->dshow_block_align);
945  ast->dshow_block_align = 0;
946  }
947  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 1024 && ast->sample_size == 1024 ||
948  st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 4096 && ast->sample_size == 4096 ||
949  st->codecpar->codec_id == AV_CODEC_ID_MP3 && ast->dshow_block_align == 1152 && ast->sample_size == 1152) {
950  av_log(s, AV_LOG_DEBUG, "overriding sample_size\n");
951  ast->sample_size = 0;
952  }
953  break;
956  sti->request_probe = 1;
957  avio_skip(pb, size);
958  break;
959  default:
962  st->codecpar->codec_tag = 0;
963  avio_skip(pb, size);
964  break;
965  }
966  }
967  break;
968  case MKTAG('s', 't', 'r', 'd'):
969  if (stream_index >= (unsigned)s->nb_streams
970  || s->streams[stream_index]->codecpar->extradata_size
971  || s->streams[stream_index]->codecpar->codec_tag == MKTAG('H','2','6','4')) {
972  avio_skip(pb, size);
973  } else {
974  uint64_t cur_pos = avio_tell(pb);
975  if (cur_pos < list_end)
976  size = FFMIN(size, list_end - cur_pos);
977  st = s->streams[stream_index];
978 
979  if (size<(1<<30)) {
980  if (st->codecpar->extradata) {
981  av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n");
982  }
983  if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0)
984  return ret;
985  }
986 
987  if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly
988  avio_r8(pb);
989 
991  if (ret < 0) {
992  av_log(s, AV_LOG_WARNING, "could not decoding EXIF data in stream header.\n");
993  }
994  }
995  break;
996  case MKTAG('i', 'n', 'd', 'x'):
997  pos = avio_tell(pb);
998  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !(s->flags & AVFMT_FLAG_IGNIDX) &&
999  avi->use_odml &&
1000  read_odml_index(s, 0) < 0 &&
1001  (s->error_recognition & AV_EF_EXPLODE))
1002  return AVERROR_INVALIDDATA;
1003  avio_seek(pb, pos + size, SEEK_SET);
1004  break;
1005  case MKTAG('v', 'p', 'r', 'p'):
1006  if (stream_index < (unsigned)s->nb_streams && size > 9 * 4) {
1007  AVRational active, active_aspect;
1008 
1009  st = s->streams[stream_index];
1010  avio_rl32(pb);
1011  avio_rl32(pb);
1012  avio_rl32(pb);
1013  avio_rl32(pb);
1014  avio_rl32(pb);
1015 
1016  active_aspect.den = avio_rl16(pb);
1017  active_aspect.num = avio_rl16(pb);
1018  active.num = avio_rl32(pb);
1019  active.den = avio_rl32(pb);
1020  avio_rl32(pb); // nbFieldsPerFrame
1021 
1022  if (active_aspect.num && active_aspect.den &&
1023  active.num && active.den) {
1024  st->sample_aspect_ratio = av_div_q(active_aspect, active);
1025  av_log(s, AV_LOG_TRACE, "vprp %d/%d %d/%d\n",
1026  active_aspect.num, active_aspect.den,
1027  active.num, active.den);
1028  }
1029  size -= 9 * 4;
1030  }
1031  avio_skip(pb, size);
1032  break;
1033  case MKTAG('s', 't', 'r', 'n'):
1034  case MKTAG('i', 's', 'b', 'j'):
1035  case MKTAG('i', 'n', 'a', 'm'):
1036  case MKTAG('i', 'a', 'r', 't'):
1037  case MKTAG('i', 'c', 'o', 'p'):
1038  case MKTAG('i', 'c', 'm', 't'):
1039  case MKTAG('i', 'g', 'n', 'r'):
1040  case MKTAG('i', 'p', 'o', 'd'):
1041  case MKTAG('i', 's', 'o', 'f'):
1042  if (s->nb_streams) {
1043  ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
1044  if (ret < 0)
1045  return ret;
1046  break;
1047  }
1048  default:
1049  if (size > 1000000) {
1051  "Something went wrong during header parsing, "
1052  "tag %s has size %u, "
1053  "I will ignore it and try to continue anyway.\n",
1054  av_fourcc2str(tag), size);
1055  if (s->error_recognition & AV_EF_EXPLODE)
1056  return AVERROR_INVALIDDATA;
1057  avi->movi_list = avio_tell(pb) - 4;
1058  avi->movi_end = avi->fsize;
1059  goto end_of_header;
1060  }
1061  /* Do not fail for very large idx1 tags */
1062  case MKTAG('i', 'd', 'x', '1'):
1063  /* skip tag */
1064  size += (size & 1);
1065  avio_skip(pb, size);
1066  break;
1067  }
1068  }
1069 
1070 end_of_header:
1071  /* check stream number */
1072  if (stream_index != s->nb_streams - 1)
1073  return AVERROR_INVALIDDATA;
1074 
1075  if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))
1076  avi_load_index(s);
1078  avi->index_loaded |= 1;
1079 
1080  if ((ret = guess_ni_flag(s)) < 0)
1081  return ret;
1082 
1083  avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS);
1084 
1085  dict_entry = av_dict_get(s->metadata, "ISFT", NULL, 0);
1086  if (dict_entry && !strcmp(dict_entry->value, "PotEncoder"))
1087  for (i = 0; i < s->nb_streams; i++) {
1088  AVStream *st = s->streams[i];
1092  }
1093 
1094  for (i = 0; i < s->nb_streams; i++) {
1095  AVStream *st = s->streams[i];
1096  if (ffstream(st)->nb_index_entries)
1097  break;
1098  }
1099  // DV-in-AVI cannot be non-interleaved, if set this must be
1100  // a mis-detection.
1101  if (avi->dv_demux)
1102  avi->non_interleaved = 0;
1103  if (i == s->nb_streams && avi->non_interleaved) {
1105  "Non-interleaved AVI without index, switching to interleaved\n");
1106  avi->non_interleaved = 0;
1107  }
1108 
1109  if (avi->non_interleaved) {
1110  av_log(s, AV_LOG_INFO, "non-interleaved AVI\n");
1111  clean_index(s);
1112  }
1113 
1116 
1117  return 0;
1118 }
1119 
1121 {
1122  if (pkt->size >= 7 &&
1123  pkt->size < INT_MAX - AVPROBE_PADDING_SIZE &&
1124  !strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data + 5) == 2) {
1125  uint8_t desc[256];
1126  int score = AVPROBE_SCORE_EXTENSION, ret;
1127  AVIStream *ast = st->priv_data;
1128  const AVInputFormat *sub_demuxer;
1129  AVRational time_base;
1130  int size;
1131  AVProbeData pd;
1132  unsigned int desc_len;
1133 
1134  if (ast->sub_ctx)
1135  return 0;
1136 
1138  pkt->size - 7,
1139  0, NULL, NULL, NULL, NULL);
1140  if (!pb)
1141  goto error;
1142 
1143  desc_len = avio_rl32(pb);
1144 
1145  if (desc_len > pb->buf_end - pb->buf_ptr)
1146  goto error;
1147 
1148  ret = avio_get_str16le(pb, desc_len, desc, sizeof(desc));
1149  avio_skip(pb, desc_len - ret);
1150  if (*desc)
1151  av_dict_set(&st->metadata, "title", desc, 0);
1152 
1153  avio_rl16(pb); /* flags? */
1154  avio_rl32(pb); /* data size */
1155 
1156  size = pb->buf_end - pb->buf_ptr;
1158  .buf_size = size };
1159  if (!pd.buf)
1160  goto error;
1161  memcpy(pd.buf, pb->buf_ptr, size);
1162  sub_demuxer = av_probe_input_format2(&pd, 1, &score);
1163  av_freep(&pd.buf);
1164  if (!sub_demuxer)
1165  goto error;
1166 
1167  if (strcmp(sub_demuxer->name, "srt") && strcmp(sub_demuxer->name, "ass"))
1168  goto error;
1169 
1170  if (!(ast->sub_pkt = av_packet_alloc()))
1171  goto error;
1172 
1173  if (!(ast->sub_ctx = avformat_alloc_context()))
1174  goto error;
1175 
1176  ast->sub_ctx->pb = pb;
1177 
1178  if (ff_copy_whiteblacklists(ast->sub_ctx, s) < 0)
1179  goto error;
1180 
1181  if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) {
1182  if (ast->sub_ctx->nb_streams != 1)
1183  goto error;
1184  ff_read_packet(ast->sub_ctx, ast->sub_pkt);
1186  time_base = ast->sub_ctx->streams[0]->time_base;
1187  avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
1188  }
1189  ast->sub_buffer = pkt->buf;
1190  pkt->buf = NULL;
1192  return 1;
1193 
1194 error:
1195  av_packet_free(&ast->sub_pkt);
1196  av_freep(&ast->sub_ctx);
1197  avio_context_free(&pb);
1198  }
1199  return 0;
1200 }
1201 
1203  AVPacket *pkt)
1204 {
1205  AVIStream *ast, *next_ast = next_st->priv_data;
1206  int64_t ts, next_ts, ts_min = INT64_MAX;
1207  AVStream *st, *sub_st = NULL;
1208  int i;
1209 
1210  next_ts = av_rescale_q(next_ast->frame_offset, next_st->time_base,
1211  AV_TIME_BASE_Q);
1212 
1213  for (i = 0; i < s->nb_streams; i++) {
1214  st = s->streams[i];
1215  ast = st->priv_data;
1216  if (st->discard < AVDISCARD_ALL && ast && ast->sub_pkt && ast->sub_pkt->data) {
1217  ts = av_rescale_q(ast->sub_pkt->dts, st->time_base, AV_TIME_BASE_Q);
1218  if (ts <= next_ts && ts < ts_min) {
1219  ts_min = ts;
1220  sub_st = st;
1221  }
1222  }
1223  }
1224 
1225  if (sub_st) {
1226  ast = sub_st->priv_data;
1228  pkt->stream_index = sub_st->index;
1229 
1230  if (ff_read_packet(ast->sub_ctx, ast->sub_pkt) < 0)
1231  ast->sub_pkt->data = NULL;
1232  }
1233  return sub_st;
1234 }
1235 
1236 static int get_stream_idx(const unsigned *d)
1237 {
1238  if (d[0] >= '0' && d[0] <= '9' &&
1239  d[1] >= '0' && d[1] <= '9') {
1240  return (d[0] - '0') * 10 + (d[1] - '0');
1241  } else {
1242  return 100; // invalid stream ID
1243  }
1244 }
1245 
1246 /**
1247  *
1248  * @param exit_early set to 1 to just gather packet position without making the changes needed to actually read & return the packet
1249  */
1250 static int avi_sync(AVFormatContext *s, int exit_early)
1251 {
1252  AVIContext *avi = s->priv_data;
1253  AVIOContext *pb = s->pb;
1254  int n;
1255  unsigned int d[8];
1256  unsigned int size;
1257  int64_t i, sync;
1258 
1259 start_sync:
1260  memset(d, -1, sizeof(d));
1261  for (i = sync = avio_tell(pb); !avio_feof(pb); i++) {
1262  int j;
1263 
1264  for (j = 0; j < 7; j++)
1265  d[j] = d[j + 1];
1266  d[7] = avio_r8(pb);
1267 
1268  size = d[4] + (d[5] << 8) + (d[6] << 16) + (d[7] << 24);
1269 
1270  n = get_stream_idx(d + 2);
1271  ff_tlog(s, "%X %X %X %X %X %X %X %X %"PRId64" %u %d\n",
1272  d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
1273  if (i*(avi->io_fsize>0) + (uint64_t)size > avi->fsize || d[0] > 127)
1274  continue;
1275 
1276  // parse ix##
1277  if ((d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) ||
1278  // parse JUNK
1279  (d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') ||
1280  (d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1') ||
1281  (d[0] == 'i' && d[1] == 'n' && d[2] == 'd' && d[3] == 'x')) {
1282  avio_skip(pb, size);
1283  goto start_sync;
1284  }
1285 
1286  // parse stray LIST
1287  if (d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T') {
1288  avio_skip(pb, 4);
1289  goto start_sync;
1290  }
1291 
1292  n = get_stream_idx(d);
1293 
1294  if (!((i - avi->last_pkt_pos) & 1) &&
1295  get_stream_idx(d + 1) < s->nb_streams)
1296  continue;
1297 
1298  // detect ##ix chunk and skip
1299  if (d[2] == 'i' && d[3] == 'x' && n < s->nb_streams) {
1300  avio_skip(pb, size);
1301  goto start_sync;
1302  }
1303 
1304  if (d[2] == 'w' && d[3] == 'c' && n < s->nb_streams) {
1305  avio_skip(pb, 16 * 3 + 8);
1306  goto start_sync;
1307  }
1308 
1309  if (avi->dv_demux && n != 0)
1310  continue;
1311 
1312  // parse ##dc/##wb
1313  if (n < s->nb_streams) {
1314  AVStream *st;
1315  AVIStream *ast;
1316  st = s->streams[n];
1317  ast = st->priv_data;
1318 
1319  if (!ast) {
1320  av_log(s, AV_LOG_WARNING, "Skipping foreign stream %d packet\n", n);
1321  continue;
1322  }
1323 
1324  if (s->nb_streams >= 2) {
1325  AVStream *st1 = s->streams[1];
1326  AVIStream *ast1 = st1->priv_data;
1327  // workaround for broken small-file-bug402.avi
1328  if (ast1 && d[2] == 'w' && d[3] == 'b'
1329  && n == 0
1330  && st ->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
1332  && ast->prefix == 'd'*256+'c'
1333  && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count)
1334  ) {
1335  n = 1;
1336  st = st1;
1337  ast = ast1;
1339  "Invalid stream + prefix combination, assuming audio.\n");
1340  }
1341  }
1342 
1343  if (d[2] == 'p' && d[3] == 'c' && size <= 4 * 256 + 4) {
1344  int k = avio_r8(pb);
1345  int last = (k + avio_r8(pb) - 1) & 0xFF;
1346 
1347  avio_rl16(pb); // flags
1348 
1349  // b + (g << 8) + (r << 16);
1350  for (; k <= last; k++)
1351  ast->pal[k] = 0xFFU<<24 | avio_rb32(pb)>>8;
1352 
1353  ast->has_pal = 1;
1354  goto start_sync;
1355  } else if (((ast->prefix_count < 5 || sync + 9 > i) &&
1356  d[2] < 128 && d[3] < 128) ||
1357  d[2] * 256 + d[3] == ast->prefix /* ||
1358  (d[2] == 'd' && d[3] == 'c') ||
1359  (d[2] == 'w' && d[3] == 'b') */) {
1360  if (exit_early)
1361  return 0;
1362  if (d[2] * 256 + d[3] == ast->prefix)
1363  ast->prefix_count++;
1364  else {
1365  ast->prefix = d[2] * 256 + d[3];
1366  ast->prefix_count = 0;
1367  }
1368 
1369  if (!avi->dv_demux &&
1370  ((st->discard >= AVDISCARD_DEFAULT && size == 0) /* ||
1371  // FIXME: needs a little reordering
1372  (st->discard >= AVDISCARD_NONKEY &&
1373  !(pkt->flags & AV_PKT_FLAG_KEY)) */
1374  || st->discard >= AVDISCARD_ALL)) {
1375 
1376  ast->frame_offset += get_duration(ast, size);
1377  avio_skip(pb, size);
1378  goto start_sync;
1379  }
1380 
1381  avi->stream_index = n;
1382  ast->packet_size = size + 8;
1383  ast->remaining = size;
1384 
1385  if (size) {
1386  FFStream *const sti = ffstream(st);
1387  uint64_t pos = avio_tell(pb) - 8;
1388  if (!sti->index_entries || !sti->nb_index_entries ||
1389  sti->index_entries[sti->nb_index_entries - 1].pos < pos) {
1391  0, AVINDEX_KEYFRAME);
1392  }
1393  }
1394  return 0;
1395  }
1396  }
1397  }
1398 
1399  if (pb->error)
1400  return pb->error;
1401  return AVERROR_EOF;
1402 }
1403 
1405 {
1406  AVIContext *avi = s->priv_data;
1407  int best_stream_index = 0;
1408  AVStream *best_st = NULL;
1409  FFStream *best_sti;
1410  AVIStream *best_ast;
1411  int64_t best_ts = INT64_MAX;
1412  int i;
1413 
1414  for (i = 0; i < s->nb_streams; i++) {
1415  AVStream *st = s->streams[i];
1416  FFStream *const sti = ffstream(st);
1417  AVIStream *ast = st->priv_data;
1418  int64_t ts = ast->frame_offset;
1419  int64_t last_ts;
1420 
1421  if (!sti->nb_index_entries)
1422  continue;
1423 
1424  last_ts = sti->index_entries[sti->nb_index_entries - 1].timestamp;
1425  if (!ast->remaining && ts > last_ts)
1426  continue;
1427 
1428  ts = av_rescale_q(ts, st->time_base,
1429  (AVRational) { FFMAX(1, ast->sample_size),
1430  AV_TIME_BASE });
1431 
1432  av_log(s, AV_LOG_TRACE, "%"PRId64" %d/%d %"PRId64"\n", ts,
1433  st->time_base.num, st->time_base.den, ast->frame_offset);
1434  if (ts < best_ts) {
1435  best_ts = ts;
1436  best_st = st;
1437  best_stream_index = i;
1438  }
1439  }
1440  if (!best_st)
1441  return AVERROR_EOF;
1442 
1443  best_sti = ffstream(best_st);
1444  best_ast = best_st->priv_data;
1445  best_ts = best_ast->frame_offset;
1446  if (best_ast->remaining) {
1447  i = av_index_search_timestamp(best_st,
1448  best_ts,
1449  AVSEEK_FLAG_ANY |
1451  } else {
1452  i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
1453  if (i >= 0)
1454  best_ast->frame_offset = best_sti->index_entries[i].timestamp;
1455  }
1456 
1457  if (i >= 0) {
1458  int64_t pos = best_sti->index_entries[i].pos;
1459  pos += best_ast->packet_size - best_ast->remaining;
1460  if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
1461  return AVERROR_EOF;
1462 
1463  av_assert0(best_ast->remaining <= best_ast->packet_size);
1464 
1465  avi->stream_index = best_stream_index;
1466  if (!best_ast->remaining)
1467  best_ast->packet_size =
1468  best_ast->remaining = best_sti->index_entries[i].size;
1469  }
1470  else
1471  return AVERROR_EOF;
1472 
1473  return 0;
1474 }
1475 
1477 {
1478  AVIContext *avi = s->priv_data;
1479  AVIOContext *pb = s->pb;
1480  int err;
1481 
1482  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1483  int size = avpriv_dv_get_packet(avi->dv_demux, pkt);
1484  if (size >= 0)
1485  return size;
1486  else
1487  goto resync;
1488  }
1489 
1490  if (avi->non_interleaved) {
1491  err = ni_prepare_read(s);
1492  if (err < 0)
1493  return err;
1494  }
1495 
1496 resync:
1497  if (avi->stream_index >= 0) {
1498  AVStream *st = s->streams[avi->stream_index];
1499  FFStream *const sti = ffstream(st);
1500  AVIStream *ast = st->priv_data;
1501  int dv_demux = CONFIG_DV_DEMUXER && avi->dv_demux;
1502  int size, err;
1503 
1504  if (get_subtitle_pkt(s, st, pkt))
1505  return 0;
1506 
1507  // minorityreport.AVI block_align=1024 sample_size=1 IMA-ADPCM
1508  if (ast->sample_size <= 1)
1509  size = INT_MAX;
1510  else if (ast->sample_size < 32)
1511  // arbitrary multiplier to avoid tiny packets for raw PCM data
1512  size = 1024 * ast->sample_size;
1513  else
1514  size = ast->sample_size;
1515 
1516  if (size > ast->remaining)
1517  size = ast->remaining;
1518  avi->last_pkt_pos = avio_tell(pb);
1519  err = av_get_packet(pb, pkt, size);
1520  if (err < 0)
1521  return err;
1522  size = err;
1523 
1524  if (ast->has_pal && pkt->size < (unsigned)INT_MAX / 2 && !dv_demux) {
1525  uint8_t *pal;
1528  AVPALETTE_SIZE);
1529  if (!pal) {
1531  "Failed to allocate data for palette\n");
1532  } else {
1533  memcpy(pal, ast->pal, AVPALETTE_SIZE);
1534  ast->has_pal = 0;
1535  }
1536  }
1537 
1538  if (CONFIG_DV_DEMUXER && dv_demux) {
1540  pkt->data, pkt->size, pkt->pos);
1542  if (size < 0)
1544  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
1545  !st->codecpar->codec_tag && read_gab2_sub(s, st, pkt)) {
1546  ast->frame_offset++;
1547  avi->stream_index = -1;
1548  ast->remaining = 0;
1549  goto resync;
1550  } else {
1551  /* XXX: How to handle B-frames in AVI? */
1552  pkt->dts = ast->frame_offset;
1553 // pkt->dts += ast->start;
1554  if (ast->sample_size)
1555  pkt->dts /= ast->sample_size;
1556  pkt->stream_index = avi->stream_index;
1557 
1558  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->index_entries) {
1559  AVIndexEntry *e;
1560  int index;
1561 
1563  e = &sti->index_entries[index];
1564 
1565  if (index >= 0 && e->timestamp == ast->frame_offset) {
1566  if (index == sti->nb_index_entries-1) {
1567  int key=1;
1568  uint32_t state=-1;
1569  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1570  const uint8_t *ptr = pkt->data, *end = ptr + FFMIN(size, 256);
1571  while (ptr < end) {
1572  ptr = avpriv_find_start_code(ptr, end, &state);
1573  if (state == 0x1B6 && ptr < end) {
1574  key = !(*ptr & 0xC0);
1575  break;
1576  }
1577  }
1578  }
1579  if (!key)
1580  e->flags &= ~AVINDEX_KEYFRAME;
1581  }
1582  if (e->flags & AVINDEX_KEYFRAME)
1584  }
1585  } else {
1587  }
1588  ast->frame_offset += get_duration(ast, pkt->size);
1589  }
1590  ast->remaining -= err;
1591  if (!ast->remaining) {
1592  avi->stream_index = -1;
1593  ast->packet_size = 0;
1594  }
1595 
1596  if (!avi->non_interleaved && pkt->pos >= 0 && ast->seek_pos > pkt->pos) {
1598  goto resync;
1599  }
1600  ast->seek_pos= 0;
1601 
1602  if (!avi->non_interleaved && sti->nb_index_entries > 1 && avi->index_loaded > 1) {
1604 
1605  if (avi->dts_max < dts) {
1606  avi->dts_max = dts;
1607  } else if (avi->dts_max - (uint64_t)dts > 2*AV_TIME_BASE) {
1608  avi->non_interleaved= 1;
1609  av_log(s, AV_LOG_INFO, "Switching to NI mode, due to poor interleaving\n");
1610  }
1611  }
1612 
1613  return 0;
1614  }
1615 
1616  if ((err = avi_sync(s, 0)) < 0)
1617  return err;
1618  goto resync;
1619 }
1620 
1621 /* XXX: We make the implicit supposition that the positions are sorted
1622  * for each stream. */
1624 {
1625  AVIContext *avi = s->priv_data;
1626  AVIOContext *pb = s->pb;
1627  int nb_index_entries, i;
1628  AVStream *st;
1629  AVIStream *ast;
1630  int64_t pos;
1631  unsigned int index, tag, flags, len, first_packet = 1;
1632  int64_t last_pos = -1;
1633  unsigned last_idx = -1;
1634  int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1635  int anykey = 0;
1636 
1637  nb_index_entries = size / 16;
1638  if (nb_index_entries <= 0)
1639  return AVERROR_INVALIDDATA;
1640 
1641  idx1_pos = avio_tell(pb);
1642  avio_seek(pb, avi->movi_list + 4, SEEK_SET);
1643  if (avi_sync(s, 1) == 0)
1644  first_packet_pos = avio_tell(pb) - 8;
1645  avi->stream_index = -1;
1646  avio_seek(pb, idx1_pos, SEEK_SET);
1647 
1648  if (s->nb_streams == 1 && s->streams[0]->codecpar->codec_tag == AV_RL32("MMES")) {
1649  first_packet_pos = 0;
1650  data_offset = avi->movi_list;
1651  }
1652 
1653  /* Read the entries and sort them in each stream component. */
1654  for (i = 0; i < nb_index_entries; i++) {
1655  if (avio_feof(pb))
1656  return -1;
1657 
1658  tag = avio_rl32(pb);
1659  flags = avio_rl32(pb);
1660  pos = avio_rl32(pb);
1661  len = avio_rl32(pb);
1662  av_log(s, AV_LOG_TRACE, "%d: tag=0x%x flags=0x%x pos=0x%"PRIx64" len=%d/",
1663  i, tag, flags, pos, len);
1664 
1665  index = ((tag & 0xff) - '0') * 10;
1666  index += (tag >> 8 & 0xff) - '0';
1667  if (index >= s->nb_streams)
1668  continue;
1669  st = s->streams[index];
1670  ast = st->priv_data;
1671 
1672  /* Skip 'xxpc' palette change entries in the index until a logic
1673  * to process these is properly implemented. */
1674  if ((tag >> 16 & 0xff) == 'p' && (tag >> 24 & 0xff) == 'c')
1675  continue;
1676 
1677  if (first_packet && first_packet_pos) {
1678  if (avi->movi_list + 4 != pos || pos + 500 > first_packet_pos)
1679  data_offset = first_packet_pos - pos;
1680  first_packet = 0;
1681  }
1682  pos += data_offset;
1683 
1684  av_log(s, AV_LOG_TRACE, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
1685 
1686  // even if we have only a single stream, we should
1687  // switch to non-interleaved to get correct timestamps
1688  if (last_pos == pos)
1689  avi->non_interleaved = 1;
1690  if (last_idx != pos && len) {
1691  av_add_index_entry(st, pos, ast->cum_len, len, 0,
1692  (flags & AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);
1693  last_idx= pos;
1694  }
1695  ast->cum_len += get_duration(ast, len);
1696  last_pos = pos;
1697  anykey |= flags&AVIIF_INDEX;
1698  }
1699  if (!anykey) {
1700  for (index = 0; index < s->nb_streams; index++) {
1701  FFStream *const sti = ffstream(s->streams[index]);
1702  if (sti->nb_index_entries)
1704  }
1705  }
1706  return 0;
1707 }
1708 
1709 /* Scan the index and consider any file with streams more than
1710  * 2 seconds or 64MB apart non-interleaved. */
1712 {
1713  int64_t min_pos, pos;
1714  int i;
1715  int *idx = av_calloc(s->nb_streams, sizeof(*idx));
1716  if (!idx)
1717  return AVERROR(ENOMEM);
1718  for (min_pos = pos = 0; min_pos != INT64_MAX; pos = min_pos + 1ULL) {
1719  int64_t max_dts = INT64_MIN / 2;
1720  int64_t min_dts = INT64_MAX / 2;
1721  int64_t max_buffer = 0;
1722 
1723  min_pos = INT64_MAX;
1724 
1725  for (i = 0; i < s->nb_streams; i++) {
1726  AVStream *st = s->streams[i];
1727  AVIStream *ast = st->priv_data;
1728  FFStream *const sti = ffstream(st);
1729  int n = sti->nb_index_entries;
1730  while (idx[i] < n && sti->index_entries[idx[i]].pos < pos)
1731  idx[i]++;
1732  if (idx[i] < n) {
1733  int64_t dts;
1734  dts = av_rescale_q(sti->index_entries[idx[i]].timestamp /
1735  FFMAX(ast->sample_size, 1),
1736  st->time_base, AV_TIME_BASE_Q);
1737  min_dts = FFMIN(min_dts, dts);
1738  min_pos = FFMIN(min_pos, sti->index_entries[idx[i]].pos);
1739  }
1740  }
1741  for (i = 0; i < s->nb_streams; i++) {
1742  AVStream *st = s->streams[i];
1743  FFStream *const sti = ffstream(st);
1744  AVIStream *ast = st->priv_data;
1745 
1746  if (idx[i] && min_dts != INT64_MAX / 2) {
1747  int64_t dts, delta_dts;
1748  dts = av_rescale_q(sti->index_entries[idx[i] - 1].timestamp /
1749  FFMAX(ast->sample_size, 1),
1750  st->time_base, AV_TIME_BASE_Q);
1751  delta_dts = av_sat_sub64(dts, min_dts);
1752  max_dts = FFMAX(max_dts, dts);
1753  max_buffer = FFMAX(max_buffer,
1754  av_rescale(delta_dts,
1755  st->codecpar->bit_rate,
1756  AV_TIME_BASE));
1757  }
1758  }
1759  if (av_sat_sub64(max_dts, min_dts) > 2 * AV_TIME_BASE ||
1760  max_buffer > 1024 * 1024 * 8 * 8) {
1761  av_free(idx);
1762  return 1;
1763  }
1764  }
1765  av_free(idx);
1766  return 0;
1767 }
1768 
1770 {
1771  int i;
1772  int64_t last_start = 0;
1773  int64_t first_end = INT64_MAX;
1774  int64_t oldpos = avio_tell(s->pb);
1775 
1776  for (i = 0; i < s->nb_streams; i++) {
1777  AVStream *st = s->streams[i];
1778  FFStream *const sti = ffstream(st);
1779  int n = sti->nb_index_entries;
1780  unsigned int size;
1781 
1782  if (n <= 0)
1783  continue;
1784 
1785  if (n >= 2) {
1786  int64_t pos = sti->index_entries[0].pos;
1787  unsigned tag[2];
1788  avio_seek(s->pb, pos, SEEK_SET);
1789  tag[0] = avio_r8(s->pb);
1790  tag[1] = avio_r8(s->pb);
1791  avio_rl16(s->pb);
1792  size = avio_rl32(s->pb);
1793  if (get_stream_idx(tag) == i && pos + size > sti->index_entries[1].pos)
1794  last_start = INT64_MAX;
1795  if (get_stream_idx(tag) == i && size == sti->index_entries[0].size + 8)
1796  last_start = INT64_MAX;
1797  }
1798 
1799  if (sti->index_entries[0].pos > last_start)
1800  last_start = sti->index_entries[0].pos;
1801  if (sti->index_entries[n - 1].pos < first_end)
1802  first_end = sti->index_entries[n - 1].pos;
1803  }
1804  avio_seek(s->pb, oldpos, SEEK_SET);
1805 
1806  if (last_start > first_end)
1807  return 1;
1808 
1809  return check_stream_max_drift(s);
1810 }
1811 
1813 {
1814  AVIContext *avi = s->priv_data;
1815  AVIOContext *pb = s->pb;
1816  uint32_t tag, size;
1817  int64_t pos = avio_tell(pb);
1818  int64_t next;
1819  int ret = -1;
1820 
1821  if (avio_seek(pb, avi->movi_end, SEEK_SET) < 0)
1822  goto the_end; // maybe truncated file
1823  av_log(s, AV_LOG_TRACE, "movi_end=0x%"PRIx64"\n", avi->movi_end);
1824  for (;;) {
1825  tag = avio_rl32(pb);
1826  size = avio_rl32(pb);
1827  if (avio_feof(pb))
1828  break;
1829  next = avio_tell(pb);
1830  if (next < 0 || next > INT64_MAX - size - (size & 1))
1831  break;
1832  next += size + (size & 1LL);
1833 
1834  if (tag == MKTAG('i', 'd', 'x', '1') &&
1835  avi_read_idx1(s, size) >= 0) {
1836  avi->index_loaded=2;
1837  ret = 0;
1838  }else if (tag == MKTAG('L', 'I', 'S', 'T')) {
1839  if (size < 4) {
1840  av_log(s, AV_LOG_WARNING, "Invalid size (%u) LIST in index\n", size);
1841  break;
1842  }
1843  uint32_t tag1 = avio_rl32(pb);
1844 
1845  if (tag1 == MKTAG('I', 'N', 'F', 'O'))
1846  ff_read_riff_info(s, size - 4);
1847  }else if (!ret)
1848  break;
1849 
1850  if (avio_seek(pb, next, SEEK_SET) < 0)
1851  break; // something is wrong here
1852  }
1853 
1854 the_end:
1855  avio_seek(pb, pos, SEEK_SET);
1856  return ret;
1857 }
1858 
1859 static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
1860 {
1861  AVIStream *ast2 = st2->priv_data;
1862  int64_t ts2 = av_rescale_q(timestamp, st->time_base, st2->time_base);
1863  av_packet_unref(ast2->sub_pkt);
1864  if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 ||
1865  avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
1866  ff_read_packet(ast2->sub_ctx, ast2->sub_pkt);
1867 }
1868 
1869 static int avi_read_seek(AVFormatContext *s, int stream_index,
1870  int64_t timestamp, int flags)
1871 {
1872  AVIContext *avi = s->priv_data;
1873  AVStream *st;
1874  FFStream *sti;
1875  int i, index;
1876  int64_t pos, pos_min;
1877  AVIStream *ast;
1878 
1879  /* Does not matter which stream is requested dv in avi has the
1880  * stream information in the first video stream.
1881  */
1882  if (avi->dv_demux)
1883  stream_index = 0;
1884 
1885  if (!avi->index_loaded) {
1886  /* we only load the index on demand */
1887  avi_load_index(s);
1888  avi->index_loaded |= 1;
1889  }
1890  av_assert0(stream_index >= 0);
1891 
1892  st = s->streams[stream_index];
1893  sti = ffstream(st);
1894  ast = st->priv_data;
1895 
1896  if (avi->dv_demux) {
1897  // index entries are in the AVI scale/rate timebase, which does
1898  // not match DV demuxer's stream timebase
1899  timestamp = av_rescale_q(timestamp, st->time_base,
1900  (AVRational){ ast->scale, ast->rate });
1901  } else
1902  timestamp *= FFMAX(ast->sample_size, 1);
1903 
1904  index = av_index_search_timestamp(st, timestamp, flags);
1905  if (index < 0) {
1906  if (sti->nb_index_entries > 0)
1907  av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n",
1908  timestamp,
1909  sti->index_entries[0].timestamp,
1910  sti->index_entries[sti->nb_index_entries - 1].timestamp);
1911  return AVERROR_INVALIDDATA;
1912  }
1913 
1914  /* find the position */
1915  pos = sti->index_entries[index].pos;
1916  timestamp = sti->index_entries[index].timestamp;
1917 
1918  av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n",
1919  timestamp, index, sti->index_entries[index].timestamp);
1920 
1921  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1922  /* One and only one real stream for DV in AVI, and it has video */
1923  /* offsets. Calling with other stream indexes should have failed */
1924  /* the av_index_search_timestamp call above. */
1925 
1926  if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1927  return -1;
1928 
1929  /* Feed the DV video stream version of the timestamp to the */
1930  /* DV demux so it can synthesize correct timestamps. */
1931  ff_dv_ts_reset(avi->dv_demux,
1932  av_rescale_q(timestamp, (AVRational){ ast->scale, ast->rate },
1933  st->time_base));
1934 
1935  avi->stream_index = -1;
1936  return 0;
1937  }
1938  timestamp /= FFMAX(ast->sample_size, 1);
1939 
1940  pos_min = pos;
1941  for (i = 0; i < s->nb_streams; i++) {
1942  AVStream *st2 = s->streams[i];
1943  FFStream *const sti2 = ffstream(st2);
1944  AVIStream *ast2 = st2->priv_data;
1945 
1946  ast2->packet_size =
1947  ast2->remaining = 0;
1948 
1949  if (ast2->sub_ctx) {
1950  seek_subtitle(st, st2, timestamp);
1951  continue;
1952  }
1953 
1954  if (sti2->nb_index_entries <= 0)
1955  continue;
1956 
1957 // av_assert1(st2->codecpar->block_align);
1959  av_rescale_q(timestamp,
1960  st->time_base,
1961  st2->time_base) *
1962  FFMAX(ast2->sample_size, 1),
1963  flags |
1966  if (index < 0)
1967  index = 0;
1968  ast2->seek_pos = sti2->index_entries[index].pos;
1969  pos_min = FFMIN(pos_min,ast2->seek_pos);
1970  }
1971  for (i = 0; i < s->nb_streams; i++) {
1972  AVStream *st2 = s->streams[i];
1973  FFStream *const sti2 = ffstream(st2);
1974  AVIStream *ast2 = st2->priv_data;
1975 
1976  if (ast2->sub_ctx || sti2->nb_index_entries <= 0)
1977  continue;
1978 
1980  st2,
1981  av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
1983  if (index < 0)
1984  index = 0;
1985  while (!avi->non_interleaved && index > 0 && sti2->index_entries[index-1].pos >= pos_min)
1986  index--;
1987  ast2->frame_offset = sti2->index_entries[index].timestamp;
1988  }
1989 
1990  /* do the seek */
1991  if (avio_seek(s->pb, pos_min, SEEK_SET) < 0) {
1992  av_log(s, AV_LOG_ERROR, "Seek failed\n");
1993  return -1;
1994  }
1995  avi->stream_index = -1;
1996  avi->dts_max = INT_MIN;
1997  return 0;
1998 }
1999 
2001 {
2002  int i;
2003  AVIContext *avi = s->priv_data;
2004 
2005  for (i = 0; i < s->nb_streams; i++) {
2006  AVStream *st = s->streams[i];
2007  AVIStream *ast = st->priv_data;
2008  if (ast) {
2009  if (ast->sub_ctx) {
2010  av_freep(&ast->sub_ctx->pb);
2012  }
2013  av_buffer_unref(&ast->sub_buffer);
2014  av_packet_free(&ast->sub_pkt);
2015  }
2016  }
2017 
2018  av_freep(&avi->dv_demux);
2019 
2020  return 0;
2021 }
2022 
2023 static int avi_probe(const AVProbeData *p)
2024 {
2025  int i;
2026 
2027  /* check file header */
2028  for (i = 0; avi_headers[i][0]; i++)
2029  if (AV_RL32(p->buf ) == AV_RL32(avi_headers[i] ) &&
2030  AV_RL32(p->buf + 8) == AV_RL32(avi_headers[i] + 4))
2031  return AVPROBE_SCORE_MAX;
2032 
2033  return 0;
2034 }
2035 
2037  .p.name = "avi",
2038  .p.long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
2039  .p.extensions = "avi",
2040  .p.priv_class = &demuxer_class,
2041  .priv_data_size = sizeof(AVIContext),
2042  .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
2043  .read_probe = avi_probe,
2048 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
flags
const SwsFlags flags[]
Definition: swscale.c:61
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
ff_avi_demuxer
const FFInputFormat ff_avi_demuxer
Definition: avidec.c:2036
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:1404
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:422
av_exif_parse_buffer
int av_exif_parse_buffer(void *logctx, const uint8_t *buf, size_t size, AVExifMetadata *ifd, enum AVExifHeaderMode header_mode)
Decodes the EXIF data provided in the buffer and writes it into the struct *ifd.
Definition: exif.c:881
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:1623
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:1416
AVExifMetadata
Definition: exif.h:76
bytestream2_tell
static av_always_inline int bytestream2_tell(const GetByteContext *g)
Definition: bytestream.h:192
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:769
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:815
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_exif_ifd_to_dict
int av_exif_ifd_to_dict(void *logctx, const AVExifMetadata *ifd, AVDictionary **metadata)
Recursively reads all tags from the IFD and stores them in the provided metadata dictionary.
Definition: exif.c:1052
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:263
int64_t
long long int64_t
Definition: coverity.c:34
AVIStream
Definition: avidec.c:46
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:208
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:1331
MAX_ODML_DEPTH
#define MAX_ODML_DEPTH
Definition: avidec.c:90
state
static struct @560 state
AVPacket::data
uint8_t * data
Definition: packet.h:588
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:429
avi_read_close
static int avi_read_close(AVFormatContext *s)
Definition: avidec.c:2000
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:833
data
const char data[16]
Definition: mxf.c:149
AVIOContext::error
int error
contains the error code or 0 if no error happened
Definition: avio.h:239
AVMetadataConv
Definition: metadata.h:34
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:524
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:32
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: codec_id.h:472
avi_metadata_creation_time
static void avi_metadata_creation_time(AVDictionary **metadata, char *date)
Definition: avidec.c:351
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:1120
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:326
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:643
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:598
DVDemuxContext
struct DVDemuxContext DVDemuxContext
Definition: dv.h:33
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:606
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:340
check_stream_max_drift
static int check_stream_max_drift(AVFormatContext *s)
Definition: avidec.c:1711
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:377
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:116
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:738
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:781
calculate_bitrate
static int calculate_bitrate(AVFormatContext *s)
Definition: avidec.c:458
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:238
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:362
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:2475
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:122
AV_CODEC_ID_XAN_DPCM
@ AV_CODEC_ID_XAN_DPCM
Definition: codec_id.h:451
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
av_exif_free
void av_exif_free(AVExifMetadata *ifd)
Frees all resources associated with the given EXIF metadata struct.
Definition: exif.c:658
dv.h
avi_read_seek
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: avidec.c:1869
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:461
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:803
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:717
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:1859
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:764
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:236
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
AVInputFormat
Definition: avformat.h:544
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:231
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:1250
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:60
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:549
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:201
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:460
AVIndexEntry::size
int size
Definition: avformat.h:609
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:600
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
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:231
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:348
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:257
key
const char * key
Definition: hwcontext_opencl.c:189
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:202
AVIStream::sub_pkt
AVPacket * sub_pkt
Definition: avidec.c:67
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
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:74
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:238
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:314
AV_CODEC_ID_AVRN
@ AV_CODEC_ID_AVRN
Definition: codec_id.h:264
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
AVFormatContext
Format I/O context.
Definition: avformat.h:1263
internal.h
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:571
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:767
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVSEEK_FLAG_BACKWARD
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2473
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
avpriv_dv_get_packet
int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
Definition: dv.c:733
metadata
Stream codec metadata
Definition: ogg-flac-chained-meta.txt:2
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:783
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:1236
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:826
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
AVSTREAM_PARSE_NONE
@ AVSTREAM_PARSE_NONE
Definition: avformat.h:588
AVIndexEntry::flags
int flags
Definition: avformat.h:608
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1305
avi_read_packet
static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: avidec.c:1476
FFStream::nb_index_entries
int nb_index_entries
Definition: internal.h:186
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
options
Definition: swscale.c:43
AVIStream::packet_size
int packet_size
Definition: avidec.c:50
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:824
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:396
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_EXIF_ASSUME_LE
@ AV_EXIF_ASSUME_LE
skip the TIFF header, assume little endian
Definition: exif.h:65
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:489
guess_ni_flag
static int guess_ni_flag(AVFormatContext *s)
Definition: avidec.c:1769
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:805
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:1319
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:462
startcode.h
av_sat_sub64
#define av_sat_sub64
Definition: common.h:142
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:733
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:589
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:143
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:163
AVDISCARD_DEFAULT
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition: defs.h:227
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:128
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
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:664
AVIContext::odml_read
int64_t odml_read
Definition: avidec.c:87
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:637
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:199
avi_probe
static int avi_probe(const AVProbeData *p)
Definition: avidec.c:2023
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:822
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:70
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:587
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:606
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:594
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
read_header
static int read_header(FFV1Context *f, RangeCoder *c)
Definition: ffv1dec.c:498
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:221
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:1202
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
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:629
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:253
resync
static int resync(AVFormatContext *s)
Definition: flvdec.c:1161
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:228
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_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:95
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:1812
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:98
AVIStream::prefix
int prefix
Definition: avidec.c:59
AV_CODEC_ID_XSUB
@ AV_CODEC_ID_XSUB
Definition: codec_id.h:575
tag
uint32_t tag
Definition: movenc.c:2032
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:756
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:744
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:236
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
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:1432
av_div_i
AVInteger av_div_i(AVInteger a, AVInteger b)
Return a/b.
Definition: integer.c:143
av_malloc
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:98
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:590
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:750
avpriv_dv_init_demux
DVDemuxContext * avpriv_dv_init_demux(AVFormatContext *s)
Definition: dv.c:728
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:615
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:599
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
AVPacket::stream_index
int stream_index
Definition: packet.h:590
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:321
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:184
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:356
desc
const char * desc
Definition: libsvtav1.c:82
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
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:37
avi_read_header
static int avi_read_header(AVFormatContext *s)
Definition: avidec.c:508
FFStream::request_probe
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
Definition: internal.h:198
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:90
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
ff_tlog
#define ff_tlog(a,...)
Definition: tableprint_vlc.h:29
AVPacket
This structure stores compressed data.
Definition: packet.h:565
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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:86
riff.h
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:608
FFInputFormat
Definition: demux.h:66
avio_rl64
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:741
bytestream.h
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:589
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
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:92
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:793
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
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:591
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:560
snprintf
#define snprintf
Definition: snprintf.h:34
avi_headers
static const char avi_headers[][8]
Definition: avidec.c:109
duration
static int64_t duration
Definition: ffplay.c:329
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:107
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:347
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:245
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:349