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