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