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