FFmpeg  4.4.6
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  ff_read_riff_info(s, size - 4);
550  else if (tag1 == MKTAG('n', 'c', 'd', 't'))
551  avi_read_nikon(s, list_end);
552 
553  break;
554  case MKTAG('I', 'D', 'I', 'T'):
555  {
556  unsigned char date[64] = { 0 };
557  size += (size & 1);
558  size -= avio_read(pb, date, FFMIN(size, sizeof(date) - 1));
559  avio_skip(pb, size);
560  avi_metadata_creation_time(&s->metadata, date);
561  break;
562  }
563  case MKTAG('d', 'm', 'l', 'h'):
564  avi->is_odml = 1;
565  avio_skip(pb, size + (size & 1));
566  break;
567  case MKTAG('a', 'm', 'v', 'h'):
568  amv_file_format = 1;
569  case MKTAG('a', 'v', 'i', 'h'):
570  /* AVI header */
571  /* using frame_period is bad idea */
572  frame_period = avio_rl32(pb);
573  avio_rl32(pb); /* max. bytes per second */
574  avio_rl32(pb);
576 
577  avio_skip(pb, 2 * 4);
578  avio_rl32(pb);
579  avio_rl32(pb);
580  avih_width = avio_rl32(pb);
581  avih_height = avio_rl32(pb);
582 
583  avio_skip(pb, size - 10 * 4);
584  break;
585  case MKTAG('s', 't', 'r', 'h'):
586  /* stream header */
587 
588  tag1 = avio_rl32(pb);
589  handler = avio_rl32(pb); /* codec tag */
590 
591  if (tag1 == MKTAG('p', 'a', 'd', 's')) {
592  avio_skip(pb, size - 8);
593  break;
594  } else {
595  stream_index++;
596  st = avformat_new_stream(s, NULL);
597  if (!st)
598  RETURN_ERROR(AVERROR(ENOMEM));
599 
600  st->id = stream_index;
601  ast = av_mallocz(sizeof(AVIStream));
602  if (!ast)
603  RETURN_ERROR(AVERROR(ENOMEM));
604  st->priv_data = ast;
605  }
606  if (amv_file_format)
607  tag1 = stream_index ? MKTAG('a', 'u', 'd', 's')
608  : MKTAG('v', 'i', 'd', 's');
609 
610  print_tag(s, "strh", tag1, -1);
611 
612  if (tag1 == MKTAG('i', 'a', 'v', 's') ||
613  tag1 == MKTAG('i', 'v', 'a', 's')) {
614  int64_t dv_dur;
615 
616  /* After some consideration -- I don't think we
617  * have to support anything but DV in type1 AVIs. */
618  if (s->nb_streams != 1)
620 
621  if (handler != MKTAG('d', 'v', 's', 'd') &&
622  handler != MKTAG('d', 'v', 'h', 'd') &&
623  handler != MKTAG('d', 'v', 's', 'l'))
624  return AVERROR_INVALIDDATA;
625 
626  if (!CONFIG_DV_DEMUXER)
628 
629  ast = s->streams[0]->priv_data;
630  st->priv_data = NULL;
631  ff_free_stream(s, st);
632 
634  if (!avi->dv_demux) {
635  av_free(ast);
636  return AVERROR(ENOMEM);
637  }
638 
639  s->streams[0]->priv_data = ast;
640  avio_skip(pb, 3 * 4);
641  ast->scale = avio_rl32(pb);
642  ast->rate = avio_rl32(pb);
643  avio_skip(pb, 4); /* start time */
644 
645  dv_dur = avio_rl32(pb);
646  if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) {
647  dv_dur *= AV_TIME_BASE;
648  s->duration = av_rescale(dv_dur, ast->scale, ast->rate);
649  }
650  /* else, leave duration alone; timing estimation in utils.c
651  * will make a guess based on bitrate. */
652 
653  stream_index = s->nb_streams - 1;
654  avio_skip(pb, size - 9 * 4);
655  break;
656  }
657 
658  av_assert0(stream_index < s->nb_streams);
659  ast->handler = handler;
660 
661  avio_rl32(pb); /* flags */
662  avio_rl16(pb); /* priority */
663  avio_rl16(pb); /* language */
664  avio_rl32(pb); /* initial frame */
665  ast->scale = avio_rl32(pb);
666  ast->rate = avio_rl32(pb);
667  if (!(ast->scale && ast->rate)) {
669  "scale/rate is %"PRIu32"/%"PRIu32" which is invalid. "
670  "(This file has been generated by broken software.)\n",
671  ast->scale,
672  ast->rate);
673  if (frame_period) {
674  ast->rate = 1000000;
675  ast->scale = frame_period;
676  } else {
677  ast->rate = 25;
678  ast->scale = 1;
679  }
680  }
681  avpriv_set_pts_info(st, 64, ast->scale, ast->rate);
682 
683  ast->cum_len = avio_rl32(pb); /* start */
684  st->nb_frames = avio_rl32(pb);
685 
686  st->start_time = 0;
687  avio_rl32(pb); /* buffer size */
688  avio_rl32(pb); /* quality */
689  if (ast->cum_len > 3600LL * ast->rate / ast->scale) {
690  av_log(s, AV_LOG_ERROR, "crazy start time, iam scared, giving up\n");
691  ast->cum_len = 0;
692  }
693  ast->sample_size = avio_rl32(pb);
694  ast->cum_len *= FFMAX(1, ast->sample_size);
695  av_log(s, AV_LOG_TRACE, "%"PRIu32" %"PRIu32" %d\n",
696  ast->rate, ast->scale, ast->sample_size);
697 
698  switch (tag1) {
699  case MKTAG('v', 'i', 'd', 's'):
701 
702  ast->sample_size = 0;
703  st->avg_frame_rate = av_inv_q(st->time_base);
704  break;
705  case MKTAG('a', 'u', 'd', 's'):
707  break;
708  case MKTAG('t', 'x', 't', 's'):
710  break;
711  case MKTAG('d', 'a', 't', 's'):
713  break;
714  default:
715  av_log(s, AV_LOG_INFO, "unknown stream type %X\n", tag1);
716  }
717 
718  if (ast->sample_size < 0) {
719  if (s->error_recognition & AV_EF_EXPLODE) {
721  "Invalid sample_size %d at stream %d\n",
722  ast->sample_size,
723  stream_index);
725  }
727  "Invalid sample_size %d at stream %d "
728  "setting it to 0\n",
729  ast->sample_size,
730  stream_index);
731  ast->sample_size = 0;
732  }
733 
734  if (ast->sample_size == 0) {
735  st->duration = st->nb_frames;
736  if (st->duration > 0 && avi->io_fsize > 0 && avi->riff_end > avi->io_fsize) {
737  av_log(s, AV_LOG_DEBUG, "File is truncated adjusting duration\n");
738  st->duration = av_rescale(st->duration, avi->io_fsize, avi->riff_end);
739  }
740  }
741  ast->frame_offset = ast->cum_len;
742  avio_skip(pb, size - 12 * 4);
743  break;
744  case MKTAG('s', 't', 'r', 'f'):
745  /* stream header */
746  if (!size && (codec_type == AVMEDIA_TYPE_AUDIO ||
748  break;
749  if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {
750  avio_skip(pb, size);
751  } else {
752  uint64_t cur_pos = avio_tell(pb);
753  unsigned esize;
754  if (cur_pos < list_end)
755  size = FFMIN(size, list_end - cur_pos);
756  st = s->streams[stream_index];
758  avio_skip(pb, size);
759  break;
760  }
761  switch (codec_type) {
762  case AVMEDIA_TYPE_VIDEO:
763  if (amv_file_format) {
764  st->codecpar->width = avih_width;
765  st->codecpar->height = avih_height;
768  avio_skip(pb, size);
769  break;
770  }
771  tag1 = ff_get_bmp_header(pb, st, &esize);
772 
773  if (tag1 == MKTAG('D', 'X', 'S', 'B') ||
774  tag1 == MKTAG('D', 'X', 'S', 'A')) {
776  st->codecpar->codec_tag = tag1;
778  break;
779  }
780 
781  if (size > 10 * 4 && size < (1 << 30) && size < avi->fsize) {
782  if (esize == size-1 && (esize&1)) {
783  st->codecpar->extradata_size = esize - 10 * 4;
784  } else
785  st->codecpar->extradata_size = size - 10 * 4;
786  if (st->codecpar->extradata) {
787  av_log(s, AV_LOG_WARNING, "New extradata in strf chunk, freeing previous one.\n");
788  }
789  ret = ff_get_extradata(s, st->codecpar, pb,
790  st->codecpar->extradata_size);
791  if (ret < 0)
792  return ret;
793  }
794 
795  // FIXME: check if the encoder really did this correctly
796  if (st->codecpar->extradata_size & 1)
797  avio_r8(pb);
798 
799  /* Extract palette from extradata if bpp <= 8.
800  * This code assumes that extradata contains only palette.
801  * This is true for all paletted codecs implemented in
802  * FFmpeg. */
803  if (st->codecpar->extradata_size &&
804  (st->codecpar->bits_per_coded_sample <= 8)) {
805  int pal_size = (1 << st->codecpar->bits_per_coded_sample) << 2;
806  const uint8_t *pal_src;
807 
808  pal_size = FFMIN(pal_size, st->codecpar->extradata_size);
809  pal_src = st->codecpar->extradata +
810  st->codecpar->extradata_size - pal_size;
811  /* Exclude the "BottomUp" field from the palette */
812  if (pal_src - st->codecpar->extradata >= 9 &&
813  !memcmp(st->codecpar->extradata + st->codecpar->extradata_size - 9, "BottomUp", 9))
814  pal_src -= 9;
815  for (i = 0; i < pal_size / 4; i++)
816  ast->pal[i] = 0xFFU<<24 | AV_RL32(pal_src + 4 * i);
817  ast->has_pal = 1;
818  }
819 
820  print_tag(s, "video", tag1, 0);
821 
823  st->codecpar->codec_tag = tag1;
825  tag1);
826  /* If codec is not found yet, try with the mov tags. */
827  if (!st->codecpar->codec_id) {
828  st->codecpar->codec_id =
830  if (st->codecpar->codec_id)
832  "mov tag found in avi (fourcc %s)\n",
833  av_fourcc2str(tag1));
834  }
835  if (!st->codecpar->codec_id)
837 
838  /* This is needed to get the pict type which is necessary
839  * for generating correct pts. */
841 
842  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 &&
843  ast->handler == MKTAG('X', 'V', 'I', 'D'))
844  st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D');
845 
846  if (st->codecpar->codec_tag == MKTAG('V', 'S', 'S', 'H'))
848  if (st->codecpar->codec_id == AV_CODEC_ID_RV40)
850  if (st->codecpar->codec_id == AV_CODEC_ID_HEVC &&
851  st->codecpar->codec_tag == MKTAG('H', '2', '6', '5'))
853 
854  if (st->codecpar->codec_id == AV_CODEC_ID_AVRN &&
855  st->codecpar->codec_tag == MKTAG('A', 'V', 'R', 'n') &&
856  (st->codecpar->extradata_size < 31 ||
857  memcmp(&st->codecpar->extradata[28], "1:1", 3)))
859 
860  if (st->codecpar->codec_tag == 0 && st->codecpar->height > 0 &&
861  st->codecpar->extradata_size < 1U << 30) {
862  st->codecpar->extradata_size += 9;
863  if ((ret = av_reallocp(&st->codecpar->extradata,
864  st->codecpar->extradata_size +
866  st->codecpar->extradata_size = 0;
867  return ret;
868  } else
869  memcpy(st->codecpar->extradata + st->codecpar->extradata_size - 9,
870  "BottomUp", 9);
871  }
872  if (st->codecpar->height == INT_MIN)
873  return AVERROR_INVALIDDATA;
874  st->codecpar->height = FFABS(st->codecpar->height);
875 
876 // avio_skip(pb, size - 5 * 4);
877  break;
878  case AVMEDIA_TYPE_AUDIO:
879  ret = ff_get_wav_header(s, pb, st->codecpar, size, 0);
880  if (ret < 0)
881  return ret;
883  if (ast->sample_size && st->codecpar->block_align &&
884  ast->sample_size != st->codecpar->block_align) {
885  av_log(s,
887  "sample size (%d) != block align (%d)\n",
888  ast->sample_size,
889  st->codecpar->block_align);
890  ast->sample_size = st->codecpar->block_align;
891  }
892  /* 2-aligned
893  * (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
894  if (size & 1)
895  avio_skip(pb, 1);
896  /* Force parsing as several audio frames can be in
897  * one packet and timestamps refer to packet start. */
899  /* ADTS header is in extradata, AAC without header must be
900  * stored as exact frames. Parser not needed and it will
901  * fail. */
902  if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
905  // The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS
906  if (st->codecpar->codec_id == AV_CODEC_ID_FLAC)
908  /* AVI files with Xan DPCM audio (wrongly) declare PCM
909  * audio in the header but have Axan as stream_code_tag. */
910  if (ast->handler == AV_RL32("Axan")) {
912  st->codecpar->codec_tag = 0;
913  ast->dshow_block_align = 0;
914  }
915  if (amv_file_format) {
917  ast->dshow_block_align = 0;
918  }
919  if ((st->codecpar->codec_id == AV_CODEC_ID_AAC ||
921  st->codecpar->codec_id == AV_CODEC_ID_MP2 ) && ast->dshow_block_align <= 4 && ast->dshow_block_align) {
922  av_log(s, AV_LOG_DEBUG, "overriding invalid dshow_block_align of %d\n", ast->dshow_block_align);
923  ast->dshow_block_align = 0;
924  }
925  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 1024 && ast->sample_size == 1024 ||
926  st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 4096 && ast->sample_size == 4096 ||
927  st->codecpar->codec_id == AV_CODEC_ID_MP3 && ast->dshow_block_align == 1152 && ast->sample_size == 1152) {
928  av_log(s, AV_LOG_DEBUG, "overriding sample_size\n");
929  ast->sample_size = 0;
930  }
931  break;
934  st->internal->request_probe= 1;
935  avio_skip(pb, size);
936  break;
937  default:
940  st->codecpar->codec_tag = 0;
941  avio_skip(pb, size);
942  break;
943  }
944  }
945  break;
946  case MKTAG('s', 't', 'r', 'd'):
947  if (stream_index >= (unsigned)s->nb_streams
948  || s->streams[stream_index]->codecpar->extradata_size
949  || s->streams[stream_index]->codecpar->codec_tag == MKTAG('H','2','6','4')) {
950  avio_skip(pb, size);
951  } else {
952  uint64_t cur_pos = avio_tell(pb);
953  if (cur_pos < list_end)
954  size = FFMIN(size, list_end - cur_pos);
955  st = s->streams[stream_index];
956 
957  if (size<(1<<30)) {
958  if (st->codecpar->extradata) {
959  av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n");
960  }
961  if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0)
962  goto fail;
963  }
964 
965  if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly
966  avio_r8(pb);
967 
968  ret = avi_extract_stream_metadata(s, st);
969  if (ret < 0) {
970  av_log(s, AV_LOG_WARNING, "could not decoding EXIF data in stream header.\n");
971  }
972  }
973  break;
974  case MKTAG('i', 'n', 'd', 'x'):
975  pos = avio_tell(pb);
976  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !(s->flags & AVFMT_FLAG_IGNIDX) &&
977  avi->use_odml &&
978  read_odml_index(s, 0) < 0 &&
979  (s->error_recognition & AV_EF_EXPLODE))
981  avio_seek(pb, pos + size, SEEK_SET);
982  break;
983  case MKTAG('v', 'p', 'r', 'p'):
984  if (stream_index < (unsigned)s->nb_streams && size > 9 * 4) {
985  AVRational active, active_aspect;
986 
987  st = s->streams[stream_index];
988  avio_rl32(pb);
989  avio_rl32(pb);
990  avio_rl32(pb);
991  avio_rl32(pb);
992  avio_rl32(pb);
993 
994  active_aspect.den = avio_rl16(pb);
995  active_aspect.num = avio_rl16(pb);
996  active.num = avio_rl32(pb);
997  active.den = avio_rl32(pb);
998  avio_rl32(pb); // nbFieldsPerFrame
999 
1000  if (active_aspect.num && active_aspect.den &&
1001  active.num && active.den) {
1002  st->sample_aspect_ratio = av_div_q(active_aspect, active);
1003  av_log(s, AV_LOG_TRACE, "vprp %d/%d %d/%d\n",
1004  active_aspect.num, active_aspect.den,
1005  active.num, active.den);
1006  }
1007  size -= 9 * 4;
1008  }
1009  avio_skip(pb, size);
1010  break;
1011  case MKTAG('s', 't', 'r', 'n'):
1012  case MKTAG('i', 's', 'b', 'j'):
1013  case MKTAG('i', 'n', 'a', 'm'):
1014  case MKTAG('i', 'a', 'r', 't'):
1015  case MKTAG('i', 'c', 'o', 'p'):
1016  case MKTAG('i', 'c', 'm', 't'):
1017  case MKTAG('i', 'g', 'n', 'r'):
1018  case MKTAG('i', 'p', 'o', 'd'):
1019  case MKTAG('i', 's', 'o', 'f'):
1020  if (s->nb_streams) {
1021  ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
1022  if (ret < 0)
1023  goto fail;
1024  break;
1025  }
1026  default:
1027  if (size > 1000000) {
1029  "Something went wrong during header parsing, "
1030  "tag %s has size %u, "
1031  "I will ignore it and try to continue anyway.\n",
1032  av_fourcc2str(tag), size);
1033  if (s->error_recognition & AV_EF_EXPLODE)
1035  avi->movi_list = avio_tell(pb) - 4;
1036  avi->movi_end = avi->fsize;
1037  goto end_of_header;
1038  }
1039  /* Do not fail for very large idx1 tags */
1040  case MKTAG('i', 'd', 'x', '1'):
1041  /* skip tag */
1042  size += (size & 1);
1043  avio_skip(pb, size);
1044  break;
1045  }
1046  }
1047 
1048 end_of_header:
1049  /* check stream number */
1050  if (stream_index != s->nb_streams - 1) {
1052  }
1053 
1054  if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))
1055  avi_load_index(s);
1057  avi->index_loaded |= 1;
1058 
1059  if ((ret = guess_ni_flag(s)) < 0)
1060  goto fail;
1061 
1062  avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS);
1063 
1064  dict_entry = av_dict_get(s->metadata, "ISFT", NULL, 0);
1065  if (dict_entry && !strcmp(dict_entry->value, "PotEncoder"))
1066  for (i = 0; i < s->nb_streams; i++) {
1067  AVStream *st = s->streams[i];
1071  }
1072 
1073  for (i = 0; i < s->nb_streams; i++) {
1074  AVStream *st = s->streams[i];
1075  if (st->nb_index_entries)
1076  break;
1077  }
1078  // DV-in-AVI cannot be non-interleaved, if set this must be
1079  // a mis-detection.
1080  if (avi->dv_demux)
1081  avi->non_interleaved = 0;
1082  if (i == s->nb_streams && avi->non_interleaved) {
1084  "Non-interleaved AVI without index, switching to interleaved\n");
1085  avi->non_interleaved = 0;
1086  }
1087 
1088  if (avi->non_interleaved) {
1089  av_log(s, AV_LOG_INFO, "non-interleaved AVI\n");
1090  clean_index(s);
1091  }
1092 
1095 
1096  return 0;
1097 fail:
1098  avi_read_close(s);
1099  return ret;
1100 }
1101 
1103 {
1104  if (pkt->size >= 7 &&
1105  pkt->size < INT_MAX - AVPROBE_PADDING_SIZE &&
1106  !strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data + 5) == 2) {
1107  uint8_t desc[256];
1108  int score = AVPROBE_SCORE_EXTENSION, ret;
1109  AVIStream *ast = st->priv_data;
1110  ff_const59 AVInputFormat *sub_demuxer;
1111  AVRational time_base;
1112  int size;
1113  AVProbeData pd;
1114  unsigned int desc_len;
1115 
1116  if (ast->sub_ctx)
1117  return 0;
1118 
1120  pkt->size - 7,
1121  0, NULL, NULL, NULL, NULL);
1122  if (!pb)
1123  goto error;
1124 
1125  desc_len = avio_rl32(pb);
1126 
1127  if (desc_len > pb->buf_end - pb->buf_ptr)
1128  goto error;
1129 
1130  ret = avio_get_str16le(pb, desc_len, desc, sizeof(desc));
1131  avio_skip(pb, desc_len - ret);
1132  if (*desc)
1133  av_dict_set(&st->metadata, "title", desc, 0);
1134 
1135  avio_rl16(pb); /* flags? */
1136  avio_rl32(pb); /* data size */
1137 
1138  size = pb->buf_end - pb->buf_ptr;
1140  .buf_size = size };
1141  if (!pd.buf)
1142  goto error;
1143  memcpy(pd.buf, pb->buf_ptr, size);
1144  sub_demuxer = av_probe_input_format2(&pd, 1, &score);
1145  av_freep(&pd.buf);
1146  if (!sub_demuxer)
1147  goto error;
1148 
1149  if (strcmp(sub_demuxer->name, "srt") && strcmp(sub_demuxer->name, "ass"))
1150  goto error;
1151 
1152  if (!(ast->sub_pkt = av_packet_alloc()))
1153  goto error;
1154 
1155  if (!(ast->sub_ctx = avformat_alloc_context()))
1156  goto error;
1157 
1158  ast->sub_ctx->pb = pb;
1159 
1160  if (ff_copy_whiteblacklists(ast->sub_ctx, s) < 0)
1161  goto error;
1162 
1163  if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) {
1164  if (ast->sub_ctx->nb_streams != 1)
1165  goto error;
1166  ff_read_packet(ast->sub_ctx, ast->sub_pkt);
1168  time_base = ast->sub_ctx->streams[0]->time_base;
1169  avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
1170  }
1171  ast->sub_buffer = pkt->buf;
1172  pkt->buf = NULL;
1174  return 1;
1175 
1176 error:
1177  av_packet_free(&ast->sub_pkt);
1178  av_freep(&ast->sub_ctx);
1179  avio_context_free(&pb);
1180  }
1181  return 0;
1182 }
1183 
1185  AVPacket *pkt)
1186 {
1187  AVIStream *ast, *next_ast = next_st->priv_data;
1188  int64_t ts, next_ts, ts_min = INT64_MAX;
1189  AVStream *st, *sub_st = NULL;
1190  int i;
1191 
1192  next_ts = av_rescale_q(next_ast->frame_offset, next_st->time_base,
1193  AV_TIME_BASE_Q);
1194 
1195  for (i = 0; i < s->nb_streams; i++) {
1196  st = s->streams[i];
1197  ast = st->priv_data;
1198  if (st->discard < AVDISCARD_ALL && ast && ast->sub_pkt && ast->sub_pkt->data) {
1199  ts = av_rescale_q(ast->sub_pkt->dts, st->time_base, AV_TIME_BASE_Q);
1200  if (ts <= next_ts && ts < ts_min) {
1201  ts_min = ts;
1202  sub_st = st;
1203  }
1204  }
1205  }
1206 
1207  if (sub_st) {
1208  ast = sub_st->priv_data;
1210  pkt->stream_index = sub_st->index;
1211 
1212  if (ff_read_packet(ast->sub_ctx, ast->sub_pkt) < 0)
1213  ast->sub_pkt->data = NULL;
1214  }
1215  return sub_st;
1216 }
1217 
1218 static int get_stream_idx(const unsigned *d)
1219 {
1220  if (d[0] >= '0' && d[0] <= '9' &&
1221  d[1] >= '0' && d[1] <= '9') {
1222  return (d[0] - '0') * 10 + (d[1] - '0');
1223  } else {
1224  return 100; // invalid stream ID
1225  }
1226 }
1227 
1228 /**
1229  *
1230  * @param exit_early set to 1 to just gather packet position without making the changes needed to actually read & return the packet
1231  */
1232 static int avi_sync(AVFormatContext *s, int exit_early)
1233 {
1234  AVIContext *avi = s->priv_data;
1235  AVIOContext *pb = s->pb;
1236  int n;
1237  unsigned int d[8];
1238  unsigned int size;
1239  int64_t i, sync;
1240 
1241 start_sync:
1242  memset(d, -1, sizeof(d));
1243  for (i = sync = avio_tell(pb); !avio_feof(pb); i++) {
1244  int j;
1245 
1246  for (j = 0; j < 7; j++)
1247  d[j] = d[j + 1];
1248  d[7] = avio_r8(pb);
1249 
1250  size = d[4] + (d[5] << 8) + (d[6] << 16) + (d[7] << 24);
1251 
1252  n = get_stream_idx(d + 2);
1253  ff_tlog(s, "%X %X %X %X %X %X %X %X %"PRId64" %u %d\n",
1254  d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
1255  if (i*(avi->io_fsize>0) + (uint64_t)size > avi->fsize || d[0] > 127)
1256  continue;
1257 
1258  // parse ix##
1259  if ((d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) ||
1260  // parse JUNK
1261  (d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') ||
1262  (d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1') ||
1263  (d[0] == 'i' && d[1] == 'n' && d[2] == 'd' && d[3] == 'x')) {
1264  avio_skip(pb, size);
1265  goto start_sync;
1266  }
1267 
1268  // parse stray LIST
1269  if (d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T') {
1270  avio_skip(pb, 4);
1271  goto start_sync;
1272  }
1273 
1274  n = get_stream_idx(d);
1275 
1276  if (!((i - avi->last_pkt_pos) & 1) &&
1277  get_stream_idx(d + 1) < s->nb_streams)
1278  continue;
1279 
1280  // detect ##ix chunk and skip
1281  if (d[2] == 'i' && d[3] == 'x' && n < s->nb_streams) {
1282  avio_skip(pb, size);
1283  goto start_sync;
1284  }
1285 
1286  if (d[2] == 'w' && d[3] == 'c' && n < s->nb_streams) {
1287  avio_skip(pb, 16 * 3 + 8);
1288  goto start_sync;
1289  }
1290 
1291  if (avi->dv_demux && n != 0)
1292  continue;
1293 
1294  // parse ##dc/##wb
1295  if (n < s->nb_streams) {
1296  AVStream *st;
1297  AVIStream *ast;
1298  st = s->streams[n];
1299  ast = st->priv_data;
1300 
1301  if (!ast) {
1302  av_log(s, AV_LOG_WARNING, "Skipping foreign stream %d packet\n", n);
1303  continue;
1304  }
1305 
1306  if (s->nb_streams >= 2) {
1307  AVStream *st1 = s->streams[1];
1308  AVIStream *ast1 = st1->priv_data;
1309  // workaround for broken small-file-bug402.avi
1310  if (ast1 && d[2] == 'w' && d[3] == 'b'
1311  && n == 0
1312  && st ->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
1314  && ast->prefix == 'd'*256+'c'
1315  && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count)
1316  ) {
1317  n = 1;
1318  st = st1;
1319  ast = ast1;
1321  "Invalid stream + prefix combination, assuming audio.\n");
1322  }
1323  }
1324 
1325  if (d[2] == 'p' && d[3] == 'c' && size <= 4 * 256 + 4) {
1326  int k = avio_r8(pb);
1327  int last = (k + avio_r8(pb) - 1) & 0xFF;
1328 
1329  avio_rl16(pb); // flags
1330 
1331  // b + (g << 8) + (r << 16);
1332  for (; k <= last; k++)
1333  ast->pal[k] = 0xFFU<<24 | avio_rb32(pb)>>8;
1334 
1335  ast->has_pal = 1;
1336  goto start_sync;
1337  } else if (((ast->prefix_count < 5 || sync + 9 > i) &&
1338  d[2] < 128 && d[3] < 128) ||
1339  d[2] * 256 + d[3] == ast->prefix /* ||
1340  (d[2] == 'd' && d[3] == 'c') ||
1341  (d[2] == 'w' && d[3] == 'b') */) {
1342  if (exit_early)
1343  return 0;
1344  if (d[2] * 256 + d[3] == ast->prefix)
1345  ast->prefix_count++;
1346  else {
1347  ast->prefix = d[2] * 256 + d[3];
1348  ast->prefix_count = 0;
1349  }
1350 
1351  if (!avi->dv_demux &&
1352  ((st->discard >= AVDISCARD_DEFAULT && size == 0) /* ||
1353  // FIXME: needs a little reordering
1354  (st->discard >= AVDISCARD_NONKEY &&
1355  !(pkt->flags & AV_PKT_FLAG_KEY)) */
1356  || st->discard >= AVDISCARD_ALL)) {
1357 
1358  ast->frame_offset += get_duration(ast, size);
1359  avio_skip(pb, size);
1360  goto start_sync;
1361  }
1362 
1363  avi->stream_index = n;
1364  ast->packet_size = size + 8;
1365  ast->remaining = size;
1366 
1367  if (size) {
1368  uint64_t pos = avio_tell(pb) - 8;
1369  if (!st->index_entries || !st->nb_index_entries ||
1370  st->index_entries[st->nb_index_entries - 1].pos < pos) {
1372  0, AVINDEX_KEYFRAME);
1373  }
1374  }
1375  return 0;
1376  }
1377  }
1378  }
1379 
1380  if (pb->error)
1381  return pb->error;
1382  return AVERROR_EOF;
1383 }
1384 
1386 {
1387  AVIContext *avi = s->priv_data;
1388  int best_stream_index = 0;
1389  AVStream *best_st = NULL;
1390  AVIStream *best_ast;
1391  int64_t best_ts = INT64_MAX;
1392  int i;
1393 
1394  for (i = 0; i < s->nb_streams; i++) {
1395  AVStream *st = s->streams[i];
1396  AVIStream *ast = st->priv_data;
1397  int64_t ts = ast->frame_offset;
1398  int64_t last_ts;
1399 
1400  if (!st->nb_index_entries)
1401  continue;
1402 
1403  last_ts = st->index_entries[st->nb_index_entries - 1].timestamp;
1404  if (!ast->remaining && ts > last_ts)
1405  continue;
1406 
1407  ts = av_rescale_q(ts, st->time_base,
1408  (AVRational) { FFMAX(1, ast->sample_size),
1409  AV_TIME_BASE });
1410 
1411  av_log(s, AV_LOG_TRACE, "%"PRId64" %d/%d %"PRId64"\n", ts,
1412  st->time_base.num, st->time_base.den, ast->frame_offset);
1413  if (ts < best_ts) {
1414  best_ts = ts;
1415  best_st = st;
1416  best_stream_index = i;
1417  }
1418  }
1419  if (!best_st)
1420  return AVERROR_EOF;
1421 
1422  best_ast = best_st->priv_data;
1423  best_ts = best_ast->frame_offset;
1424  if (best_ast->remaining) {
1425  i = av_index_search_timestamp(best_st,
1426  best_ts,
1427  AVSEEK_FLAG_ANY |
1429  } else {
1430  i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
1431  if (i >= 0)
1432  best_ast->frame_offset = best_st->index_entries[i].timestamp;
1433  }
1434 
1435  if (i >= 0) {
1436  int64_t pos = best_st->index_entries[i].pos;
1437  pos += best_ast->packet_size - best_ast->remaining;
1438  if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
1439  return AVERROR_EOF;
1440 
1441  av_assert0(best_ast->remaining <= best_ast->packet_size);
1442 
1443  avi->stream_index = best_stream_index;
1444  if (!best_ast->remaining)
1445  best_ast->packet_size =
1446  best_ast->remaining = best_st->index_entries[i].size;
1447  }
1448  else
1449  return AVERROR_EOF;
1450 
1451  return 0;
1452 }
1453 
1455 {
1456  AVIContext *avi = s->priv_data;
1457  AVIOContext *pb = s->pb;
1458  int err;
1459 
1460  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1461  int size = avpriv_dv_get_packet(avi->dv_demux, pkt);
1462  if (size >= 0)
1463  return size;
1464  else
1465  goto resync;
1466  }
1467 
1468  if (avi->non_interleaved) {
1469  err = ni_prepare_read(s);
1470  if (err < 0)
1471  return err;
1472  }
1473 
1474 resync:
1475  if (avi->stream_index >= 0) {
1476  AVStream *st = s->streams[avi->stream_index];
1477  AVIStream *ast = st->priv_data;
1478  int dv_demux = CONFIG_DV_DEMUXER && avi->dv_demux;
1479  int size, err;
1480 
1481  if (get_subtitle_pkt(s, st, pkt))
1482  return 0;
1483 
1484  // minorityreport.AVI block_align=1024 sample_size=1 IMA-ADPCM
1485  if (ast->sample_size <= 1)
1486  size = INT_MAX;
1487  else if (ast->sample_size < 32)
1488  // arbitrary multiplier to avoid tiny packets for raw PCM data
1489  size = 1024 * ast->sample_size;
1490  else
1491  size = ast->sample_size;
1492 
1493  if (size > ast->remaining)
1494  size = ast->remaining;
1495  avi->last_pkt_pos = avio_tell(pb);
1496  err = av_get_packet(pb, pkt, size);
1497  if (err < 0)
1498  return err;
1499  size = err;
1500 
1501  if (ast->has_pal && pkt->size < (unsigned)INT_MAX / 2 && !dv_demux) {
1502  uint8_t *pal;
1505  AVPALETTE_SIZE);
1506  if (!pal) {
1508  "Failed to allocate data for palette\n");
1509  } else {
1510  memcpy(pal, ast->pal, AVPALETTE_SIZE);
1511  ast->has_pal = 0;
1512  }
1513  }
1514 
1515  if (CONFIG_DV_DEMUXER && dv_demux) {
1516  AVBufferRef *avbuf = pkt->buf;
1518  pkt->data, pkt->size, pkt->pos);
1519  pkt->buf = avbuf;
1521  if (size < 0)
1523  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
1524  !st->codecpar->codec_tag && read_gab2_sub(s, st, pkt)) {
1525  ast->frame_offset++;
1526  avi->stream_index = -1;
1527  ast->remaining = 0;
1528  goto resync;
1529  } else {
1530  /* XXX: How to handle B-frames in AVI? */
1531  pkt->dts = ast->frame_offset;
1532 // pkt->dts += ast->start;
1533  if (ast->sample_size)
1534  pkt->dts /= ast->sample_size;
1535  pkt->stream_index = avi->stream_index;
1536 
1537  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) {
1538  AVIndexEntry *e;
1539  int index;
1540 
1542  e = &st->index_entries[index];
1543 
1544  if (index >= 0 && e->timestamp == ast->frame_offset) {
1545  if (index == st->nb_index_entries-1) {
1546  int key=1;
1547  uint32_t state=-1;
1548  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1549  const uint8_t *ptr = pkt->data, *end = ptr + FFMIN(size, 256);
1550  while (ptr < end) {
1551  ptr = avpriv_find_start_code(ptr, end, &state);
1552  if (state == 0x1B6 && ptr < end) {
1553  key = !(*ptr & 0xC0);
1554  break;
1555  }
1556  }
1557  }
1558  if (!key)
1559  e->flags &= ~AVINDEX_KEYFRAME;
1560  }
1561  if (e->flags & AVINDEX_KEYFRAME)
1563  }
1564  } else {
1566  }
1567  ast->frame_offset += get_duration(ast, pkt->size);
1568  }
1569  ast->remaining -= err;
1570  if (!ast->remaining) {
1571  avi->stream_index = -1;
1572  ast->packet_size = 0;
1573  }
1574 
1575  if (!avi->non_interleaved && pkt->pos >= 0 && ast->seek_pos > pkt->pos) {
1577  goto resync;
1578  }
1579  ast->seek_pos= 0;
1580 
1581  if (!avi->non_interleaved && st->nb_index_entries>1 && avi->index_loaded>1) {
1583 
1584  if (avi->dts_max < dts) {
1585  avi->dts_max = dts;
1586  } else if (avi->dts_max - (uint64_t)dts > 2*AV_TIME_BASE) {
1587  avi->non_interleaved= 1;
1588  av_log(s, AV_LOG_INFO, "Switching to NI mode, due to poor interleaving\n");
1589  }
1590  }
1591 
1592  return 0;
1593  }
1594 
1595  if ((err = avi_sync(s, 0)) < 0)
1596  return err;
1597  goto resync;
1598 }
1599 
1600 /* XXX: We make the implicit supposition that the positions are sorted
1601  * for each stream. */
1603 {
1604  AVIContext *avi = s->priv_data;
1605  AVIOContext *pb = s->pb;
1606  int nb_index_entries, i;
1607  AVStream *st;
1608  AVIStream *ast;
1609  int64_t pos;
1610  unsigned int index, tag, flags, len, first_packet = 1;
1611  int64_t last_pos = -1;
1612  unsigned last_idx = -1;
1613  int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1614  int anykey = 0;
1615 
1616  nb_index_entries = size / 16;
1617  if (nb_index_entries <= 0)
1618  return AVERROR_INVALIDDATA;
1619 
1620  idx1_pos = avio_tell(pb);
1621  avio_seek(pb, avi->movi_list + 4, SEEK_SET);
1622  if (avi_sync(s, 1) == 0)
1623  first_packet_pos = avio_tell(pb) - 8;
1624  avi->stream_index = -1;
1625  avio_seek(pb, idx1_pos, SEEK_SET);
1626 
1627  if (s->nb_streams == 1 && s->streams[0]->codecpar->codec_tag == AV_RL32("MMES")) {
1628  first_packet_pos = 0;
1629  data_offset = avi->movi_list;
1630  }
1631 
1632  /* Read the entries and sort them in each stream component. */
1633  for (i = 0; i < nb_index_entries; i++) {
1634  if (avio_feof(pb))
1635  return -1;
1636 
1637  tag = avio_rl32(pb);
1638  flags = avio_rl32(pb);
1639  pos = avio_rl32(pb);
1640  len = avio_rl32(pb);
1641  av_log(s, AV_LOG_TRACE, "%d: tag=0x%x flags=0x%x pos=0x%"PRIx64" len=%d/",
1642  i, tag, flags, pos, len);
1643 
1644  index = ((tag & 0xff) - '0') * 10;
1645  index += (tag >> 8 & 0xff) - '0';
1646  if (index >= s->nb_streams)
1647  continue;
1648  st = s->streams[index];
1649  ast = st->priv_data;
1650 
1651  /* Skip 'xxpc' palette change entries in the index until a logic
1652  * to process these is properly implemented. */
1653  if ((tag >> 16 & 0xff) == 'p' && (tag >> 24 & 0xff) == 'c')
1654  continue;
1655 
1656  if (first_packet && first_packet_pos) {
1657  if (avi->movi_list + 4 != pos || pos + 500 > first_packet_pos)
1658  data_offset = first_packet_pos - pos;
1659  first_packet = 0;
1660  }
1661  pos += data_offset;
1662 
1663  av_log(s, AV_LOG_TRACE, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
1664 
1665  // even if we have only a single stream, we should
1666  // switch to non-interleaved to get correct timestamps
1667  if (last_pos == pos)
1668  avi->non_interleaved = 1;
1669  if (last_idx != pos && len) {
1670  av_add_index_entry(st, pos, ast->cum_len, len, 0,
1671  (flags & AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);
1672  last_idx= pos;
1673  }
1674  ast->cum_len += get_duration(ast, len);
1675  last_pos = pos;
1676  anykey |= flags&AVIIF_INDEX;
1677  }
1678  if (!anykey) {
1679  for (index = 0; index < s->nb_streams; index++) {
1680  st = s->streams[index];
1681  if (st->nb_index_entries)
1683  }
1684  }
1685  return 0;
1686 }
1687 
1688 /* Scan the index and consider any file with streams more than
1689  * 2 seconds or 64MB apart non-interleaved. */
1691 {
1692  int64_t min_pos, pos;
1693  int i;
1694  int *idx = av_mallocz_array(s->nb_streams, sizeof(*idx));
1695  if (!idx)
1696  return AVERROR(ENOMEM);
1697  for (min_pos = pos = 0; min_pos != INT64_MAX; pos = min_pos + 1LU) {
1698  int64_t max_dts = INT64_MIN / 2;
1699  int64_t min_dts = INT64_MAX / 2;
1700  int64_t max_buffer = 0;
1701 
1702  min_pos = INT64_MAX;
1703 
1704  for (i = 0; i < s->nb_streams; i++) {
1705  AVStream *st = s->streams[i];
1706  AVIStream *ast = st->priv_data;
1707  int n = st->nb_index_entries;
1708  while (idx[i] < n && st->index_entries[idx[i]].pos < pos)
1709  idx[i]++;
1710  if (idx[i] < n) {
1711  int64_t dts;
1712  dts = av_rescale_q(st->index_entries[idx[i]].timestamp /
1713  FFMAX(ast->sample_size, 1),
1714  st->time_base, AV_TIME_BASE_Q);
1715  min_dts = FFMIN(min_dts, dts);
1716  min_pos = FFMIN(min_pos, st->index_entries[idx[i]].pos);
1717  }
1718  }
1719  for (i = 0; i < s->nb_streams; i++) {
1720  AVStream *st = s->streams[i];
1721  AVIStream *ast = st->priv_data;
1722 
1723  if (idx[i] && min_dts != INT64_MAX / 2) {
1724  int64_t dts, delta_dts;
1725  dts = av_rescale_q(st->index_entries[idx[i] - 1].timestamp /
1726  FFMAX(ast->sample_size, 1),
1727  st->time_base, AV_TIME_BASE_Q);
1728  delta_dts = av_sat_sub64(dts, min_dts);
1729  max_dts = FFMAX(max_dts, dts);
1730  max_buffer = FFMAX(max_buffer,
1731  av_rescale(delta_dts,
1732  st->codecpar->bit_rate,
1733  AV_TIME_BASE));
1734  }
1735  }
1736  if (av_sat_sub64(max_dts, min_dts) > 2 * AV_TIME_BASE ||
1737  max_buffer > 1024 * 1024 * 8 * 8) {
1738  av_free(idx);
1739  return 1;
1740  }
1741  }
1742  av_free(idx);
1743  return 0;
1744 }
1745 
1747 {
1748  int i;
1749  int64_t last_start = 0;
1750  int64_t first_end = INT64_MAX;
1751  int64_t oldpos = avio_tell(s->pb);
1752 
1753  for (i = 0; i < s->nb_streams; i++) {
1754  AVStream *st = s->streams[i];
1755  int n = st->nb_index_entries;
1756  unsigned int size;
1757 
1758  if (n <= 0)
1759  continue;
1760 
1761  if (n >= 2) {
1762  int64_t pos = st->index_entries[0].pos;
1763  unsigned tag[2];
1764  avio_seek(s->pb, pos, SEEK_SET);
1765  tag[0] = avio_r8(s->pb);
1766  tag[1] = avio_r8(s->pb);
1767  avio_rl16(s->pb);
1768  size = avio_rl32(s->pb);
1769  if (get_stream_idx(tag) == i && pos + size > st->index_entries[1].pos)
1770  last_start = INT64_MAX;
1771  if (get_stream_idx(tag) == i && size == st->index_entries[0].size + 8)
1772  last_start = INT64_MAX;
1773  }
1774 
1775  if (st->index_entries[0].pos > last_start)
1776  last_start = st->index_entries[0].pos;
1777  if (st->index_entries[n - 1].pos < first_end)
1778  first_end = st->index_entries[n - 1].pos;
1779  }
1780  avio_seek(s->pb, oldpos, SEEK_SET);
1781 
1782  if (last_start > first_end)
1783  return 1;
1784 
1785  return check_stream_max_drift(s);
1786 }
1787 
1789 {
1790  AVIContext *avi = s->priv_data;
1791  AVIOContext *pb = s->pb;
1792  uint32_t tag, size;
1793  int64_t pos = avio_tell(pb);
1794  int64_t next;
1795  int ret = -1;
1796 
1797  if (avio_seek(pb, avi->movi_end, SEEK_SET) < 0)
1798  goto the_end; // maybe truncated file
1799  av_log(s, AV_LOG_TRACE, "movi_end=0x%"PRIx64"\n", avi->movi_end);
1800  for (;;) {
1801  tag = avio_rl32(pb);
1802  size = avio_rl32(pb);
1803  if (avio_feof(pb))
1804  break;
1805  next = avio_tell(pb);
1806  if (next < 0 || next > INT64_MAX - size - (size & 1))
1807  break;
1808  next += size + (size & 1LL);
1809 
1810  if (tag == MKTAG('i', 'd', 'x', '1') &&
1811  avi_read_idx1(s, size) >= 0) {
1812  avi->index_loaded=2;
1813  ret = 0;
1814  }else if (tag == MKTAG('L', 'I', 'S', 'T')) {
1815  uint32_t tag1 = avio_rl32(pb);
1816 
1817  if (tag1 == MKTAG('I', 'N', 'F', 'O'))
1818  ff_read_riff_info(s, size - 4);
1819  }else if (!ret)
1820  break;
1821 
1822  if (avio_seek(pb, next, SEEK_SET) < 0)
1823  break; // something is wrong here
1824  }
1825 
1826 the_end:
1827  avio_seek(pb, pos, SEEK_SET);
1828  return ret;
1829 }
1830 
1831 static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
1832 {
1833  AVIStream *ast2 = st2->priv_data;
1834  int64_t ts2 = av_rescale_q(timestamp, st->time_base, st2->time_base);
1835  av_packet_unref(ast2->sub_pkt);
1836  if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 ||
1837  avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
1838  ff_read_packet(ast2->sub_ctx, ast2->sub_pkt);
1839 }
1840 
1841 static int avi_read_seek(AVFormatContext *s, int stream_index,
1842  int64_t timestamp, int flags)
1843 {
1844  AVIContext *avi = s->priv_data;
1845  AVStream *st;
1846  int i, index;
1847  int64_t pos, pos_min;
1848  AVIStream *ast;
1849 
1850  /* Does not matter which stream is requested dv in avi has the
1851  * stream information in the first video stream.
1852  */
1853  if (avi->dv_demux)
1854  stream_index = 0;
1855 
1856  if (!avi->index_loaded) {
1857  /* we only load the index on demand */
1858  avi_load_index(s);
1859  avi->index_loaded |= 1;
1860  }
1861  av_assert0(stream_index >= 0);
1862 
1863  st = s->streams[stream_index];
1864  ast = st->priv_data;
1866  timestamp * FFMAX(ast->sample_size, 1),
1867  flags);
1868  if (index < 0) {
1869  if (st->nb_index_entries > 0)
1870  av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n",
1871  timestamp * FFMAX(ast->sample_size, 1),
1872  st->index_entries[0].timestamp,
1874  return AVERROR_INVALIDDATA;
1875  }
1876 
1877  /* find the position */
1878  pos = st->index_entries[index].pos;
1879  timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
1880 
1881  av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n",
1882  timestamp, index, st->index_entries[index].timestamp);
1883 
1884  if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1885  /* One and only one real stream for DV in AVI, and it has video */
1886  /* offsets. Calling with other stream indexes should have failed */
1887  /* the av_index_search_timestamp call above. */
1888 
1889  if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1890  return -1;
1891 
1892  /* Feed the DV video stream version of the timestamp to the */
1893  /* DV demux so it can synthesize correct timestamps. */
1894  ff_dv_offset_reset(avi->dv_demux, timestamp);
1895 
1896  avi->stream_index = -1;
1897  return 0;
1898  }
1899 
1900  pos_min = pos;
1901  for (i = 0; i < s->nb_streams; i++) {
1902  AVStream *st2 = s->streams[i];
1903  AVIStream *ast2 = st2->priv_data;
1904 
1905  ast2->packet_size =
1906  ast2->remaining = 0;
1907 
1908  if (ast2->sub_ctx) {
1909  seek_subtitle(st, st2, timestamp);
1910  continue;
1911  }
1912 
1913  if (st2->nb_index_entries <= 0)
1914  continue;
1915 
1916 // av_assert1(st2->codecpar->block_align);
1918  av_rescale_q(timestamp,
1919  st->time_base,
1920  st2->time_base) *
1921  FFMAX(ast2->sample_size, 1),
1922  flags |
1925  if (index < 0)
1926  index = 0;
1927  ast2->seek_pos = st2->index_entries[index].pos;
1928  pos_min = FFMIN(pos_min,ast2->seek_pos);
1929  }
1930  for (i = 0; i < s->nb_streams; i++) {
1931  AVStream *st2 = s->streams[i];
1932  AVIStream *ast2 = st2->priv_data;
1933 
1934  if (ast2->sub_ctx || st2->nb_index_entries <= 0)
1935  continue;
1936 
1938  st2,
1939  av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
1941  if (index < 0)
1942  index = 0;
1943  while (!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min)
1944  index--;
1945  ast2->frame_offset = st2->index_entries[index].timestamp;
1946  }
1947 
1948  /* do the seek */
1949  if (avio_seek(s->pb, pos_min, SEEK_SET) < 0) {
1950  av_log(s, AV_LOG_ERROR, "Seek failed\n");
1951  return -1;
1952  }
1953  avi->stream_index = -1;
1954  avi->dts_max = INT_MIN;
1955  return 0;
1956 }
1957 
1959 {
1960  int i;
1961  AVIContext *avi = s->priv_data;
1962 
1963  for (i = 0; i < s->nb_streams; i++) {
1964  AVStream *st = s->streams[i];
1965  AVIStream *ast = st->priv_data;
1966  if (ast) {
1967  if (ast->sub_ctx) {
1968  av_freep(&ast->sub_ctx->pb);
1970  }
1971  av_buffer_unref(&ast->sub_buffer);
1972  av_packet_free(&ast->sub_pkt);
1973  }
1974  }
1975 
1976  av_freep(&avi->dv_demux);
1977 
1978  return 0;
1979 }
1980 
1981 static int avi_probe(const AVProbeData *p)
1982 {
1983  int i;
1984 
1985  /* check file header */
1986  for (i = 0; avi_headers[i][0]; i++)
1987  if (AV_RL32(p->buf ) == AV_RL32(avi_headers[i] ) &&
1988  AV_RL32(p->buf + 8) == AV_RL32(avi_headers[i] + 4))
1989  return AVPROBE_SCORE_MAX;
1990 
1991  return 0;
1992 }
1993 
1995  .name = "avi",
1996  .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
1997  .priv_data_size = sizeof(AVIContext),
1998  .extensions = "avi",
1999  .read_probe = avi_probe,
2004  .priv_class = &demuxer_class,
2005 };
#define U(x)
Definition: vp56_arith.h:37
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:1184
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: avidec.c:1841
static int avi_sync(AVFormatContext *s, int exit_early)
Definition: avidec.c:1232
static int avi_extract_stream_metadata(AVFormatContext *s, AVStream *st)
Definition: avidec.c:408
static int avi_load_index(AVFormatContext *s)
Definition: avidec.c:1788
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:1602
static int get_duration(AVIStream *ast, int len)
Definition: avidec.c:135
static int check_stream_max_drift(AVFormatContext *s)
Definition: avidec.c:1690
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:1981
#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:1385
#define RETURN_ERROR(code)
Definition: avidec.c:490
AVInputFormat ff_avi_demuxer
Definition: avidec.c:1994
static int avi_read_close(AVFormatContext *s)
Definition: avidec.c:1958
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:1831
static int get_stream_idx(const unsigned *d)
Definition: avidec.c:1218
static void clean_index(AVFormatContext *s)
Definition: avidec.c:289
static int guess_ni_flag(AVFormatContext *s)
Definition: avidec.c:1746
static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition: avidec.c:1102
static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: avidec.c:1454
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:98
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:545
@ 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