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  st->codecpar->height = FFABS(st->codecpar->height);
866 
867 // avio_skip(pb, size - 5 * 4);
868  break;
869  case AVMEDIA_TYPE_AUDIO:
870  ret = ff_get_wav_header(s, pb, st->codecpar, size, 0);
871  if (ret < 0)
872  return ret;
874  if (ast->sample_size && st->codecpar->block_align &&
875  ast->sample_size != st->codecpar->block_align) {
876  av_log(s,
878  "sample size (%d) != block align (%d)\n",
879  ast->sample_size,
880  st->codecpar->block_align);
881  ast->sample_size = st->codecpar->block_align;
882  }
883  /* 2-aligned
884  * (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
885  if (size & 1)
886  avio_skip(pb, 1);
887  /* Force parsing as several audio frames can be in
888  * one packet and timestamps refer to packet start. */
890  /* ADTS header is in extradata, AAC without header must be
891  * stored as exact frames. Parser not needed and it will
892  * fail. */
893  if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
896  // The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS
897  if (st->codecpar->codec_id == AV_CODEC_ID_FLAC)
899  /* AVI files with Xan DPCM audio (wrongly) declare PCM
900  * audio in the header but have Axan as stream_code_tag. */
901  if (ast->handler == AV_RL32("Axan")) {
903  st->codecpar->codec_tag = 0;
904  ast->dshow_block_align = 0;
905  }
906  if (amv_file_format) {
908  ast->dshow_block_align = 0;
909  }
910  if ((st->codecpar->codec_id == AV_CODEC_ID_AAC ||
912  st->codecpar->codec_id == AV_CODEC_ID_MP2 ) && ast->dshow_block_align <= 4 && ast->dshow_block_align) {
913  av_log(s, AV_LOG_DEBUG, "overriding invalid dshow_block_align of %d\n", ast->dshow_block_align);
914  ast->dshow_block_align = 0;
915  }
916  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 1024 && ast->sample_size == 1024 ||
917  st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 4096 && ast->sample_size == 4096 ||
918  st->codecpar->codec_id == AV_CODEC_ID_MP3 && ast->dshow_block_align == 1152 && ast->sample_size == 1152) {
919  av_log(s, AV_LOG_DEBUG, "overriding sample_size\n");
920  ast->sample_size = 0;
921  }
922  break;
925  sti->request_probe = 1;
926  avio_skip(pb, size);
927  break;
928  default:
931  st->codecpar->codec_tag = 0;
932  avio_skip(pb, size);
933  break;
934  }
935  }
936  break;
937  case MKTAG('s', 't', 'r', 'd'):
938  if (stream_index >= (unsigned)s->nb_streams
939  || s->streams[stream_index]->codecpar->extradata_size
940  || s->streams[stream_index]->codecpar->codec_tag == MKTAG('H','2','6','4')) {
941  avio_skip(pb, size);
942  } else {
943  uint64_t cur_pos = avio_tell(pb);
944  if (cur_pos < list_end)
945  size = FFMIN(size, list_end - cur_pos);
946  st = s->streams[stream_index];
947 
948  if (size<(1<<30)) {
949  if (st->codecpar->extradata) {
950  av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n");
951  }
952  if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0)
953  return ret;
954  }
955 
956  if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly
957  avio_r8(pb);
958 
960  if (ret < 0) {
961  av_log(s, AV_LOG_WARNING, "could not decoding EXIF data in stream header.\n");
962  }
963  }
964  break;
965  case MKTAG('i', 'n', 'd', 'x'):
966  pos = avio_tell(pb);
967  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !(s->flags & AVFMT_FLAG_IGNIDX) &&
968  avi->use_odml &&
969  read_odml_index(s, 0) < 0 &&
970  (s->error_recognition & AV_EF_EXPLODE))
971  return AVERROR_INVALIDDATA;
972  avio_seek(pb, pos + size, SEEK_SET);
973  break;
974  case MKTAG('v', 'p', 'r', 'p'):
975  if (stream_index < (unsigned)s->nb_streams && size > 9 * 4) {
976  AVRational active, active_aspect;
977 
978  st = s->streams[stream_index];
979  avio_rl32(pb);
980  avio_rl32(pb);
981  avio_rl32(pb);
982  avio_rl32(pb);
983  avio_rl32(pb);
984 
985  active_aspect.den = avio_rl16(pb);
986  active_aspect.num = avio_rl16(pb);
987  active.num = avio_rl32(pb);
988  active.den = avio_rl32(pb);
989  avio_rl32(pb); // nbFieldsPerFrame
990 
991  if (active_aspect.num && active_aspect.den &&
992  active.num && active.den) {
993  st->sample_aspect_ratio = av_div_q(active_aspect, active);
994  av_log(s, AV_LOG_TRACE, "vprp %d/%d %d/%d\n",
995  active_aspect.num, active_aspect.den,
996  active.num, active.den);
997  }
998  size -= 9 * 4;
999  }
1000  avio_skip(pb, size);
1001  break;
1002  case MKTAG('s', 't', 'r', 'n'):
1003  case MKTAG('i', 's', 'b', 'j'):
1004  case MKTAG('i', 'n', 'a', 'm'):
1005  case MKTAG('i', 'a', 'r', 't'):
1006  case MKTAG('i', 'c', 'o', 'p'):
1007  case MKTAG('i', 'c', 'm', 't'):
1008  case MKTAG('i', 'g', 'n', 'r'):
1009  case MKTAG('i', 'p', 'o', 'd'):
1010  case MKTAG('i', 's', 'o', 'f'):
1011  if (s->nb_streams) {
1012  ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
1013  if (ret < 0)
1014  return ret;
1015  break;
1016  }
1017  default:
1018  if (size > 1000000) {
1020  "Something went wrong during header parsing, "
1021  "tag %s has size %u, "
1022  "I will ignore it and try to continue anyway.\n",
1023  av_fourcc2str(tag), size);
1024  if (s->error_recognition & AV_EF_EXPLODE)
1025  return AVERROR_INVALIDDATA;
1026  avi->movi_list = avio_tell(pb) - 4;
1027  avi->movi_end = avi->fsize;
1028  goto end_of_header;
1029  }
1030  /* Do not fail for very large idx1 tags */
1031  case MKTAG('i', 'd', 'x', '1'):
1032  /* skip tag */
1033  size += (size & 1);
1034  avio_skip(pb, size);
1035  break;
1036  }
1037  }
1038 
1039 end_of_header:
1040  /* check stream number */
1041  if (stream_index != s->nb_streams - 1)
1042  return AVERROR_INVALIDDATA;
1043 
1044  if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))
1045  avi_load_index(s);
1047  avi->index_loaded |= 1;
1048 
1049  if ((ret = guess_ni_flag(s)) < 0)
1050  return ret;
1051 
1052  avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS);
1053 
1054  dict_entry = av_dict_get(s->metadata, "ISFT", NULL, 0);
1055  if (dict_entry && !strcmp(dict_entry->value, "PotEncoder"))
1056  for (i = 0; i < s->nb_streams; i++) {
1057  AVStream *st = s->streams[i];
1061  }
1062 
1063  for (i = 0; i < s->nb_streams; i++) {
1064  AVStream *st = s->streams[i];
1065  if (ffstream(st)->nb_index_entries)
1066  break;
1067  }
1068  // DV-in-AVI cannot be non-interleaved, if set this must be
1069  // a mis-detection.
1070  if (avi->dv_demux)
1071  avi->non_interleaved = 0;
1072  if (i == s->nb_streams && avi->non_interleaved) {
1074  "Non-interleaved AVI without index, switching to interleaved\n");
1075  avi->non_interleaved = 0;
1076  }
1077 
1078  if (avi->non_interleaved) {
1079  av_log(s, AV_LOG_INFO, "non-interleaved AVI\n");
1080  clean_index(s);
1081  }
1082 
1085 
1086  return 0;
1087 }
1088 
1090 {
1091  if (pkt->size >= 7 &&
1092  pkt->size < INT_MAX - AVPROBE_PADDING_SIZE &&
1093  !strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data + 5) == 2) {
1094  uint8_t desc[256];
1095  int score = AVPROBE_SCORE_EXTENSION, ret;
1096  AVIStream *ast = st->priv_data;
1097  const AVInputFormat *sub_demuxer;
1098  AVRational time_base;
1099  int size;
1100  AVProbeData pd;
1101  unsigned int desc_len;
1103  pkt->size - 7,
1104  0, NULL, NULL, NULL, NULL);
1105  if (!pb)
1106  goto error;
1107 
1108  desc_len = avio_rl32(pb);
1109 
1110  if (desc_len > pb->buf_end - pb->buf_ptr)
1111  goto error;
1112 
1113  ret = avio_get_str16le(pb, desc_len, desc, sizeof(desc));
1114  avio_skip(pb, desc_len - ret);
1115  if (*desc)
1116  av_dict_set(&st->metadata, "title", desc, 0);
1117 
1118  avio_rl16(pb); /* flags? */
1119  avio_rl32(pb); /* data size */
1120 
1121  size = pb->buf_end - pb->buf_ptr;
1123  .buf_size = size };
1124  if (!pd.buf)
1125  goto error;
1126  memcpy(pd.buf, pb->buf_ptr, size);
1127  sub_demuxer = av_probe_input_format2(&pd, 1, &score);
1128  av_freep(&pd.buf);
1129  if (!sub_demuxer)
1130  goto error;
1131 
1132  if (strcmp(sub_demuxer->name, "srt") && strcmp(sub_demuxer->name, "ass"))
1133  goto error;
1134 
1135  if (!(ast->sub_pkt = av_packet_alloc()))
1136  goto error;
1137 
1138  if (!(ast->sub_ctx = avformat_alloc_context()))
1139  goto error;
1140 
1141  ast->sub_ctx->pb = pb;
1142 
1143  if (ff_copy_whiteblacklists(ast->sub_ctx, s) < 0)
1144  goto error;
1145 
1146  if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) {
1147  if (ast->sub_ctx->nb_streams != 1)
1148  goto error;
1149  ff_read_packet(ast->sub_ctx, ast->sub_pkt);
1151  time_base = ast->sub_ctx->streams[0]->time_base;
1152  avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
1153  }
1154  ast->sub_buffer = pkt->buf;
1155  pkt->buf = NULL;
1157  return 1;
1158 
1159 error:
1160  av_packet_free(&ast->sub_pkt);
1161  av_freep(&ast->sub_ctx);
1162  avio_context_free(&pb);
1163  }
1164  return 0;
1165 }
1166 
1168  AVPacket *pkt)
1169 {
1170  AVIStream *ast, *next_ast = next_st->priv_data;
1171  int64_t ts, next_ts, ts_min = INT64_MAX;
1172  AVStream *st, *sub_st = NULL;
1173  int i;
1174 
1175  next_ts = av_rescale_q(next_ast->frame_offset, next_st->time_base,
1176  AV_TIME_BASE_Q);
1177 
1178  for (i = 0; i < s->nb_streams; i++) {
1179  st = s->streams[i];
1180  ast = st->priv_data;
1181  if (st->discard < AVDISCARD_ALL && ast && ast->sub_pkt && ast->sub_pkt->data) {
1182  ts = av_rescale_q(ast->sub_pkt->dts, st->time_base, AV_TIME_BASE_Q);
1183  if (ts <= next_ts && ts < ts_min) {
1184  ts_min = ts;
1185  sub_st = st;
1186  }
1187  }
1188  }
1189 
1190  if (sub_st) {
1191  ast = sub_st->priv_data;
1193  pkt->stream_index = sub_st->index;
1194 
1195  if (ff_read_packet(ast->sub_ctx, ast->sub_pkt) < 0)
1196  ast->sub_pkt->data = NULL;
1197  }
1198  return sub_st;
1199 }
1200 
1201 static int get_stream_idx(const unsigned *d)
1202 {
1203  if (d[0] >= '0' && d[0] <= '9' &&
1204  d[1] >= '0' && d[1] <= '9') {
1205  return (d[0] - '0') * 10 + (d[1] - '0');
1206  } else {
1207  return 100; // invalid stream ID
1208  }
1209 }
1210 
1211 /**
1212  *
1213  * @param exit_early set to 1 to just gather packet position without making the changes needed to actually read & return the packet
1214  */
1215 static int avi_sync(AVFormatContext *s, int exit_early)
1216 {
1217  AVIContext *avi = s->priv_data;
1218  AVIOContext *pb = s->pb;
1219  int n;
1220  unsigned int d[8];
1221  unsigned int size;
1222  int64_t i, sync;
1223 
1224 start_sync:
1225  memset(d, -1, sizeof(d));
1226  for (i = sync = avio_tell(pb); !avio_feof(pb); i++) {
1227  int j;
1228 
1229  for (j = 0; j < 7; j++)
1230  d[j] = d[j + 1];
1231  d[7] = avio_r8(pb);
1232 
1233  size = d[4] + (d[5] << 8) + (d[6] << 16) + (d[7] << 24);
1234 
1235  n = get_stream_idx(d + 2);
1236  ff_tlog(s, "%X %X %X %X %X %X %X %X %"PRId64" %u %d\n",
1237  d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
1238  if (i*(avi->io_fsize>0) + (uint64_t)size > avi->fsize || d[0] > 127)
1239  continue;
1240 
1241  // parse ix##
1242  if ((d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) ||
1243  // parse JUNK
1244  (d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') ||
1245  (d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1') ||
1246  (d[0] == 'i' && d[1] == 'n' && d[2] == 'd' && d[3] == 'x')) {
1247  avio_skip(pb, size);
1248  goto start_sync;
1249  }
1250 
1251  // parse stray LIST
1252  if (d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T') {
1253  avio_skip(pb, 4);
1254  goto start_sync;
1255  }
1256 
1257  n = get_stream_idx(d);
1258 
1259  if (!((i - avi->last_pkt_pos) & 1) &&
1260  get_stream_idx(d + 1) < s->nb_streams)
1261  continue;
1262 
1263  // detect ##ix chunk and skip
1264  if (d[2] == 'i' && d[3] == 'x' && n < s->nb_streams) {
1265  avio_skip(pb, size);
1266  goto start_sync;
1267  }
1268 
1269  if (d[2] == 'w' && d[3] == 'c' && n < s->nb_streams) {
1270  avio_skip(pb, 16 * 3 + 8);
1271  goto start_sync;
1272  }
1273 
1274  if (avi->dv_demux && n != 0)
1275  continue;
1276 
1277  // parse ##dc/##wb
1278  if (n < s->nb_streams) {
1279  AVStream *st;
1280  AVIStream *ast;
1281  st = s->streams[n];
1282  ast = st->priv_data;
1283 
1284  if (!ast) {
1285  av_log(s, AV_LOG_WARNING, "Skipping foreign stream %d packet\n", n);
1286  continue;
1287  }
1288 
1289  if (s->nb_streams >= 2) {
1290  AVStream *st1 = s->streams[1];
1291  AVIStream *ast1 = st1->priv_data;
1292  // workaround for broken small-file-bug402.avi
1293  if (ast1 && d[2] == 'w' && d[3] == 'b'
1294  && n == 0
1295  && st ->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
1297  && ast->prefix == 'd'*256+'c'
1298  && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count)
1299  ) {
1300  n = 1;
1301  st = st1;
1302  ast = ast1;
1304  "Invalid stream + prefix combination, assuming audio.\n");
1305  }
1306  }
1307 
1308  if (d[2] == 'p' && d[3] == 'c' && size <= 4 * 256 + 4) {
1309  int k = avio_r8(pb);
1310  int last = (k + avio_r8(pb) - 1) & 0xFF;
1311 
1312  avio_rl16(pb); // flags
1313 
1314  // b + (g << 8) + (r << 16);
1315  for (; k <= last; k++)
1316  ast->pal[k] = 0xFFU<<24 | avio_rb32(pb)>>8;
1317 
1318  ast->has_pal = 1;
1319  goto start_sync;
1320  } else if (((ast->prefix_count < 5 || sync + 9 > i) &&
1321  d[2] < 128 && d[3] < 128) ||
1322  d[2] * 256 + d[3] == ast->prefix /* ||
1323  (d[2] == 'd' && d[3] == 'c') ||
1324  (d[2] == 'w' && d[3] == 'b') */) {
1325  if (exit_early)
1326  return 0;
1327  if (d[2] * 256 + d[3] == ast->prefix)
1328  ast->prefix_count++;
1329  else {
1330  ast->prefix = d[2] * 256 + d[3];
1331  ast->prefix_count = 0;
1332  }
1333 
1334  if (!avi->dv_demux &&
1335  ((st->discard >= AVDISCARD_DEFAULT && size == 0) /* ||
1336  // FIXME: needs a little reordering
1337  (st->discard >= AVDISCARD_NONKEY &&
1338  !(pkt->flags & AV_PKT_FLAG_KEY)) */
1339  || st->discard >= AVDISCARD_ALL)) {
1340 
1341  ast->frame_offset += get_duration(ast, size);
1342  avio_skip(pb, size);
1343  goto start_sync;
1344  }
1345 
1346  avi->stream_index = n;
1347  ast->packet_size = size + 8;
1348  ast->remaining = size;
1349 
1350  if (size) {
1351  FFStream *const sti = ffstream(st);
1352  uint64_t pos = avio_tell(pb) - 8;
1353  if (!sti->index_entries || !sti->nb_index_entries ||
1354  sti->index_entries[sti->nb_index_entries - 1].pos < pos) {
1356  0, AVINDEX_KEYFRAME);
1357  }
1358  }
1359  return 0;
1360  }
1361  }
1362  }
1363 
1364  if (pb->error)
1365  return pb->error;
1366  return AVERROR_EOF;
1367 }
1368 
1370 {
1371  AVIContext *avi = s->priv_data;
1372  int best_stream_index = 0;
1373  AVStream *best_st = NULL;
1374  FFStream *best_sti;
1375  AVIStream *best_ast;
1376  int64_t best_ts = INT64_MAX;
1377  int i;
1378 
1379  for (i = 0; i < s->nb_streams; i++) {
1380  AVStream *st = s->streams[i];
1381  FFStream *const sti = ffstream(st);
1382  AVIStream *ast = st->priv_data;
1383  int64_t ts = ast->frame_offset;
1384  int64_t last_ts;
1385 
1386  if (!sti->nb_index_entries)
1387  continue;
1388 
1389  last_ts = sti->index_entries[sti->nb_index_entries - 1].timestamp;
1390  if (!ast->remaining && ts > last_ts)
1391  continue;
1392 
1393  ts = av_rescale_q(ts, st->time_base,
1394  (AVRational) { FFMAX(1, ast->sample_size),
1395  AV_TIME_BASE });
1396 
1397  av_log(s, AV_LOG_TRACE, "%"PRId64" %d/%d %"PRId64"\n", ts,
1398  st->time_base.num, st->time_base.den, ast->frame_offset);
1399  if (ts < best_ts) {
1400  best_ts = ts;
1401  best_st = st;
1402  best_stream_index = i;
1403  }
1404  }
1405  if (!best_st)
1406  return AVERROR_EOF;
1407 
1408  best_sti = ffstream(best_st);
1409  best_ast = best_st->priv_data;
1410  best_ts = best_ast->frame_offset;
1411  if (best_ast->remaining) {
1412  i = av_index_search_timestamp(best_st,
1413  best_ts,
1414  AVSEEK_FLAG_ANY |
1416  } else {
1417  i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
1418  if (i >= 0)
1419  best_ast->frame_offset = best_sti->index_entries[i].timestamp;
1420  }
1421 
1422  if (i >= 0) {
1423  int64_t pos = best_sti->index_entries[i].pos;
1424  pos += best_ast->packet_size - best_ast->remaining;
1425  if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
1426  return AVERROR_EOF;
1427 
1428  av_assert0(best_ast->remaining <= best_ast->packet_size);
1429 
1430  avi->stream_index = best_stream_index;
1431  if (!best_ast->remaining)
1432  best_ast->packet_size =
1433  best_ast->remaining = best_sti->index_entries[i].size;
1434  }
1435  else
1436  return AVERROR_EOF;
1437 
1438  return 0;
1439 }
1440 
1442 {
1443  AVIContext *avi = s->priv_data;
1444  AVIOContext *pb = s->pb;
1445  int err;
1446 
1447  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1448  int size = avpriv_dv_get_packet(avi->dv_demux, pkt);
1449  if (size >= 0)
1450  return size;
1451  else
1452  goto resync;
1453  }
1454 
1455  if (avi->non_interleaved) {
1456  err = ni_prepare_read(s);
1457  if (err < 0)
1458  return err;
1459  }
1460 
1461 resync:
1462  if (avi->stream_index >= 0) {
1463  AVStream *st = s->streams[avi->stream_index];
1464  FFStream *const sti = ffstream(st);
1465  AVIStream *ast = st->priv_data;
1466  int dv_demux = CONFIG_DV_DEMUXER && avi->dv_demux;
1467  int size, err;
1468 
1469  if (get_subtitle_pkt(s, st, pkt))
1470  return 0;
1471 
1472  // minorityreport.AVI block_align=1024 sample_size=1 IMA-ADPCM
1473  if (ast->sample_size <= 1)
1474  size = INT_MAX;
1475  else if (ast->sample_size < 32)
1476  // arbitrary multiplier to avoid tiny packets for raw PCM data
1477  size = 1024 * ast->sample_size;
1478  else
1479  size = ast->sample_size;
1480 
1481  if (size > ast->remaining)
1482  size = ast->remaining;
1483  avi->last_pkt_pos = avio_tell(pb);
1484  err = av_get_packet(pb, pkt, size);
1485  if (err < 0)
1486  return err;
1487  size = err;
1488 
1489  if (ast->has_pal && pkt->size < (unsigned)INT_MAX / 2 && !dv_demux) {
1490  uint8_t *pal;
1493  AVPALETTE_SIZE);
1494  if (!pal) {
1496  "Failed to allocate data for palette\n");
1497  } else {
1498  memcpy(pal, ast->pal, AVPALETTE_SIZE);
1499  ast->has_pal = 0;
1500  }
1501  }
1502 
1503  if (CONFIG_DV_DEMUXER && dv_demux) {
1505  pkt->data, pkt->size, pkt->pos);
1507  if (size < 0)
1509  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
1510  !st->codecpar->codec_tag && read_gab2_sub(s, st, pkt)) {
1511  ast->frame_offset++;
1512  avi->stream_index = -1;
1513  ast->remaining = 0;
1514  goto resync;
1515  } else {
1516  /* XXX: How to handle B-frames in AVI? */
1517  pkt->dts = ast->frame_offset;
1518 // pkt->dts += ast->start;
1519  if (ast->sample_size)
1520  pkt->dts /= ast->sample_size;
1521  pkt->stream_index = avi->stream_index;
1522 
1523  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->index_entries) {
1524  AVIndexEntry *e;
1525  int index;
1526 
1528  e = &sti->index_entries[index];
1529 
1530  if (index >= 0 && e->timestamp == ast->frame_offset) {
1531  if (index == sti->nb_index_entries-1) {
1532  int key=1;
1533  uint32_t state=-1;
1534  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1535  const uint8_t *ptr = pkt->data, *end = ptr + FFMIN(size, 256);
1536  while (ptr < end) {
1537  ptr = avpriv_find_start_code(ptr, end, &state);
1538  if (state == 0x1B6 && ptr < end) {
1539  key = !(*ptr & 0xC0);
1540  break;
1541  }
1542  }
1543  }
1544  if (!key)
1545  e->flags &= ~AVINDEX_KEYFRAME;
1546  }
1547  if (e->flags & AVINDEX_KEYFRAME)
1549  }
1550  } else {
1552  }
1553  ast->frame_offset += get_duration(ast, pkt->size);
1554  }
1555  ast->remaining -= err;
1556  if (!ast->remaining) {
1557  avi->stream_index = -1;
1558  ast->packet_size = 0;
1559  }
1560 
1561  if (!avi->non_interleaved && pkt->pos >= 0 && ast->seek_pos > pkt->pos) {
1563  goto resync;
1564  }
1565  ast->seek_pos= 0;
1566 
1567  if (!avi->non_interleaved && sti->nb_index_entries > 1 && avi->index_loaded > 1) {
1568  int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q);
1569 
1570  if (avi->dts_max < dts) {
1571  avi->dts_max = dts;
1572  } else if (avi->dts_max - (uint64_t)dts > 2*AV_TIME_BASE) {
1573  avi->non_interleaved= 1;
1574  av_log(s, AV_LOG_INFO, "Switching to NI mode, due to poor interleaving\n");
1575  }
1576  }
1577 
1578  return 0;
1579  }
1580 
1581  if ((err = avi_sync(s, 0)) < 0)
1582  return err;
1583  goto resync;
1584 }
1585 
1586 /* XXX: We make the implicit supposition that the positions are sorted
1587  * for each stream. */
1589 {
1590  AVIContext *avi = s->priv_data;
1591  AVIOContext *pb = s->pb;
1592  int nb_index_entries, i;
1593  AVStream *st;
1594  AVIStream *ast;
1595  int64_t pos;
1596  unsigned int index, tag, flags, len, first_packet = 1;
1597  int64_t last_pos = -1;
1598  unsigned last_idx = -1;
1599  int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1600  int anykey = 0;
1601 
1602  nb_index_entries = size / 16;
1603  if (nb_index_entries <= 0)
1604  return AVERROR_INVALIDDATA;
1605 
1606  idx1_pos = avio_tell(pb);
1607  avio_seek(pb, avi->movi_list + 4, SEEK_SET);
1608  if (avi_sync(s, 1) == 0)
1609  first_packet_pos = avio_tell(pb) - 8;
1610  avi->stream_index = -1;
1611  avio_seek(pb, idx1_pos, SEEK_SET);
1612 
1613  if (s->nb_streams == 1 && s->streams[0]->codecpar->codec_tag == AV_RL32("MMES")) {
1614  first_packet_pos = 0;
1615  data_offset = avi->movi_list;
1616  }
1617 
1618  /* Read the entries and sort them in each stream component. */
1619  for (i = 0; i < nb_index_entries; i++) {
1620  if (avio_feof(pb))
1621  return -1;
1622 
1623  tag = avio_rl32(pb);
1624  flags = avio_rl32(pb);
1625  pos = avio_rl32(pb);
1626  len = avio_rl32(pb);
1627  av_log(s, AV_LOG_TRACE, "%d: tag=0x%x flags=0x%x pos=0x%"PRIx64" len=%d/",
1628  i, tag, flags, pos, len);
1629 
1630  index = ((tag & 0xff) - '0') * 10;
1631  index += (tag >> 8 & 0xff) - '0';
1632  if (index >= s->nb_streams)
1633  continue;
1634  st = s->streams[index];
1635  ast = st->priv_data;
1636 
1637  /* Skip 'xxpc' palette change entries in the index until a logic
1638  * to process these is properly implemented. */
1639  if ((tag >> 16 & 0xff) == 'p' && (tag >> 24 & 0xff) == 'c')
1640  continue;
1641 
1642  if (first_packet && first_packet_pos) {
1643  if (avi->movi_list + 4 != pos || pos + 500 > first_packet_pos)
1644  data_offset = first_packet_pos - pos;
1645  first_packet = 0;
1646  }
1647  pos += data_offset;
1648 
1649  av_log(s, AV_LOG_TRACE, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
1650 
1651  // even if we have only a single stream, we should
1652  // switch to non-interleaved to get correct timestamps
1653  if (last_pos == pos)
1654  avi->non_interleaved = 1;
1655  if (last_idx != pos && len) {
1656  av_add_index_entry(st, pos, ast->cum_len, len, 0,
1657  (flags & AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);
1658  last_idx= pos;
1659  }
1660  ast->cum_len += get_duration(ast, len);
1661  last_pos = pos;
1662  anykey |= flags&AVIIF_INDEX;
1663  }
1664  if (!anykey) {
1665  for (index = 0; index < s->nb_streams; index++) {
1666  FFStream *const sti = ffstream(s->streams[index]);
1667  if (sti->nb_index_entries)
1669  }
1670  }
1671  return 0;
1672 }
1673 
1674 /* Scan the index and consider any file with streams more than
1675  * 2 seconds or 64MB apart non-interleaved. */
1677 {
1678  int64_t min_pos, pos;
1679  int i;
1680  int *idx = av_calloc(s->nb_streams, sizeof(*idx));
1681  if (!idx)
1682  return AVERROR(ENOMEM);
1683  for (min_pos = pos = 0; min_pos != INT64_MAX; pos = min_pos + 1LU) {
1684  int64_t max_dts = INT64_MIN / 2;
1685  int64_t min_dts = INT64_MAX / 2;
1686  int64_t max_buffer = 0;
1687 
1688  min_pos = INT64_MAX;
1689 
1690  for (i = 0; i < s->nb_streams; i++) {
1691  AVStream *st = s->streams[i];
1692  AVIStream *ast = st->priv_data;
1693  FFStream *const sti = ffstream(st);
1694  int n = sti->nb_index_entries;
1695  while (idx[i] < n && sti->index_entries[idx[i]].pos < pos)
1696  idx[i]++;
1697  if (idx[i] < n) {
1698  int64_t dts;
1699  dts = av_rescale_q(sti->index_entries[idx[i]].timestamp /
1700  FFMAX(ast->sample_size, 1),
1701  st->time_base, AV_TIME_BASE_Q);
1702  min_dts = FFMIN(min_dts, dts);
1703  min_pos = FFMIN(min_pos, sti->index_entries[idx[i]].pos);
1704  }
1705  }
1706  for (i = 0; i < s->nb_streams; i++) {
1707  AVStream *st = s->streams[i];
1708  FFStream *const sti = ffstream(st);
1709  AVIStream *ast = st->priv_data;
1710 
1711  if (idx[i] && min_dts != INT64_MAX / 2) {
1712  int64_t dts, delta_dts;
1713  dts = av_rescale_q(sti->index_entries[idx[i] - 1].timestamp /
1714  FFMAX(ast->sample_size, 1),
1715  st->time_base, AV_TIME_BASE_Q);
1716  delta_dts = av_sat_sub64(dts, min_dts);
1717  max_dts = FFMAX(max_dts, dts);
1718  max_buffer = FFMAX(max_buffer,
1719  av_rescale(delta_dts,
1720  st->codecpar->bit_rate,
1721  AV_TIME_BASE));
1722  }
1723  }
1724  if (av_sat_sub64(max_dts, min_dts) > 2 * AV_TIME_BASE ||
1725  max_buffer > 1024 * 1024 * 8 * 8) {
1726  av_free(idx);
1727  return 1;
1728  }
1729  }
1730  av_free(idx);
1731  return 0;
1732 }
1733 
1735 {
1736  int i;
1737  int64_t last_start = 0;
1738  int64_t first_end = INT64_MAX;
1739  int64_t oldpos = avio_tell(s->pb);
1740 
1741  for (i = 0; i < s->nb_streams; i++) {
1742  AVStream *st = s->streams[i];
1743  FFStream *const sti = ffstream(st);
1744  int n = sti->nb_index_entries;
1745  unsigned int size;
1746 
1747  if (n <= 0)
1748  continue;
1749 
1750  if (n >= 2) {
1751  int64_t pos = sti->index_entries[0].pos;
1752  unsigned tag[2];
1753  avio_seek(s->pb, pos, SEEK_SET);
1754  tag[0] = avio_r8(s->pb);
1755  tag[1] = avio_r8(s->pb);
1756  avio_rl16(s->pb);
1757  size = avio_rl32(s->pb);
1758  if (get_stream_idx(tag) == i && pos + size > sti->index_entries[1].pos)
1759  last_start = INT64_MAX;
1760  if (get_stream_idx(tag) == i && size == sti->index_entries[0].size + 8)
1761  last_start = INT64_MAX;
1762  }
1763 
1764  if (sti->index_entries[0].pos > last_start)
1765  last_start = sti->index_entries[0].pos;
1766  if (sti->index_entries[n - 1].pos < first_end)
1767  first_end = sti->index_entries[n - 1].pos;
1768  }
1769  avio_seek(s->pb, oldpos, SEEK_SET);
1770 
1771  if (last_start > first_end)
1772  return 1;
1773 
1774  return check_stream_max_drift(s);
1775 }
1776 
1778 {
1779  AVIContext *avi = s->priv_data;
1780  AVIOContext *pb = s->pb;
1781  uint32_t tag, size;
1782  int64_t pos = avio_tell(pb);
1783  int64_t next;
1784  int ret = -1;
1785 
1786  if (avio_seek(pb, avi->movi_end, SEEK_SET) < 0)
1787  goto the_end; // maybe truncated file
1788  av_log(s, AV_LOG_TRACE, "movi_end=0x%"PRIx64"\n", avi->movi_end);
1789  for (;;) {
1790  tag = avio_rl32(pb);
1791  size = avio_rl32(pb);
1792  if (avio_feof(pb))
1793  break;
1794  next = avio_tell(pb);
1795  if (next < 0 || next > INT64_MAX - size - (size & 1))
1796  break;
1797  next += size + (size & 1LL);
1798 
1799  if (tag == MKTAG('i', 'd', 'x', '1') &&
1800  avi_read_idx1(s, size) >= 0) {
1801  avi->index_loaded=2;
1802  ret = 0;
1803  }else if (tag == MKTAG('L', 'I', 'S', 'T')) {
1804  uint32_t tag1 = avio_rl32(pb);
1805 
1806  if (tag1 == MKTAG('I', 'N', 'F', 'O'))
1807  ff_read_riff_info(s, size - 4);
1808  }else if (!ret)
1809  break;
1810 
1811  if (avio_seek(pb, next, SEEK_SET) < 0)
1812  break; // something is wrong here
1813  }
1814 
1815 the_end:
1816  avio_seek(pb, pos, SEEK_SET);
1817  return ret;
1818 }
1819 
1820 static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
1821 {
1822  AVIStream *ast2 = st2->priv_data;
1823  int64_t ts2 = av_rescale_q(timestamp, st->time_base, st2->time_base);
1824  av_packet_unref(ast2->sub_pkt);
1825  if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 ||
1826  avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
1827  ff_read_packet(ast2->sub_ctx, ast2->sub_pkt);
1828 }
1829 
1830 static int avi_read_seek(AVFormatContext *s, int stream_index,
1831  int64_t timestamp, int flags)
1832 {
1833  AVIContext *avi = s->priv_data;
1834  AVStream *st;
1835  FFStream *sti;
1836  int i, index;
1837  int64_t pos, pos_min;
1838  AVIStream *ast;
1839 
1840  /* Does not matter which stream is requested dv in avi has the
1841  * stream information in the first video stream.
1842  */
1843  if (avi->dv_demux)
1844  stream_index = 0;
1845 
1846  if (!avi->index_loaded) {
1847  /* we only load the index on demand */
1848  avi_load_index(s);
1849  avi->index_loaded |= 1;
1850  }
1851  av_assert0(stream_index >= 0);
1852 
1853  st = s->streams[stream_index];
1854  sti = ffstream(st);
1855  ast = st->priv_data;
1857  timestamp * FFMAX(ast->sample_size, 1),
1858  flags);
1859  if (index < 0) {
1860  if (sti->nb_index_entries > 0)
1861  av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n",
1862  timestamp * FFMAX(ast->sample_size, 1),
1863  sti->index_entries[0].timestamp,
1864  sti->index_entries[sti->nb_index_entries - 1].timestamp);
1865  return AVERROR_INVALIDDATA;
1866  }
1867 
1868  /* find the position */
1869  pos = sti->index_entries[index].pos;
1870  timestamp = sti->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
1871 
1872  av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n",
1873  timestamp, index, sti->index_entries[index].timestamp);
1874 
1875  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1876  /* One and only one real stream for DV in AVI, and it has video */
1877  /* offsets. Calling with other stream indexes should have failed */
1878  /* the av_index_search_timestamp call above. */
1879 
1880  if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1881  return -1;
1882 
1883  /* Feed the DV video stream version of the timestamp to the */
1884  /* DV demux so it can synthesize correct timestamps. */
1885  ff_dv_offset_reset(avi->dv_demux, timestamp);
1886 
1887  avi->stream_index = -1;
1888  return 0;
1889  }
1890 
1891  pos_min = pos;
1892  for (i = 0; i < s->nb_streams; i++) {
1893  AVStream *st2 = s->streams[i];
1894  FFStream *const sti2 = ffstream(st2);
1895  AVIStream *ast2 = st2->priv_data;
1896 
1897  ast2->packet_size =
1898  ast2->remaining = 0;
1899 
1900  if (ast2->sub_ctx) {
1901  seek_subtitle(st, st2, timestamp);
1902  continue;
1903  }
1904 
1905  if (sti2->nb_index_entries <= 0)
1906  continue;
1907 
1908 // av_assert1(st2->codecpar->block_align);
1910  av_rescale_q(timestamp,
1911  st->time_base,
1912  st2->time_base) *
1913  FFMAX(ast2->sample_size, 1),
1914  flags |
1917  if (index < 0)
1918  index = 0;
1919  ast2->seek_pos = sti2->index_entries[index].pos;
1920  pos_min = FFMIN(pos_min,ast2->seek_pos);
1921  }
1922  for (i = 0; i < s->nb_streams; i++) {
1923  AVStream *st2 = s->streams[i];
1924  FFStream *const sti2 = ffstream(st2);
1925  AVIStream *ast2 = st2->priv_data;
1926 
1927  if (ast2->sub_ctx || sti2->nb_index_entries <= 0)
1928  continue;
1929 
1931  st2,
1932  av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
1934  if (index < 0)
1935  index = 0;
1936  while (!avi->non_interleaved && index > 0 && sti2->index_entries[index-1].pos >= pos_min)
1937  index--;
1938  ast2->frame_offset = sti2->index_entries[index].timestamp;
1939  }
1940 
1941  /* do the seek */
1942  if (avio_seek(s->pb, pos_min, SEEK_SET) < 0) {
1943  av_log(s, AV_LOG_ERROR, "Seek failed\n");
1944  return -1;
1945  }
1946  avi->stream_index = -1;
1947  avi->dts_max = INT_MIN;
1948  return 0;
1949 }
1950 
1952 {
1953  int i;
1954  AVIContext *avi = s->priv_data;
1955 
1956  for (i = 0; i < s->nb_streams; i++) {
1957  AVStream *st = s->streams[i];
1958  AVIStream *ast = st->priv_data;
1959  if (ast) {
1960  if (ast->sub_ctx) {
1961  av_freep(&ast->sub_ctx->pb);
1963  }
1964  av_buffer_unref(&ast->sub_buffer);
1965  av_packet_free(&ast->sub_pkt);
1966  }
1967  }
1968 
1969  av_freep(&avi->dv_demux);
1970 
1971  return 0;
1972 }
1973 
1974 static int avi_probe(const AVProbeData *p)
1975 {
1976  int i;
1977 
1978  /* check file header */
1979  for (i = 0; avi_headers[i][0]; i++)
1980  if (AV_RL32(p->buf ) == AV_RL32(avi_headers[i] ) &&
1981  AV_RL32(p->buf + 8) == AV_RL32(avi_headers[i] + 4))
1982  return AVPROBE_SCORE_MAX;
1983 
1984  return 0;
1985 }
1986 
1988  .name = "avi",
1989  .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
1990  .priv_data_size = sizeof(AVIContext),
1991  .flags_internal = FF_FMT_INIT_CLEANUP,
1992  .extensions = "avi",
1993  .read_probe = avi_probe,
1998  .priv_class = &demuxer_class,
1999 };
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:1369
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:1588
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
state
static struct @321 state
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:1951
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:1089
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:1676
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:1830
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:1820
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:1215
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:1201
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:1441
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:1734
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:1987
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:759
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
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:1974
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:1167
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:1777
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:1195
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