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