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