79 #define MAX_ODML_DEPTH 1000
99 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
' ' },
100 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
'X' },
101 {
'R',
'I',
'F',
'F',
'A',
'V',
'I', 0x19 },
102 {
'O',
'N',
'2',
' ',
'O',
'N',
'2',
'f' },
103 {
'R',
'I',
'F',
'F',
'A',
'M',
'V',
' ' },
115 #define print_tag(str, tag, size) \
116 av_dlog(NULL, "pos:%"PRIX64" %s: tag=%c%c%c%c size=0x%x\n", \
117 avio_tell(pb), str, tag & 0xff, \
119 (tag >> 16) & 0xff, \
120 (tag >> 24) & 0xff, \
151 if (header[7] == 0x19)
153 "This file has been generated by a totally broken muxer.\n");
163 int index_sub_type =
avio_r8(pb);
168 int stream_id = ((chunk_id & 0xFF) -
'0') * 10 +
169 ((chunk_id >> 8 & 0xFF) -
'0');
173 int64_t last_pos = -1;
174 int64_t filesize = avi->
fsize;
177 "longs_pre_entry:%d index_type:%d entries_in_use:%d "
178 "chunk_id:%X base:%16"PRIX64
"\n",
185 if (stream_id >= s->
nb_streams || stream_id < 0)
195 if (index_type && longs_pre_entry != 2)
200 if (filesize > 0 && base >= filesize) {
202 if (base >> 32 == (base & 0xFFFFFFFF) &&
203 (base & 0xFFFFFFFF) < filesize &&
204 filesize <= 0xFFFFFFFF)
210 for (i = 0; i < entries_in_use; i++) {
223 if (last_pos == pos || pos == base - 8)
248 if (
avio_seek(pb, offset + 8, SEEK_SET) < 0)
276 int64_t pos,
size, ts;
288 for (j = 0; j <
size; j += max)
303 if (size == UINT_MAX)
317 static const char months[12][4] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
318 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
322 char month[4], time[9],
buffer[64];
325 if (sscanf(date,
"%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d",
326 month, &day, time, &year) == 4) {
327 for (i = 0; i < 12; i++)
329 snprintf(buffer,
sizeof(buffer),
"%.4d-%.2d-%.2d %s",
330 year, i + 1, day, time);
333 }
else if (date[4] ==
'/' && date[7] ==
'/') {
334 date[4] = date[7] =
'-';
345 case MKTAG(
'n',
'c',
't',
'g'):
351 const char *
name = NULL;
355 FFMIN(size,
sizeof(buffer) - 1));
364 name =
"creation_time";
365 if (buffer[4] ==
':' && buffer[7] ==
':')
366 buffer[4] = buffer[7] =
'-';
392 int avih_width = 0, avih_height = 0;
393 int amv_file_format = 0;
394 uint64_t list_end = 0;
423 case MKTAG(
'L',
'I',
'S',
'T'):
430 if (tag1 ==
MKTAG(
'm',
'o',
'v',
'i')) {
438 }
else if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
440 else if (tag1 ==
MKTAG(
'n',
'c',
'd',
't'))
444 case MKTAG(
'I',
'D',
'I',
'T'):
446 unsigned char date[64] = { 0 };
453 case MKTAG(
'd',
'm',
'l',
'h'):
457 case MKTAG(
'a',
'm',
'v',
'h'):
459 case MKTAG(
'a',
'v',
'i',
'h'):
475 case MKTAG(
's',
't',
'r',
'h'):
481 if (tag1 ==
MKTAG(
'p',
'a',
'd',
's')) {
490 st->
id = stream_index;
497 tag1 = stream_index ?
MKTAG(
'a',
'u',
'd',
's')
498 : MKTAG(
'v',
'i',
'd',
's');
502 if (tag1 == MKTAG(
'i',
'a',
'v',
's') ||
503 tag1 == MKTAG(
'i',
'v',
'a',
's')) {
511 if (handler != MKTAG(
'd',
'v',
's',
'd') &&
512 handler != MKTAG(
'd',
'v',
'h',
'd') &&
513 handler != MKTAG(
'd',
'v',
's',
'l'))
524 if (CONFIG_DV_DEMUXER) {
537 if (ast->
scale > 0 && ast->
rate > 0 && dv_dur > 0) {
560 "scale/rate is %u/%u which is invalid. "
561 "(This file has been generated by broken software.)\n",
566 ast->
scale = frame_period;
586 av_dlog(s,
"%"PRIu32
" %"PRIu32
" %d\n",
590 case MKTAG(
'v',
'i',
'd',
's'):
595 case MKTAG(
'a',
'u',
'd',
's'):
598 case MKTAG(
't',
'x',
't',
's'):
601 case MKTAG(
'd',
'a',
't',
's'):
617 case MKTAG(
's',
't',
'r',
'f'):
626 if (cur_pos < list_end)
627 size =
FFMIN(size, list_end - cur_pos);
633 switch (codec_type) {
635 if (amv_file_format) {
645 if (tag1 == MKTAG(
'D',
'X',
'S',
'B') ||
646 tag1 == MKTAG(
'D',
'X',
'S',
'A')) {
653 if (size > 10 * 4 && size < (1 << 30) &&
size < avi->fsize) {
654 if (esize == size-1 && (esize&1)) {
678 for (i = 0; i < pal_size / 4; i++)
679 ast->
pal[i] = 0xFFU<<24 |
AV_RL32(pal_src+4*i);
720 "sample size (%d) != block align (%d)\n",
745 if (amv_file_format) {
774 case MKTAG(
's',
't',
'r',
'd'):
781 if (cur_pos < list_end)
782 size =
FFMIN(size, list_end - cur_pos);
794 case MKTAG(
'i',
'n',
'd',
'x'):
803 case MKTAG(
'v',
'p',
'r',
'p'):
804 if (stream_index < (
unsigned)s->
nb_streams && size > 9 * 4) {
820 if (active_aspect.
num && active_aspect.
den &&
821 active.
num && active.
den) {
823 av_dlog(s,
"vprp %d/%d %d/%d\n",
824 active_aspect.
num, active_aspect.
den,
831 case MKTAG(
's',
't',
'r',
'n'):
839 if (size > 1000000) {
841 "Something went wrong during header parsing, "
842 "I will ignore it and try to continue anyway.\n");
870 if (dict_entry && !strcmp(dict_entry->
value,
"PotEncoder"))
889 "Non-interleaved AVI without index, switching to interleaved\n");
906 if (pkt->
size >= 7 &&
915 0, NULL, NULL, NULL, NULL);
947 memset(pkt, 0,
sizeof(*pkt));
960 int64_t ts, next_ts, ts_min = INT64_MAX;
972 if (ts <= next_ts && ts < ts_min) {
992 if (d[0] >=
'0' && d[0] <=
'9' &&
993 d[1] >=
'0' && d[1] <=
'9') {
994 return (d[0] -
'0') * 10 + (d[1] -
'0');
1014 memset(d, -1,
sizeof(d));
1018 for (j = 0; j < 7; j++)
1022 size = d[4] + (d[5] << 8) + (d[6] << 16) + (d[7] << 24);
1025 av_dlog(s,
"%X %X %X %X %X %X %X %X %"PRId64
" %u %d\n",
1026 d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
1027 if (i*(avi->
io_fsize>0) + (uint64_t)size > avi->
fsize || d[0] > 127)
1031 if ((d[0] ==
'i' && d[1] ==
'x' && n < s->nb_streams) ||
1033 (d[0] ==
'J' && d[1] ==
'U' && d[2] ==
'N' && d[3] ==
'K') ||
1034 (d[0] ==
'i' && d[1] ==
'd' && d[2] ==
'x' && d[3] ==
'1')) {
1040 if (d[0] ==
'L' && d[1] ==
'I' && d[2] ==
'S' && d[3] ==
'T') {
1052 if (d[2] ==
'i' && d[3] ==
'x' && n < s->nb_streams) {
1058 if (n < s->nb_streams) {
1073 if ( d[2] ==
'w' && d[3] ==
'b'
1077 && ast->
prefix ==
'd'*256+
'c'
1084 "Invalid stream + prefix combination, assuming audio.\n");
1101 if (d[2] ==
'p' && d[3] ==
'c' && size <= 4 * 256 + 4) {
1103 int last = (k +
avio_r8(pb) - 1) & 0xFF;
1108 for (; k <= last; k++)
1114 d[2] < 128 && d[3] < 128) ||
1115 d[2] * 256 + d[3] == ast->
prefix
1120 if (d[2] * 256 + d[3] == ast->
prefix)
1123 ast->
prefix = d[2] * 256 + d[3];
1154 #if FF_API_DESTRUCT_PACKET
1158 if (CONFIG_DV_DEMUXER && avi->
dv_demux) {
1167 int best_stream_index = 0;
1170 int64_t best_ts = INT64_MAX;
1190 av_dlog(s,
"%"PRId64
" %d/%d %"PRId64
"\n", ts,
1191 st->time_base.num, st->time_base.den, ast->frame_offset);
1195 best_stream_index = i;
1201 best_ast = best_st->priv_data;
1202 best_ts = best_ast->frame_offset;
1203 if (best_ast->remaining) {
1211 best_ast->frame_offset = best_st->index_entries[i].timestamp;
1215 int64_t pos = best_st->index_entries[i].pos;
1216 pos += best_ast->packet_size - best_ast->remaining;
1220 av_assert0(best_ast->remaining <= best_ast->packet_size);
1223 if (!best_ast->remaining)
1224 best_ast->packet_size =
1225 best_ast->remaining = best_st->index_entries[i].size;
1232 if (avi->stream_index >= 0) {
1233 AVStream *st =
s->streams[avi->stream_index];
1264 "Failed to allocate data for palette\n");
1271 if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1273 #if FF_API_DESTRUCT_PACKET
1280 #if FF_API_DESTRUCT_PACKET
1292 avi->stream_index = -1;
1302 "dts:%"PRId64
" offset:%"PRId64
" %d/%d smpl_siz:%d "
1303 "base:%d st:%d size:%d\n",
1326 for (i=0; i<
FFMIN(size,256); i++) {
1328 if (state == 0x1B6) {
1334 state= (state<<8) +
pkt->
data[i];
1349 avi->stream_index = -1;
1359 if (!avi->non_interleaved && st->
nb_index_entries>1 && avi->index_loaded>1) {
1363 avi->non_interleaved= 1;
1365 }
else if (avi->dts_max < dts)
1383 int nb_index_entries, i;
1387 unsigned last_pos = -1;
1388 unsigned last_idx = -1;
1389 int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1392 nb_index_entries = size / 16;
1393 if (nb_index_entries <= 0)
1404 first_packet_pos = 0;
1409 for (i = 0; i < nb_index_entries; i++) {
1417 av_dlog(s,
"%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
1418 i, tag, flags, pos, len);
1420 index = ((tag & 0xff) -
'0') * 10;
1421 index += (tag >> 8 & 0xff) -
'0';
1427 if (first_packet && first_packet_pos) {
1428 data_offset = first_packet_pos - pos;
1437 if (last_pos == pos)
1439 if (last_idx != pos && len) {
1449 for (index = 0; index < s->
nb_streams; index++) {
1461 int64_t last_start = 0;
1462 int64_t first_end = INT64_MAX;
1465 int64_t min_pos, pos;
1480 last_start = INT64_MAX;
1489 if (last_start > first_end)
1494 for (min_pos=pos=0; min_pos!=INT64_MAX; pos= min_pos+1LU) {
1495 int64_t max_dts = INT64_MIN/2, min_dts= INT64_MAX/2;
1496 min_pos = INT64_MAX;
1537 next =
avio_tell(pb) + size + (size & 1);
1539 av_dlog(s,
"tag=%c%c%c%c size=0x%x\n",
1546 if (tag ==
MKTAG(
'i',
'd',
'x',
'1') &&
1550 }
else if (tag ==
MKTAG(
'L',
'I',
'S',
'T')) {
1553 if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
1578 int64_t timestamp,
int flags)
1583 int64_t pos, pos_min;
1599 st = s->
streams[stream_index];
1606 av_log(s,
AV_LOG_DEBUG,
"Failed to find timestamp %"PRId64
" in index %"PRId64
" .. %"PRId64
"\n",
1617 av_dlog(s,
"XX %"PRId64
" %d %"PRId64
"\n",
1620 if (CONFIG_DV_DEMUXER && avi->
dv_demux) {
1741 .priv_class = &demuxer_class,