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