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  offset = avio_rl64(pb);
244  avio_rl32(pb); /* size */
245  duration = avio_rl32(pb);
246 
247  if (avio_feof(pb))
248  return AVERROR_INVALIDDATA;
249 
250  pos = avio_tell(pb);
251 
252  if (avi->odml_depth > MAX_ODML_DEPTH) {
253  av_log(s, AV_LOG_ERROR, "Too deeply nested ODML indexes\n");
254  return AVERROR_INVALIDDATA;
255  }
256 
257  if (avio_seek(pb, offset + 8, SEEK_SET) < 0)
258  return -1;
259  avi->odml_depth++;
260  read_odml_index(s, frame_num);
261  avi->odml_depth--;
262  frame_num += duration;
263 
264  if (avio_seek(pb, pos, SEEK_SET) < 0) {
265  av_log(s, AV_LOG_ERROR, "Failed to restore position after reading index\n");
266  return -1;
267  }
268 
269  }
270  }
271  avi->index_loaded = 2;
272  return 0;
273 }
274 
276 {
277  int i;
278  int64_t j;
279 
280  for (i = 0; i < s->nb_streams; i++) {
281  AVStream *st = s->streams[i];
282  FFStream *const sti = ffstream(st);
283  AVIStream *ast = st->priv_data;
284  int n = sti->nb_index_entries;
285  int max = ast->sample_size;
286  int64_t pos, size, ts;
287 
288  if (n != 1 || ast->sample_size == 0)
289  continue;
290 
291  while (max < 1024)
292  max += max;
293 
294  pos = sti->index_entries[0].pos;
295  size = sti->index_entries[0].size;
296  ts = sti->index_entries[0].timestamp;
297 
298  for (j = 0; j < size; j += max)
299  av_add_index_entry(st, pos + j, ts + j, FFMIN(max, size - j), 0,
301  }
302 }
303 
304 static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag,
305  uint32_t size)
306 {
307  AVIOContext *pb = s->pb;
308  char key[5] = { 0 };
309  char *value;
310 
311  size += (size & 1);
312 
313  if (size == UINT_MAX)
314  return AVERROR(EINVAL);
315  value = av_malloc(size + 1);
316  if (!value)
317  return AVERROR(ENOMEM);
318  if (avio_read(pb, value, size) != size) {
319  av_freep(&value);
320  return AVERROR_INVALIDDATA;
321  }
322  value[size] = 0;
323 
324  AV_WL32(key, tag);
325 
326  return av_dict_set(st ? &st->metadata : &s->metadata, key, value,
328 }
329 
330 static const char months[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
331  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
332 
333 static void avi_metadata_creation_time(AVDictionary **metadata, char *date)
334 {
335  char month[4], time[9], buffer[64];
336  int i, day, year;
337  /* parse standard AVI date format (ie. "Mon Mar 10 15:04:43 2003") */
338  if (sscanf(date, "%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d",
339  month, &day, time, &year) == 4) {
340  for (i = 0; i < 12; i++)
341  if (!av_strcasecmp(month, months[i])) {
342  snprintf(buffer, sizeof(buffer), "%.4d-%.2d-%.2d %s",
343  year, i + 1, day, time);
344  av_dict_set(metadata, "creation_time", buffer, 0);
345  }
346  } else if (date[4] == '/' && date[7] == '/') {
347  date[4] = date[7] = '-';
348  av_dict_set(metadata, "creation_time", date, 0);
349  }
350 }
351 
352 static void avi_read_nikon(AVFormatContext *s, uint64_t end)
353 {
354  while (avio_tell(s->pb) < end && !avio_feof(s->pb)) {
355  uint32_t tag = avio_rl32(s->pb);
356  uint32_t size = avio_rl32(s->pb);
357  switch (tag) {
358  case MKTAG('n', 'c', 't', 'g'): /* Nikon Tags */
359  {
360  uint64_t tag_end = avio_tell(s->pb) + size;
361  while (avio_tell(s->pb) < tag_end && !avio_feof(s->pb)) {
362  uint16_t tag = avio_rl16(s->pb);
363  uint16_t size = avio_rl16(s->pb);
364  const char *name = NULL;
365  char buffer[64] = { 0 };
366  uint64_t remaining = tag_end - avio_tell(s->pb);
367  size = FFMIN(size, remaining);
368  size -= avio_read(s->pb, buffer,
369  FFMIN(size, sizeof(buffer) - 1));
370  switch (tag) {
371  case 0x03:
372  name = "maker";
373  break;
374  case 0x04:
375  name = "model";
376  break;
377  case 0x13:
378  name = "creation_time";
379  if (buffer[4] == ':' && buffer[7] == ':')
380  buffer[4] = buffer[7] = '-';
381  break;
382  }
383  if (name)
384  av_dict_set(&s->metadata, name, buffer, 0);
385  avio_skip(s->pb, size);
386  }
387  break;
388  }
389  default:
390  avio_skip(s->pb, size);
391  break;
392  }
393  }
394 }
395 
397 {
398  GetByteContext gb;
399  uint8_t *data = st->codecpar->extradata;
400  int data_size = st->codecpar->extradata_size;
401  int tag, offset;
402 
403  if (!data || data_size < 8) {
404  return AVERROR_INVALIDDATA;
405  }
406 
407  bytestream2_init(&gb, data, data_size);
408 
409  tag = bytestream2_get_le32(&gb);
410 
411  switch (tag) {
412  case MKTAG('A', 'V', 'I', 'F'):
413  // skip 4 byte padding
414  bytestream2_skip(&gb, 4);
415  offset = bytestream2_tell(&gb);
416 
417  // decode EXIF tags from IFD, AVI is always little-endian
418  return avpriv_exif_decode_ifd(s, data + offset, data_size - offset,
419  1, 0, &st->metadata);
420  break;
421  case MKTAG('C', 'A', 'S', 'I'):
422  avpriv_request_sample(s, "RIFF stream data tag type CASI (%u)", tag);
423  break;
424  case MKTAG('Z', 'o', 'r', 'a'):
425  avpriv_request_sample(s, "RIFF stream data tag type Zora (%u)", tag);
426  break;
427  default:
428  break;
429  }
430 
431  return 0;
432 }
433 
435 {
436  AVIContext *avi = s->priv_data;
437  int i, j;
438  int64_t lensum = 0;
439  int64_t maxpos = 0;
440 
441  for (i = 0; i<s->nb_streams; i++) {
442  int64_t len = 0;
443  FFStream *const sti = ffstream(s->streams[i]);
444 
445  if (!sti->nb_index_entries)
446  continue;
447 
448  for (j = 0; j < sti->nb_index_entries; j++)
449  len += sti->index_entries[j].size;
450  maxpos = FFMAX(maxpos, sti->index_entries[j-1].pos);
451  lensum += len;
452  }
453  if (maxpos < av_rescale(avi->io_fsize, 9, 10)) // index does not cover the whole file
454  return 0;
455  if (lensum*9/10 > maxpos || lensum < maxpos*9/10) // frame sum and filesize mismatch
456  return 0;
457 
458  for (i = 0; i<s->nb_streams; i++) {
459  int64_t len = 0;
460  AVStream *st = s->streams[i];
461  FFStream *const sti = ffstream(st);
462  int64_t duration;
463  int64_t bitrate;
464 
465  for (j = 0; j < sti->nb_index_entries; j++)
466  len += sti->index_entries[j].size;
467 
468  if (sti->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
469  continue;
472  if (bitrate > 0) {
473  st->codecpar->bit_rate = bitrate;
474  }
475  }
476  return 1;
477 }
478 
480 {
481  AVIContext *avi = s->priv_data;
482  AVIOContext *pb = s->pb;
483  unsigned int tag, tag1, handler;
484  int codec_type, stream_index, frame_period;
485  unsigned int size;
486  int i;
487  AVStream *st;
488  AVIStream *ast = NULL;
489  int avih_width = 0, avih_height = 0;
490  int amv_file_format = 0;
491  uint64_t list_end = 0;
492  int64_t pos;
493  int ret;
494  AVDictionaryEntry *dict_entry;
495 
496  avi->stream_index = -1;
497 
498  ret = get_riff(s, pb);
499  if (ret < 0)
500  return ret;
501 
502  av_log(avi, AV_LOG_DEBUG, "use odml:%d\n", avi->use_odml);
503 
504  avi->io_fsize = avi->fsize = avio_size(pb);
505  if (avi->fsize <= 0 || avi->fsize < avi->riff_end)
506  avi->fsize = avi->riff_end == 8 ? INT64_MAX : avi->riff_end;
507 
508  /* first list tag */
509  stream_index = -1;
510  codec_type = -1;
511  frame_period = 0;
512  for (;;) {
513  if (avio_feof(pb))
514  return AVERROR_INVALIDDATA;
515  tag = avio_rl32(pb);
516  size = avio_rl32(pb);
517 
518  print_tag(s, "tag", tag, size);
519 
520  switch (tag) {
521  case MKTAG('L', 'I', 'S', 'T'):
522  list_end = avio_tell(pb) + size;
523  /* Ignored, except at start of video packets. */
524  tag1 = avio_rl32(pb);
525 
526  print_tag(s, "list", tag1, 0);
527 
528  if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
529  avi->movi_list = avio_tell(pb) - 4;
530  if (size)
531  avi->movi_end = avi->movi_list + size + (size & 1);
532  else
533  avi->movi_end = avi->fsize;
534  av_log(s, AV_LOG_TRACE, "movi end=%"PRIx64"\n", avi->movi_end);
535  goto end_of_header;
536  } else if (tag1 == MKTAG('I', 'N', 'F', 'O'))
537  ff_read_riff_info(s, size - 4);
538  else if (tag1 == MKTAG('n', 'c', 'd', 't'))
539  avi_read_nikon(s, list_end);
540 
541  break;
542  case MKTAG('I', 'D', 'I', 'T'):
543  {
544  unsigned char date[64] = { 0 };
545  size += (size & 1);
546  size -= avio_read(pb, date, FFMIN(size, sizeof(date) - 1));
547  avio_skip(pb, size);
548  avi_metadata_creation_time(&s->metadata, date);
549  break;
550  }
551  case MKTAG('d', 'm', 'l', 'h'):
552  avi->is_odml = 1;
553  avio_skip(pb, size + (size & 1));
554  break;
555  case MKTAG('a', 'm', 'v', 'h'):
556  amv_file_format = 1;
557  case MKTAG('a', 'v', 'i', 'h'):
558  /* AVI header */
559  /* using frame_period is bad idea */
560  frame_period = avio_rl32(pb);
561  avio_rl32(pb); /* max. bytes per second */
562  avio_rl32(pb);
564 
565  avio_skip(pb, 2 * 4);
566  avio_rl32(pb);
567  avio_rl32(pb);
568  avih_width = avio_rl32(pb);
569  avih_height = avio_rl32(pb);
570 
571  avio_skip(pb, size - 10 * 4);
572  break;
573  case MKTAG('s', 't', 'r', 'h'):
574  /* stream header */
575 
576  tag1 = avio_rl32(pb);
577  handler = avio_rl32(pb); /* codec tag */
578 
579  if (tag1 == MKTAG('p', 'a', 'd', 's')) {
580  avio_skip(pb, size - 8);
581  break;
582  } else {
583  stream_index++;
584  st = avformat_new_stream(s, NULL);
585  if (!st)
586  return AVERROR(ENOMEM);
587 
588  st->id = stream_index;
589  ast = av_mallocz(sizeof(AVIStream));
590  if (!ast)
591  return AVERROR(ENOMEM);
592  st->priv_data = ast;
593  }
594  if (amv_file_format)
595  tag1 = stream_index ? MKTAG('a', 'u', 'd', 's')
596  : MKTAG('v', 'i', 'd', 's');
597 
598  print_tag(s, "strh", tag1, -1);
599 
600  if (tag1 == MKTAG('i', 'a', 'v', 's') ||
601  tag1 == MKTAG('i', 'v', 'a', 's')) {
602  int64_t dv_dur;
603 
604  /* After some consideration -- I don't think we
605  * have to support anything but DV in type1 AVIs. */
606  if (s->nb_streams != 1)
607  return AVERROR_INVALIDDATA;
608 
609  if (handler != MKTAG('d', 'v', 's', 'd') &&
610  handler != MKTAG('d', 'v', 'h', 'd') &&
611  handler != MKTAG('d', 'v', 's', 'l'))
612  return AVERROR_INVALIDDATA;
613 
614  if (!CONFIG_DV_DEMUXER)
616 
617  ast = s->streams[0]->priv_data;
618  st->priv_data = NULL;
619  ff_free_stream(s, st);
620 
622  if (!avi->dv_demux) {
623  av_free(ast);
624  return AVERROR(ENOMEM);
625  }
626 
627  s->streams[0]->priv_data = ast;
628  avio_skip(pb, 3 * 4);
629  ast->scale = avio_rl32(pb);
630  ast->rate = avio_rl32(pb);
631  avio_skip(pb, 4); /* start time */
632 
633  dv_dur = avio_rl32(pb);
634  if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) {
635  dv_dur *= AV_TIME_BASE;
636  s->duration = av_rescale(dv_dur, ast->scale, ast->rate);
637  }
638  /* else, leave duration alone; timing estimation in utils.c
639  * will make a guess based on bitrate. */
640 
641  stream_index = s->nb_streams - 1;
642  avio_skip(pb, size - 9 * 4);
643  break;
644  }
645 
646  av_assert0(stream_index < s->nb_streams);
647  ast->handler = handler;
648 
649  avio_rl32(pb); /* flags */
650  avio_rl16(pb); /* priority */
651  avio_rl16(pb); /* language */
652  avio_rl32(pb); /* initial frame */
653  ast->scale = avio_rl32(pb);
654  ast->rate = avio_rl32(pb);
655  if (!(ast->scale && ast->rate)) {
657  "scale/rate is %"PRIu32"/%"PRIu32" which is invalid. "
658  "(This file has been generated by broken software.)\n",
659  ast->scale,
660  ast->rate);
661  if (frame_period) {
662  ast->rate = 1000000;
663  ast->scale = frame_period;
664  } else {
665  ast->rate = 25;
666  ast->scale = 1;
667  }
668  }
669  avpriv_set_pts_info(st, 64, ast->scale, ast->rate);
670 
671  ast->cum_len = avio_rl32(pb); /* start */
672  st->nb_frames = avio_rl32(pb);
673 
674  st->start_time = 0;
675  avio_rl32(pb); /* buffer size */
676  avio_rl32(pb); /* quality */
677  if (ast->cum_len > 3600LL * ast->rate / ast->scale) {
678  av_log(s, AV_LOG_ERROR, "crazy start time, iam scared, giving up\n");
679  ast->cum_len = 0;
680  }
681  ast->sample_size = avio_rl32(pb);
682  ast->cum_len *= FFMAX(1, ast->sample_size);
683  av_log(s, AV_LOG_TRACE, "%"PRIu32" %"PRIu32" %d\n",
684  ast->rate, ast->scale, ast->sample_size);
685 
686  switch (tag1) {
687  case MKTAG('v', 'i', 'd', 's'):
689 
690  ast->sample_size = 0;
691  st->avg_frame_rate = av_inv_q(st->time_base);
692  break;
693  case MKTAG('a', 'u', 'd', 's'):
695  break;
696  case MKTAG('t', 'x', 't', 's'):
698  break;
699  case MKTAG('d', 'a', 't', 's'):
701  break;
702  default:
703  av_log(s, AV_LOG_INFO, "unknown stream type %X\n", tag1);
704  }
705 
706  if (ast->sample_size < 0) {
707  if (s->error_recognition & AV_EF_EXPLODE) {
709  "Invalid sample_size %d at stream %d\n",
710  ast->sample_size,
711  stream_index);
712  return AVERROR_INVALIDDATA;
713  }
715  "Invalid sample_size %d at stream %d "
716  "setting it to 0\n",
717  ast->sample_size,
718  stream_index);
719  ast->sample_size = 0;
720  }
721 
722  if (ast->sample_size == 0) {
723  st->duration = st->nb_frames;
724  if (st->duration > 0 && avi->io_fsize > 0 && avi->riff_end > avi->io_fsize) {
725  av_log(s, AV_LOG_DEBUG, "File is truncated adjusting duration\n");
726  st->duration = av_rescale(st->duration, avi->io_fsize, avi->riff_end);
727  }
728  }
729  ast->frame_offset = ast->cum_len;
730  avio_skip(pb, size - 12 * 4);
731  break;
732  case MKTAG('s', 't', 'r', 'f'):
733  /* stream header */
734  if (!size && (codec_type == AVMEDIA_TYPE_AUDIO ||
736  break;
737  if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {
738  avio_skip(pb, size);
739  } else {
740  uint64_t cur_pos = avio_tell(pb);
741  FFStream *sti;
742  unsigned esize;
743  if (cur_pos < list_end)
744  size = FFMIN(size, list_end - cur_pos);
745  st = s->streams[stream_index];
746  sti = ffstream(st);
748  avio_skip(pb, size);
749  break;
750  }
751  switch (codec_type) {
752  case AVMEDIA_TYPE_VIDEO:
753  if (amv_file_format) {
754  st->codecpar->width = avih_width;
755  st->codecpar->height = avih_height;
758  avio_skip(pb, size);
759  break;
760  }
761  tag1 = ff_get_bmp_header(pb, st, &esize);
762 
763  if (tag1 == MKTAG('D', 'X', 'S', 'B') ||
764  tag1 == MKTAG('D', 'X', 'S', 'A')) {
766  st->codecpar->codec_tag = tag1;
768  break;
769  }
770 
771  if (size > 10 * 4 && size < (1 << 30) && size < avi->fsize) {
772  if (esize == size-1 && (esize&1)) {
773  st->codecpar->extradata_size = esize - 10 * 4;
774  } else
775  st->codecpar->extradata_size = size - 10 * 4;
776  if (st->codecpar->extradata) {
777  av_log(s, AV_LOG_WARNING, "New extradata in strf chunk, freeing previous one.\n");
778  }
779  ret = ff_get_extradata(s, st->codecpar, pb,
780  st->codecpar->extradata_size);
781  if (ret < 0)
782  return ret;
783  }
784 
785  // FIXME: check if the encoder really did this correctly
786  if (st->codecpar->extradata_size & 1)
787  avio_r8(pb);
788 
789  /* Extract palette from extradata if bpp <= 8.
790  * This code assumes that extradata contains only palette.
791  * This is true for all paletted codecs implemented in
792  * FFmpeg. */
793  if (st->codecpar->extradata_size &&
794  (st->codecpar->bits_per_coded_sample <= 8)) {
795  int pal_size = (1 << st->codecpar->bits_per_coded_sample) << 2;
796  const uint8_t *pal_src;
797 
798  pal_size = FFMIN(pal_size, st->codecpar->extradata_size);
799  pal_src = st->codecpar->extradata +
800  st->codecpar->extradata_size - pal_size;
801  /* Exclude the "BottomUp" field from the palette */
802  if (pal_src - st->codecpar->extradata >= 9 &&
803  !memcmp(st->codecpar->extradata + st->codecpar->extradata_size - 9, "BottomUp", 9))
804  pal_src -= 9;
805  for (i = 0; i < pal_size / 4; i++)
806  ast->pal[i] = 0xFFU<<24 | AV_RL32(pal_src + 4 * i);
807  ast->has_pal = 1;
808  }
809 
810  print_tag(s, "video", tag1, 0);
811 
813  st->codecpar->codec_tag = tag1;
815  tag1);
816  /* If codec is not found yet, try with the mov tags. */
817  if (!st->codecpar->codec_id) {
818  st->codecpar->codec_id =
820  if (st->codecpar->codec_id)
822  "mov tag found in avi (fourcc %s)\n",
823  av_fourcc2str(tag1));
824  }
825  if (!st->codecpar->codec_id)
827 
828  /* This is needed to get the pict type which is necessary
829  * for generating correct pts. */
831 
832  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 &&
833  ast->handler == MKTAG('X', 'V', 'I', 'D'))
834  st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D');
835 
836  if (st->codecpar->codec_tag == MKTAG('V', 'S', 'S', 'H'))
838  if (st->codecpar->codec_id == AV_CODEC_ID_RV40)
840  if (st->codecpar->codec_id == AV_CODEC_ID_HEVC &&
841  st->codecpar->codec_tag == MKTAG('H', '2', '6', '5'))
843 
844  if (st->codecpar->codec_id == AV_CODEC_ID_AVRN &&
845  st->codecpar->codec_tag == MKTAG('A', 'V', 'R', 'n') &&
846  (st->codecpar->extradata_size < 31 ||
847  memcmp(&st->codecpar->extradata[28], "1:1", 3)))
849 
850  if (st->codecpar->codec_tag == 0 && st->codecpar->height > 0 &&
851  st->codecpar->extradata_size < 1U << 30) {
852  st->codecpar->extradata_size += 9;
853  if ((ret = av_reallocp(&st->codecpar->extradata,
854  st->codecpar->extradata_size +
856  st->codecpar->extradata_size = 0;
857  return ret;
858  } else
859  memcpy(st->codecpar->extradata + st->codecpar->extradata_size - 9,
860  "BottomUp", 9);
861  }
862  st->codecpar->height = FFABS(st->codecpar->height);
863 
864 // avio_skip(pb, size - 5 * 4);
865  break;
866  case AVMEDIA_TYPE_AUDIO:
867  ret = ff_get_wav_header(s, pb, st->codecpar, size, 0);
868  if (ret < 0)
869  return ret;
871  if (ast->sample_size && st->codecpar->block_align &&
872  ast->sample_size != st->codecpar->block_align) {
873  av_log(s,
875  "sample size (%d) != block align (%d)\n",
876  ast->sample_size,
877  st->codecpar->block_align);
878  ast->sample_size = st->codecpar->block_align;
879  }
880  /* 2-aligned
881  * (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
882  if (size & 1)
883  avio_skip(pb, 1);
884  /* Force parsing as several audio frames can be in
885  * one packet and timestamps refer to packet start. */
887  /* ADTS header is in extradata, AAC without header must be
888  * stored as exact frames. Parser not needed and it will
889  * fail. */
890  if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
893  // The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS
894  if (st->codecpar->codec_id == AV_CODEC_ID_FLAC)
896  /* AVI files with Xan DPCM audio (wrongly) declare PCM
897  * audio in the header but have Axan as stream_code_tag. */
898  if (ast->handler == AV_RL32("Axan")) {
900  st->codecpar->codec_tag = 0;
901  ast->dshow_block_align = 0;
902  }
903  if (amv_file_format) {
905  ast->dshow_block_align = 0;
906  }
907  if ((st->codecpar->codec_id == AV_CODEC_ID_AAC ||
909  st->codecpar->codec_id == AV_CODEC_ID_MP2 ) && ast->dshow_block_align <= 4 && ast->dshow_block_align) {
910  av_log(s, AV_LOG_DEBUG, "overriding invalid dshow_block_align of %d\n", ast->dshow_block_align);
911  ast->dshow_block_align = 0;
912  }
913  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 1024 && ast->sample_size == 1024 ||
914  st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 4096 && ast->sample_size == 4096 ||
915  st->codecpar->codec_id == AV_CODEC_ID_MP3 && ast->dshow_block_align == 1152 && ast->sample_size == 1152) {
916  av_log(s, AV_LOG_DEBUG, "overriding sample_size\n");
917  ast->sample_size = 0;
918  }
919  break;
922  sti->request_probe = 1;
923  avio_skip(pb, size);
924  break;
925  default:
928  st->codecpar->codec_tag = 0;
929  avio_skip(pb, size);
930  break;
931  }
932  }
933  break;
934  case MKTAG('s', 't', 'r', 'd'):
935  if (stream_index >= (unsigned)s->nb_streams
936  || s->streams[stream_index]->codecpar->extradata_size
937  || s->streams[stream_index]->codecpar->codec_tag == MKTAG('H','2','6','4')) {
938  avio_skip(pb, size);
939  } else {
940  uint64_t cur_pos = avio_tell(pb);
941  if (cur_pos < list_end)
942  size = FFMIN(size, list_end - cur_pos);
943  st = s->streams[stream_index];
944 
945  if (size<(1<<30)) {
946  if (st->codecpar->extradata) {
947  av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n");
948  }
949  if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0)
950  return ret;
951  }
952 
953  if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly
954  avio_r8(pb);
955 
957  if (ret < 0) {
958  av_log(s, AV_LOG_WARNING, "could not decoding EXIF data in stream header.\n");
959  }
960  }
961  break;
962  case MKTAG('i', 'n', 'd', 'x'):
963  pos = avio_tell(pb);
964  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !(s->flags & AVFMT_FLAG_IGNIDX) &&
965  avi->use_odml &&
966  read_odml_index(s, 0) < 0 &&
967  (s->error_recognition & AV_EF_EXPLODE))
968  return AVERROR_INVALIDDATA;
969  avio_seek(pb, pos + size, SEEK_SET);
970  break;
971  case MKTAG('v', 'p', 'r', 'p'):
972  if (stream_index < (unsigned)s->nb_streams && size > 9 * 4) {
973  AVRational active, active_aspect;
974 
975  st = s->streams[stream_index];
976  avio_rl32(pb);
977  avio_rl32(pb);
978  avio_rl32(pb);
979  avio_rl32(pb);
980  avio_rl32(pb);
981 
982  active_aspect.den = avio_rl16(pb);
983  active_aspect.num = avio_rl16(pb);
984  active.num = avio_rl32(pb);
985  active.den = avio_rl32(pb);
986  avio_rl32(pb); // nbFieldsPerFrame
987 
988  if (active_aspect.num && active_aspect.den &&
989  active.num && active.den) {
990  st->sample_aspect_ratio = av_div_q(active_aspect, active);
991  av_log(s, AV_LOG_TRACE, "vprp %d/%d %d/%d\n",
992  active_aspect.num, active_aspect.den,
993  active.num, active.den);
994  }
995  size -= 9 * 4;
996  }
997  avio_skip(pb, size);
998  break;
999  case MKTAG('s', 't', 'r', 'n'):
1000  case MKTAG('i', 's', 'b', 'j'):
1001  case MKTAG('i', 'n', 'a', 'm'):
1002  case MKTAG('i', 'a', 'r', 't'):
1003  case MKTAG('i', 'c', 'o', 'p'):
1004  case MKTAG('i', 'c', 'm', 't'):
1005  case MKTAG('i', 'g', 'n', 'r'):
1006  case MKTAG('i', 'p', 'o', 'd'):
1007  case MKTAG('i', 's', 'o', 'f'):
1008  if (s->nb_streams) {
1009  ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
1010  if (ret < 0)
1011  return ret;
1012  break;
1013  }
1014  default:
1015  if (size > 1000000) {
1017  "Something went wrong during header parsing, "
1018  "tag %s has size %u, "
1019  "I will ignore it and try to continue anyway.\n",
1020  av_fourcc2str(tag), size);
1021  if (s->error_recognition & AV_EF_EXPLODE)
1022  return AVERROR_INVALIDDATA;
1023  avi->movi_list = avio_tell(pb) - 4;
1024  avi->movi_end = avi->fsize;
1025  goto end_of_header;
1026  }
1027  /* Do not fail for very large idx1 tags */
1028  case MKTAG('i', 'd', 'x', '1'):
1029  /* skip tag */
1030  size += (size & 1);
1031  avio_skip(pb, size);
1032  break;
1033  }
1034  }
1035 
1036 end_of_header:
1037  /* check stream number */
1038  if (stream_index != s->nb_streams - 1)
1039  return AVERROR_INVALIDDATA;
1040 
1041  if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))
1042  avi_load_index(s);
1044  avi->index_loaded |= 1;
1045 
1046  if ((ret = guess_ni_flag(s)) < 0)
1047  return ret;
1048 
1049  avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS);
1050 
1051  dict_entry = av_dict_get(s->metadata, "ISFT", NULL, 0);
1052  if (dict_entry && !strcmp(dict_entry->value, "PotEncoder"))
1053  for (i = 0; i < s->nb_streams; i++) {
1054  AVStream *st = s->streams[i];
1058  }
1059 
1060  for (i = 0; i < s->nb_streams; i++) {
1061  AVStream *st = s->streams[i];
1062  if (ffstream(st)->nb_index_entries)
1063  break;
1064  }
1065  // DV-in-AVI cannot be non-interleaved, if set this must be
1066  // a mis-detection.
1067  if (avi->dv_demux)
1068  avi->non_interleaved = 0;
1069  if (i == s->nb_streams && avi->non_interleaved) {
1071  "Non-interleaved AVI without index, switching to interleaved\n");
1072  avi->non_interleaved = 0;
1073  }
1074 
1075  if (avi->non_interleaved) {
1076  av_log(s, AV_LOG_INFO, "non-interleaved AVI\n");
1077  clean_index(s);
1078  }
1079 
1082 
1083  return 0;
1084 }
1085 
1087 {
1088  if (pkt->size >= 7 &&
1089  pkt->size < INT_MAX - AVPROBE_PADDING_SIZE &&
1090  !strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data + 5) == 2) {
1091  uint8_t desc[256];
1092  int score = AVPROBE_SCORE_EXTENSION, ret;
1093  AVIStream *ast = st->priv_data;
1094  const AVInputFormat *sub_demuxer;
1095  AVRational time_base;
1096  int size;
1097  AVProbeData pd;
1098  unsigned int desc_len;
1100  pkt->size - 7,
1101  0, NULL, NULL, NULL, NULL);
1102  if (!pb)
1103  goto error;
1104 
1105  desc_len = avio_rl32(pb);
1106 
1107  if (desc_len > pb->buf_end - pb->buf_ptr)
1108  goto error;
1109 
1110  ret = avio_get_str16le(pb, desc_len, desc, sizeof(desc));
1111  avio_skip(pb, desc_len - ret);
1112  if (*desc)
1113  av_dict_set(&st->metadata, "title", desc, 0);
1114 
1115  avio_rl16(pb); /* flags? */
1116  avio_rl32(pb); /* data size */
1117 
1118  size = pb->buf_end - pb->buf_ptr;
1120  .buf_size = size };
1121  if (!pd.buf)
1122  goto error;
1123  memcpy(pd.buf, pb->buf_ptr, size);
1124  sub_demuxer = av_probe_input_format2(&pd, 1, &score);
1125  av_freep(&pd.buf);
1126  if (!sub_demuxer)
1127  goto error;
1128 
1129  if (strcmp(sub_demuxer->name, "srt") && strcmp(sub_demuxer->name, "ass"))
1130  goto error;
1131 
1132  if (!(ast->sub_pkt = av_packet_alloc()))
1133  goto error;
1134 
1135  if (!(ast->sub_ctx = avformat_alloc_context()))
1136  goto error;
1137 
1138  ast->sub_ctx->pb = pb;
1139 
1140  if (ff_copy_whiteblacklists(ast->sub_ctx, s) < 0)
1141  goto error;
1142 
1143  if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) {
1144  if (ast->sub_ctx->nb_streams != 1)
1145  goto error;
1146  ff_read_packet(ast->sub_ctx, ast->sub_pkt);
1148  time_base = ast->sub_ctx->streams[0]->time_base;
1149  avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
1150  }
1151  ast->sub_buffer = pkt->buf;
1152  pkt->buf = NULL;
1154  return 1;
1155 
1156 error:
1157  av_packet_free(&ast->sub_pkt);
1158  av_freep(&ast->sub_ctx);
1159  avio_context_free(&pb);
1160  }
1161  return 0;
1162 }
1163 
1165  AVPacket *pkt)
1166 {
1167  AVIStream *ast, *next_ast = next_st->priv_data;
1168  int64_t ts, next_ts, ts_min = INT64_MAX;
1169  AVStream *st, *sub_st = NULL;
1170  int i;
1171 
1172  next_ts = av_rescale_q(next_ast->frame_offset, next_st->time_base,
1173  AV_TIME_BASE_Q);
1174 
1175  for (i = 0; i < s->nb_streams; i++) {
1176  st = s->streams[i];
1177  ast = st->priv_data;
1178  if (st->discard < AVDISCARD_ALL && ast && ast->sub_pkt && ast->sub_pkt->data) {
1179  ts = av_rescale_q(ast->sub_pkt->dts, st->time_base, AV_TIME_BASE_Q);
1180  if (ts <= next_ts && ts < ts_min) {
1181  ts_min = ts;
1182  sub_st = st;
1183  }
1184  }
1185  }
1186 
1187  if (sub_st) {
1188  ast = sub_st->priv_data;
1190  pkt->stream_index = sub_st->index;
1191 
1192  if (ff_read_packet(ast->sub_ctx, ast->sub_pkt) < 0)
1193  ast->sub_pkt->data = NULL;
1194  }
1195  return sub_st;
1196 }
1197 
1198 static int get_stream_idx(const unsigned *d)
1199 {
1200  if (d[0] >= '0' && d[0] <= '9' &&
1201  d[1] >= '0' && d[1] <= '9') {
1202  return (d[0] - '0') * 10 + (d[1] - '0');
1203  } else {
1204  return 100; // invalid stream ID
1205  }
1206 }
1207 
1208 /**
1209  *
1210  * @param exit_early set to 1 to just gather packet position without making the changes needed to actually read & return the packet
1211  */
1212 static int avi_sync(AVFormatContext *s, int exit_early)
1213 {
1214  AVIContext *avi = s->priv_data;
1215  AVIOContext *pb = s->pb;
1216  int n;
1217  unsigned int d[8];
1218  unsigned int size;
1219  int64_t i, sync;
1220 
1221 start_sync:
1222  memset(d, -1, sizeof(d));
1223  for (i = sync = avio_tell(pb); !avio_feof(pb); i++) {
1224  int j;
1225 
1226  for (j = 0; j < 7; j++)
1227  d[j] = d[j + 1];
1228  d[7] = avio_r8(pb);
1229 
1230  size = d[4] + (d[5] << 8) + (d[6] << 16) + (d[7] << 24);
1231 
1232  n = get_stream_idx(d + 2);
1233  ff_tlog(s, "%X %X %X %X %X %X %X %X %"PRId64" %u %d\n",
1234  d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
1235  if (i*(avi->io_fsize>0) + (uint64_t)size > avi->fsize || d[0] > 127)
1236  continue;
1237 
1238  // parse ix##
1239  if ((d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) ||
1240  // parse JUNK
1241  (d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') ||
1242  (d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1') ||
1243  (d[0] == 'i' && d[1] == 'n' && d[2] == 'd' && d[3] == 'x')) {
1244  avio_skip(pb, size);
1245  goto start_sync;
1246  }
1247 
1248  // parse stray LIST
1249  if (d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T') {
1250  avio_skip(pb, 4);
1251  goto start_sync;
1252  }
1253 
1254  n = get_stream_idx(d);
1255 
1256  if (!((i - avi->last_pkt_pos) & 1) &&
1257  get_stream_idx(d + 1) < s->nb_streams)
1258  continue;
1259 
1260  // detect ##ix chunk and skip
1261  if (d[2] == 'i' && d[3] == 'x' && n < s->nb_streams) {
1262  avio_skip(pb, size);
1263  goto start_sync;
1264  }
1265 
1266  if (d[2] == 'w' && d[3] == 'c' && n < s->nb_streams) {
1267  avio_skip(pb, 16 * 3 + 8);
1268  goto start_sync;
1269  }
1270 
1271  if (avi->dv_demux && n != 0)
1272  continue;
1273 
1274  // parse ##dc/##wb
1275  if (n < s->nb_streams) {
1276  AVStream *st;
1277  AVIStream *ast;
1278  st = s->streams[n];
1279  ast = st->priv_data;
1280 
1281  if (!ast) {
1282  av_log(s, AV_LOG_WARNING, "Skipping foreign stream %d packet\n", n);
1283  continue;
1284  }
1285 
1286  if (s->nb_streams >= 2) {
1287  AVStream *st1 = s->streams[1];
1288  AVIStream *ast1 = st1->priv_data;
1289  // workaround for broken small-file-bug402.avi
1290  if (ast1 && d[2] == 'w' && d[3] == 'b'
1291  && n == 0
1292  && st ->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
1294  && ast->prefix == 'd'*256+'c'
1295  && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count)
1296  ) {
1297  n = 1;
1298  st = st1;
1299  ast = ast1;
1301  "Invalid stream + prefix combination, assuming audio.\n");
1302  }
1303  }
1304 
1305  if (d[2] == 'p' && d[3] == 'c' && size <= 4 * 256 + 4) {
1306  int k = avio_r8(pb);
1307  int last = (k + avio_r8(pb) - 1) & 0xFF;
1308 
1309  avio_rl16(pb); // flags
1310 
1311  // b + (g << 8) + (r << 16);
1312  for (; k <= last; k++)
1313  ast->pal[k] = 0xFFU<<24 | avio_rb32(pb)>>8;
1314 
1315  ast->has_pal = 1;
1316  goto start_sync;
1317  } else if (((ast->prefix_count < 5 || sync + 9 > i) &&
1318  d[2] < 128 && d[3] < 128) ||
1319  d[2] * 256 + d[3] == ast->prefix /* ||
1320  (d[2] == 'd' && d[3] == 'c') ||
1321  (d[2] == 'w' && d[3] == 'b') */) {
1322  if (exit_early)
1323  return 0;
1324  if (d[2] * 256 + d[3] == ast->prefix)
1325  ast->prefix_count++;
1326  else {
1327  ast->prefix = d[2] * 256 + d[3];
1328  ast->prefix_count = 0;
1329  }
1330 
1331  if (!avi->dv_demux &&
1332  ((st->discard >= AVDISCARD_DEFAULT && size == 0) /* ||
1333  // FIXME: needs a little reordering
1334  (st->discard >= AVDISCARD_NONKEY &&
1335  !(pkt->flags & AV_PKT_FLAG_KEY)) */
1336  || st->discard >= AVDISCARD_ALL)) {
1337 
1338  ast->frame_offset += get_duration(ast, size);
1339  avio_skip(pb, size);
1340  goto start_sync;
1341  }
1342 
1343  avi->stream_index = n;
1344  ast->packet_size = size + 8;
1345  ast->remaining = size;
1346 
1347  if (size) {
1348  FFStream *const sti = ffstream(st);
1349  uint64_t pos = avio_tell(pb) - 8;
1350  if (!sti->index_entries || !sti->nb_index_entries ||
1351  sti->index_entries[sti->nb_index_entries - 1].pos < pos) {
1353  0, AVINDEX_KEYFRAME);
1354  }
1355  }
1356  return 0;
1357  }
1358  }
1359  }
1360 
1361  if (pb->error)
1362  return pb->error;
1363  return AVERROR_EOF;
1364 }
1365 
1367 {
1368  AVIContext *avi = s->priv_data;
1369  int best_stream_index = 0;
1370  AVStream *best_st = NULL;
1371  FFStream *best_sti;
1372  AVIStream *best_ast;
1373  int64_t best_ts = INT64_MAX;
1374  int i;
1375 
1376  for (i = 0; i < s->nb_streams; i++) {
1377  AVStream *st = s->streams[i];
1378  FFStream *const sti = ffstream(st);
1379  AVIStream *ast = st->priv_data;
1380  int64_t ts = ast->frame_offset;
1381  int64_t last_ts;
1382 
1383  if (!sti->nb_index_entries)
1384  continue;
1385 
1386  last_ts = sti->index_entries[sti->nb_index_entries - 1].timestamp;
1387  if (!ast->remaining && ts > last_ts)
1388  continue;
1389 
1390  ts = av_rescale_q(ts, st->time_base,
1391  (AVRational) { FFMAX(1, ast->sample_size),
1392  AV_TIME_BASE });
1393 
1394  av_log(s, AV_LOG_TRACE, "%"PRId64" %d/%d %"PRId64"\n", ts,
1395  st->time_base.num, st->time_base.den, ast->frame_offset);
1396  if (ts < best_ts) {
1397  best_ts = ts;
1398  best_st = st;
1399  best_stream_index = i;
1400  }
1401  }
1402  if (!best_st)
1403  return AVERROR_EOF;
1404 
1405  best_sti = ffstream(best_st);
1406  best_ast = best_st->priv_data;
1407  best_ts = best_ast->frame_offset;
1408  if (best_ast->remaining) {
1409  i = av_index_search_timestamp(best_st,
1410  best_ts,
1411  AVSEEK_FLAG_ANY |
1413  } else {
1414  i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
1415  if (i >= 0)
1416  best_ast->frame_offset = best_sti->index_entries[i].timestamp;
1417  }
1418 
1419  if (i >= 0) {
1420  int64_t pos = best_sti->index_entries[i].pos;
1421  pos += best_ast->packet_size - best_ast->remaining;
1422  if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
1423  return AVERROR_EOF;
1424 
1425  av_assert0(best_ast->remaining <= best_ast->packet_size);
1426 
1427  avi->stream_index = best_stream_index;
1428  if (!best_ast->remaining)
1429  best_ast->packet_size =
1430  best_ast->remaining = best_sti->index_entries[i].size;
1431  }
1432  else
1433  return AVERROR_EOF;
1434 
1435  return 0;
1436 }
1437 
1439 {
1440  AVIContext *avi = s->priv_data;
1441  AVIOContext *pb = s->pb;
1442  int err;
1443 
1444  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1445  int size = avpriv_dv_get_packet(avi->dv_demux, pkt);
1446  if (size >= 0)
1447  return size;
1448  else
1449  goto resync;
1450  }
1451 
1452  if (avi->non_interleaved) {
1453  err = ni_prepare_read(s);
1454  if (err < 0)
1455  return err;
1456  }
1457 
1458 resync:
1459  if (avi->stream_index >= 0) {
1460  AVStream *st = s->streams[avi->stream_index];
1461  FFStream *const sti = ffstream(st);
1462  AVIStream *ast = st->priv_data;
1463  int dv_demux = CONFIG_DV_DEMUXER && avi->dv_demux;
1464  int size, err;
1465 
1466  if (get_subtitle_pkt(s, st, pkt))
1467  return 0;
1468 
1469  // minorityreport.AVI block_align=1024 sample_size=1 IMA-ADPCM
1470  if (ast->sample_size <= 1)
1471  size = INT_MAX;
1472  else if (ast->sample_size < 32)
1473  // arbitrary multiplier to avoid tiny packets for raw PCM data
1474  size = 1024 * ast->sample_size;
1475  else
1476  size = ast->sample_size;
1477 
1478  if (size > ast->remaining)
1479  size = ast->remaining;
1480  avi->last_pkt_pos = avio_tell(pb);
1481  err = av_get_packet(pb, pkt, size);
1482  if (err < 0)
1483  return err;
1484  size = err;
1485 
1486  if (ast->has_pal && pkt->size < (unsigned)INT_MAX / 2 && !dv_demux) {
1487  uint8_t *pal;
1490  AVPALETTE_SIZE);
1491  if (!pal) {
1493  "Failed to allocate data for palette\n");
1494  } else {
1495  memcpy(pal, ast->pal, AVPALETTE_SIZE);
1496  ast->has_pal = 0;
1497  }
1498  }
1499 
1500  if (CONFIG_DV_DEMUXER && dv_demux) {
1502  pkt->data, pkt->size, pkt->pos);
1504  if (size < 0)
1506  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
1507  !st->codecpar->codec_tag && read_gab2_sub(s, st, pkt)) {
1508  ast->frame_offset++;
1509  avi->stream_index = -1;
1510  ast->remaining = 0;
1511  goto resync;
1512  } else {
1513  /* XXX: How to handle B-frames in AVI? */
1514  pkt->dts = ast->frame_offset;
1515 // pkt->dts += ast->start;
1516  if (ast->sample_size)
1517  pkt->dts /= ast->sample_size;
1518  pkt->stream_index = avi->stream_index;
1519 
1520  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->index_entries) {
1521  AVIndexEntry *e;
1522  int index;
1523 
1525  e = &sti->index_entries[index];
1526 
1527  if (index >= 0 && e->timestamp == ast->frame_offset) {
1528  if (index == sti->nb_index_entries-1) {
1529  int key=1;
1530  uint32_t state=-1;
1531  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1532  const uint8_t *ptr = pkt->data, *end = ptr + FFMIN(size, 256);
1533  while (ptr < end) {
1534  ptr = avpriv_find_start_code(ptr, end, &state);
1535  if (state == 0x1B6 && ptr < end) {
1536  key = !(*ptr & 0xC0);
1537  break;
1538  }
1539  }
1540  }
1541  if (!key)
1542  e->flags &= ~AVINDEX_KEYFRAME;
1543  }
1544  if (e->flags & AVINDEX_KEYFRAME)
1546  }
1547  } else {
1549  }
1550  ast->frame_offset += get_duration(ast, pkt->size);
1551  }
1552  ast->remaining -= err;
1553  if (!ast->remaining) {
1554  avi->stream_index = -1;
1555  ast->packet_size = 0;
1556  }
1557 
1558  if (!avi->non_interleaved && pkt->pos >= 0 && ast->seek_pos > pkt->pos) {
1560  goto resync;
1561  }
1562  ast->seek_pos= 0;
1563 
1564  if (!avi->non_interleaved && sti->nb_index_entries > 1 && avi->index_loaded > 1) {
1565  int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q);
1566 
1567  if (avi->dts_max < dts) {
1568  avi->dts_max = dts;
1569  } else if (avi->dts_max - (uint64_t)dts > 2*AV_TIME_BASE) {
1570  avi->non_interleaved= 1;
1571  av_log(s, AV_LOG_INFO, "Switching to NI mode, due to poor interleaving\n");
1572  }
1573  }
1574 
1575  return 0;
1576  }
1577 
1578  if ((err = avi_sync(s, 0)) < 0)
1579  return err;
1580  goto resync;
1581 }
1582 
1583 /* XXX: We make the implicit supposition that the positions are sorted
1584  * for each stream. */
1586 {
1587  AVIContext *avi = s->priv_data;
1588  AVIOContext *pb = s->pb;
1589  int nb_index_entries, i;
1590  AVStream *st;
1591  AVIStream *ast;
1592  int64_t pos;
1593  unsigned int index, tag, flags, len, first_packet = 1;
1594  int64_t last_pos = -1;
1595  unsigned last_idx = -1;
1596  int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1597  int anykey = 0;
1598 
1599  nb_index_entries = size / 16;
1600  if (nb_index_entries <= 0)
1601  return AVERROR_INVALIDDATA;
1602 
1603  idx1_pos = avio_tell(pb);
1604  avio_seek(pb, avi->movi_list + 4, SEEK_SET);
1605  if (avi_sync(s, 1) == 0)
1606  first_packet_pos = avio_tell(pb) - 8;
1607  avi->stream_index = -1;
1608  avio_seek(pb, idx1_pos, SEEK_SET);
1609 
1610  if (s->nb_streams == 1 && s->streams[0]->codecpar->codec_tag == AV_RL32("MMES")) {
1611  first_packet_pos = 0;
1612  data_offset = avi->movi_list;
1613  }
1614 
1615  /* Read the entries and sort them in each stream component. */
1616  for (i = 0; i < nb_index_entries; i++) {
1617  if (avio_feof(pb))
1618  return -1;
1619 
1620  tag = avio_rl32(pb);
1621  flags = avio_rl32(pb);
1622  pos = avio_rl32(pb);
1623  len = avio_rl32(pb);
1624  av_log(s, AV_LOG_TRACE, "%d: tag=0x%x flags=0x%x pos=0x%"PRIx64" len=%d/",
1625  i, tag, flags, pos, len);
1626 
1627  index = ((tag & 0xff) - '0') * 10;
1628  index += (tag >> 8 & 0xff) - '0';
1629  if (index >= s->nb_streams)
1630  continue;
1631  st = s->streams[index];
1632  ast = st->priv_data;
1633 
1634  /* Skip 'xxpc' palette change entries in the index until a logic
1635  * to process these is properly implemented. */
1636  if ((tag >> 16 & 0xff) == 'p' && (tag >> 24 & 0xff) == 'c')
1637  continue;
1638 
1639  if (first_packet && first_packet_pos) {
1640  if (avi->movi_list + 4 != pos || pos + 500 > first_packet_pos)
1641  data_offset = first_packet_pos - pos;
1642  first_packet = 0;
1643  }
1644  pos += data_offset;
1645 
1646  av_log(s, AV_LOG_TRACE, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
1647 
1648  // even if we have only a single stream, we should
1649  // switch to non-interleaved to get correct timestamps
1650  if (last_pos == pos)
1651  avi->non_interleaved = 1;
1652  if (last_idx != pos && len) {
1653  av_add_index_entry(st, pos, ast->cum_len, len, 0,
1654  (flags & AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);
1655  last_idx= pos;
1656  }
1657  ast->cum_len += get_duration(ast, len);
1658  last_pos = pos;
1659  anykey |= flags&AVIIF_INDEX;
1660  }
1661  if (!anykey) {
1662  for (index = 0; index < s->nb_streams; index++) {
1663  FFStream *const sti = ffstream(s->streams[index]);
1664  if (sti->nb_index_entries)
1666  }
1667  }
1668  return 0;
1669 }
1670 
1671 /* Scan the index and consider any file with streams more than
1672  * 2 seconds or 64MB apart non-interleaved. */
1674 {
1675  int64_t min_pos, pos;
1676  int i;
1677  int *idx = av_mallocz_array(s->nb_streams, sizeof(*idx));
1678  if (!idx)
1679  return AVERROR(ENOMEM);
1680  for (min_pos = pos = 0; min_pos != INT64_MAX; pos = min_pos + 1LU) {
1681  int64_t max_dts = INT64_MIN / 2;
1682  int64_t min_dts = INT64_MAX / 2;
1683  int64_t max_buffer = 0;
1684 
1685  min_pos = INT64_MAX;
1686 
1687  for (i = 0; i < s->nb_streams; i++) {
1688  AVStream *st = s->streams[i];
1689  AVIStream *ast = st->priv_data;
1690  FFStream *const sti = ffstream(st);
1691  int n = sti->nb_index_entries;
1692  while (idx[i] < n && sti->index_entries[idx[i]].pos < pos)
1693  idx[i]++;
1694  if (idx[i] < n) {
1695  int64_t dts;
1696  dts = av_rescale_q(sti->index_entries[idx[i]].timestamp /
1697  FFMAX(ast->sample_size, 1),
1698  st->time_base, AV_TIME_BASE_Q);
1699  min_dts = FFMIN(min_dts, dts);
1700  min_pos = FFMIN(min_pos, sti->index_entries[idx[i]].pos);
1701  }
1702  }
1703  for (i = 0; i < s->nb_streams; i++) {
1704  AVStream *st = s->streams[i];
1705  FFStream *const sti = ffstream(st);
1706  AVIStream *ast = st->priv_data;
1707 
1708  if (idx[i] && min_dts != INT64_MAX / 2) {
1709  int64_t dts, delta_dts;
1710  dts = av_rescale_q(sti->index_entries[idx[i] - 1].timestamp /
1711  FFMAX(ast->sample_size, 1),
1712  st->time_base, AV_TIME_BASE_Q);
1713  delta_dts = av_sat_sub64(dts, min_dts);
1714  max_dts = FFMAX(max_dts, dts);
1715  max_buffer = FFMAX(max_buffer,
1716  av_rescale(delta_dts,
1717  st->codecpar->bit_rate,
1718  AV_TIME_BASE));
1719  }
1720  }
1721  if (av_sat_sub64(max_dts, min_dts) > 2 * AV_TIME_BASE ||
1722  max_buffer > 1024 * 1024 * 8 * 8) {
1723  av_free(idx);
1724  return 1;
1725  }
1726  }
1727  av_free(idx);
1728  return 0;
1729 }
1730 
1732 {
1733  int i;
1734  int64_t last_start = 0;
1735  int64_t first_end = INT64_MAX;
1736  int64_t oldpos = avio_tell(s->pb);
1737 
1738  for (i = 0; i < s->nb_streams; i++) {
1739  AVStream *st = s->streams[i];
1740  FFStream *const sti = ffstream(st);
1741  int n = sti->nb_index_entries;
1742  unsigned int size;
1743 
1744  if (n <= 0)
1745  continue;
1746 
1747  if (n >= 2) {
1748  int64_t pos = sti->index_entries[0].pos;
1749  unsigned tag[2];
1750  avio_seek(s->pb, pos, SEEK_SET);
1751  tag[0] = avio_r8(s->pb);
1752  tag[1] = avio_r8(s->pb);
1753  avio_rl16(s->pb);
1754  size = avio_rl32(s->pb);
1755  if (get_stream_idx(tag) == i && pos + size > sti->index_entries[1].pos)
1756  last_start = INT64_MAX;
1757  if (get_stream_idx(tag) == i && size == sti->index_entries[0].size + 8)
1758  last_start = INT64_MAX;
1759  }
1760 
1761  if (sti->index_entries[0].pos > last_start)
1762  last_start = sti->index_entries[0].pos;
1763  if (sti->index_entries[n - 1].pos < first_end)
1764  first_end = sti->index_entries[n - 1].pos;
1765  }
1766  avio_seek(s->pb, oldpos, SEEK_SET);
1767 
1768  if (last_start > first_end)
1769  return 1;
1770 
1771  return check_stream_max_drift(s);
1772 }
1773 
1775 {
1776  AVIContext *avi = s->priv_data;
1777  AVIOContext *pb = s->pb;
1778  uint32_t tag, size;
1779  int64_t pos = avio_tell(pb);
1780  int64_t next;
1781  int ret = -1;
1782 
1783  if (avio_seek(pb, avi->movi_end, SEEK_SET) < 0)
1784  goto the_end; // maybe truncated file
1785  av_log(s, AV_LOG_TRACE, "movi_end=0x%"PRIx64"\n", avi->movi_end);
1786  for (;;) {
1787  tag = avio_rl32(pb);
1788  size = avio_rl32(pb);
1789  if (avio_feof(pb))
1790  break;
1791  next = avio_tell(pb);
1792  if (next < 0 || next > INT64_MAX - size - (size & 1))
1793  break;
1794  next += size + (size & 1LL);
1795 
1796  if (tag == MKTAG('i', 'd', 'x', '1') &&
1797  avi_read_idx1(s, size) >= 0) {
1798  avi->index_loaded=2;
1799  ret = 0;
1800  }else if (tag == MKTAG('L', 'I', 'S', 'T')) {
1801  uint32_t tag1 = avio_rl32(pb);
1802 
1803  if (tag1 == MKTAG('I', 'N', 'F', 'O'))
1804  ff_read_riff_info(s, size - 4);
1805  }else if (!ret)
1806  break;
1807 
1808  if (avio_seek(pb, next, SEEK_SET) < 0)
1809  break; // something is wrong here
1810  }
1811 
1812 the_end:
1813  avio_seek(pb, pos, SEEK_SET);
1814  return ret;
1815 }
1816 
1817 static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
1818 {
1819  AVIStream *ast2 = st2->priv_data;
1820  int64_t ts2 = av_rescale_q(timestamp, st->time_base, st2->time_base);
1821  av_packet_unref(ast2->sub_pkt);
1822  if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 ||
1823  avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
1824  ff_read_packet(ast2->sub_ctx, ast2->sub_pkt);
1825 }
1826 
1827 static int avi_read_seek(AVFormatContext *s, int stream_index,
1828  int64_t timestamp, int flags)
1829 {
1830  AVIContext *avi = s->priv_data;
1831  AVStream *st;
1832  FFStream *sti;
1833  int i, index;
1834  int64_t pos, pos_min;
1835  AVIStream *ast;
1836 
1837  /* Does not matter which stream is requested dv in avi has the
1838  * stream information in the first video stream.
1839  */
1840  if (avi->dv_demux)
1841  stream_index = 0;
1842 
1843  if (!avi->index_loaded) {
1844  /* we only load the index on demand */
1845  avi_load_index(s);
1846  avi->index_loaded |= 1;
1847  }
1848  av_assert0(stream_index >= 0);
1849 
1850  st = s->streams[stream_index];
1851  sti = ffstream(st);
1852  ast = st->priv_data;
1854  timestamp * FFMAX(ast->sample_size, 1),
1855  flags);
1856  if (index < 0) {
1857  if (sti->nb_index_entries > 0)
1858  av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n",
1859  timestamp * FFMAX(ast->sample_size, 1),
1860  sti->index_entries[0].timestamp,
1861  sti->index_entries[sti->nb_index_entries - 1].timestamp);
1862  return AVERROR_INVALIDDATA;
1863  }
1864 
1865  /* find the position */
1866  pos = sti->index_entries[index].pos;
1867  timestamp = sti->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
1868 
1869  av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n",
1870  timestamp, index, sti->index_entries[index].timestamp);
1871 
1872  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1873  /* One and only one real stream for DV in AVI, and it has video */
1874  /* offsets. Calling with other stream indexes should have failed */
1875  /* the av_index_search_timestamp call above. */
1876 
1877  if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1878  return -1;
1879 
1880  /* Feed the DV video stream version of the timestamp to the */
1881  /* DV demux so it can synthesize correct timestamps. */
1882  ff_dv_offset_reset(avi->dv_demux, timestamp);
1883 
1884  avi->stream_index = -1;
1885  return 0;
1886  }
1887 
1888  pos_min = pos;
1889  for (i = 0; i < s->nb_streams; i++) {
1890  AVStream *st2 = s->streams[i];
1891  FFStream *const sti2 = ffstream(st2);
1892  AVIStream *ast2 = st2->priv_data;
1893 
1894  ast2->packet_size =
1895  ast2->remaining = 0;
1896 
1897  if (ast2->sub_ctx) {
1898  seek_subtitle(st, st2, timestamp);
1899  continue;
1900  }
1901 
1902  if (sti2->nb_index_entries <= 0)
1903  continue;
1904 
1905 // av_assert1(st2->codecpar->block_align);
1907  av_rescale_q(timestamp,
1908  st->time_base,
1909  st2->time_base) *
1910  FFMAX(ast2->sample_size, 1),
1911  flags |
1914  if (index < 0)
1915  index = 0;
1916  ast2->seek_pos = sti2->index_entries[index].pos;
1917  pos_min = FFMIN(pos_min,ast2->seek_pos);
1918  }
1919  for (i = 0; i < s->nb_streams; i++) {
1920  AVStream *st2 = s->streams[i];
1921  FFStream *const sti2 = ffstream(st2);
1922  AVIStream *ast2 = st2->priv_data;
1923 
1924  if (ast2->sub_ctx || sti2->nb_index_entries <= 0)
1925  continue;
1926 
1928  st2,
1929  av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
1931  if (index < 0)
1932  index = 0;
1933  while (!avi->non_interleaved && index > 0 && sti2->index_entries[index-1].pos >= pos_min)
1934  index--;
1935  ast2->frame_offset = sti2->index_entries[index].timestamp;
1936  }
1937 
1938  /* do the seek */
1939  if (avio_seek(s->pb, pos_min, SEEK_SET) < 0) {
1940  av_log(s, AV_LOG_ERROR, "Seek failed\n");
1941  return -1;
1942  }
1943  avi->stream_index = -1;
1944  avi->dts_max = INT_MIN;
1945  return 0;
1946 }
1947 
1949 {
1950  int i;
1951  AVIContext *avi = s->priv_data;
1952 
1953  for (i = 0; i < s->nb_streams; i++) {
1954  AVStream *st = s->streams[i];
1955  AVIStream *ast = st->priv_data;
1956  if (ast) {
1957  if (ast->sub_ctx) {
1958  av_freep(&ast->sub_ctx->pb);
1960  }
1961  av_buffer_unref(&ast->sub_buffer);
1962  av_packet_free(&ast->sub_pkt);
1963  }
1964  }
1965 
1966  av_freep(&avi->dv_demux);
1967 
1968  return 0;
1969 }
1970 
1971 static int avi_probe(const AVProbeData *p)
1972 {
1973  int i;
1974 
1975  /* check file header */
1976  for (i = 0; avi_headers[i][0]; i++)
1977  if (AV_RL32(p->buf ) == AV_RL32(avi_headers[i] ) &&
1978  AV_RL32(p->buf + 8) == AV_RL32(avi_headers[i] + 4))
1979  return AVPROBE_SCORE_MAX;
1980 
1981  return 0;
1982 }
1983 
1985  .name = "avi",
1986  .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
1987  .priv_data_size = sizeof(AVIContext),
1988  .flags_internal = FF_FMT_INIT_CLEANUP,
1989  .extensions = "avi",
1990  .read_probe = avi_probe,
1995  .priv_class = &demuxer_class,
1996 };
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:417
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:48
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:724
options
static const AVOption options[]
Definition: avidec.c:88
ni_prepare_read
static int ni_prepare_read(AVFormatContext *s)
Definition: avidec.c:1366
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:1585
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:1217
AVStream::priv_data
void * priv_data
Definition: avformat.h:854
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:894
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:147
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:671
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:1165
MAX_ODML_DEPTH
#define MAX_ODML_DEPTH
Definition: avidec.c:83
index
fg index
Definition: ffmpeg_filter.c:168
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:1948
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:912
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
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:214
base
uint8_t base
Definition: vp3data.h:141
avi_read_nikon
static void avi_read_nikon(AVFormatContext *s, uint64_t end)
Definition: avidec.c:352
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:434
avi_metadata_creation_time
static void avi_metadata_creation_time(AVDictionary **metadata, char *date)
Definition: avidec.c:333
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:1086
codec_type
enum AVMediaType codec_type
Definition: rtp.c:37
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:338
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:425
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:777
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:785
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:1673
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:458
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:391
calculate_bitrate
static int calculate_bitrate(AVFormatContext *s)
Definition: avidec.c:434
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:426
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:2153
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:415
clean_index
static void clean_index(AVFormatContext *s)
Definition: avidec.c:275
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:486
dv.h
avi_read_seek
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: avidec.c:1827
AVPROBE_PADDING_SIZE
#define AVPROBE_PADDING_SIZE
extra allocated bytes at the end of the probe buffer
Definition: avformat.h:460
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:423
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:888
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:726
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:1817
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:304
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:773
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:626
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:1212
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:631
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:448
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:422
AVIndexEntry::size
int size
Definition: avformat.h:788
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:779
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:289
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:205
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:399
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:1097
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:992
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVSEEK_FLAG_BACKWARD
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2151
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:367
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:868
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:1198
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
state
static struct @317 state
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
AVSTREAM_PARSE_NONE
@ AVSTREAM_PARSE_NONE
Definition: avformat.h:767
AVIndexEntry::flags
int flags
Definition: avformat.h:787
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:1139
avi_read_packet
static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: avidec.c:1438
FFStream::nb_index_entries
int nb_index_entries
Definition: internal.h:273
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:446
AVIStream::packet_size
int packet_size
Definition: avidec.c:45
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:903
AV_CODEC_ID_ADPCM_IMA_AMV
@ AV_CODEC_ID_ADPCM_IMA_AMV
Definition: codec_id.h:371
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:1331
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:474
guess_ni_flag
static int guess_ni_flag(AVFormatContext *s)
Definition: avidec.c:1731
AVIStream::prefix_count
int prefix_count
Definition: avidec.c:55
AVPROBE_SCORE_EXTENSION
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:456
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:890
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:1153
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:424
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:460
ff_avi_demuxer
const AVInputFormat ff_avi_demuxer
Definition: avidec.c:1984
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:742
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:188
months
static const char months[12][4]
Definition: avidec.c:330
ff_copy_whiteblacklists
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition: utils.c:114
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:1971
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:901
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:616
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:1164
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:396
AV_CODEC_ID_RV40
@ AV_CODEC_ID_RV40
Definition: codec_id.h:119
i
int i
Definition: input.c:406
AVIContext::non_interleaved
int non_interleaved
Definition: avidec.c:78
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
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:970
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:130
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:261
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:1774
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:196
AVIStream::prefix
int prefix
Definition: avidec.c:54
AV_CODEC_ID_XSUB
@ AV_CODEC_ID_XSUB
Definition: codec_id.h:524
tag
uint32_t tag
Definition: movenc.c:1597
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:852
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:845
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:246
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:1233
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:769
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:846
avpriv_dv_init_demux
DVDemuxContext * avpriv_dv_init_demux(AVFormatContext *s)
Definition: dv.c:351
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:225
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:625
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:778
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:1146
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:333
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:271
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:479
FFStream::request_probe
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
Definition: internal.h:285
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:750
d
d
Definition: ffmpeg_filter.c:156
bytestream.h
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:768
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:878
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:770
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:360