77 #define MAX_ODML_DEPTH 1000
97 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
' ' },
98 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
'X' },
99 {
'R',
'I',
'F',
'F',
'A',
'V',
'I', 0x19 },
100 {
'O',
'N',
'2',
' ',
'O',
'N',
'2',
'f' },
101 {
'R',
'I',
'F',
'F',
'A',
'M',
'V',
' ' },
113 #define print_tag(str, tag, size) \
114 av_dlog(NULL, "%s: tag=%c%c%c%c size=0x%x\n", \
117 (tag >> 16) & 0xff, \
118 (tag >> 24) & 0xff, \
149 if (header[7] == 0x19)
151 "This file has been generated by a totally broken muxer.\n");
161 int index_sub_type =
avio_r8(pb);
166 int stream_id = ((chunk_id & 0xFF) -
'0') * 10 +
167 ((chunk_id >> 8 & 0xFF) -
'0');
171 int64_t last_pos = -1;
172 int64_t filesize = avi->
fsize;
175 "longs_pre_entry:%d index_type:%d entries_in_use:%d "
176 "chunk_id:%X base:%16"PRIX64
"\n",
183 if (stream_id >= s->
nb_streams || stream_id < 0)
193 if (index_type && longs_pre_entry != 2)
198 if (filesize > 0 && base >= filesize) {
200 if (base >> 32 == (base & 0xFFFFFFFF) &&
201 (base & 0xFFFFFFFF) < filesize &&
202 filesize <= 0xFFFFFFFF)
208 for (i = 0; i < entries_in_use; i++) {
221 if (last_pos == pos || pos == base - 8)
246 if (
avio_seek(pb, offset + 8, SEEK_SET) < 0)
274 int64_t pos,
size, ts;
286 for (j = 0; j <
size; j += max)
301 if (size == UINT_MAX)
315 static const char months[12][4] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
316 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
320 char month[4], time[9],
buffer[64];
323 if (sscanf(date,
"%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d",
324 month, &day, time, &year) == 4) {
325 for (i = 0; i < 12; i++)
327 snprintf(buffer,
sizeof(buffer),
"%.4d-%.2d-%.2d %s",
328 year, i + 1, day, time);
331 }
else if (date[4] ==
'/' && date[7] ==
'/') {
332 date[4] = date[7] =
'-';
343 case MKTAG(
'n',
'c',
't',
'g'):
349 const char *
name = NULL;
353 FFMIN(size,
sizeof(buffer) - 1));
362 name =
"creation_time";
363 if (buffer[4] ==
':' && buffer[7] ==
':')
364 buffer[4] = buffer[7] =
'-';
390 int avih_width = 0, avih_height = 0;
391 int amv_file_format = 0;
392 uint64_t list_end = 0;
421 case MKTAG(
'L',
'I',
'S',
'T'):
428 if (tag1 ==
MKTAG(
'm',
'o',
'v',
'i')) {
436 }
else if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
438 else if (tag1 ==
MKTAG(
'n',
'c',
'd',
't'))
442 case MKTAG(
'I',
'D',
'I',
'T'):
444 unsigned char date[64] = { 0 };
451 case MKTAG(
'd',
'm',
'l',
'h'):
455 case MKTAG(
'a',
'm',
'v',
'h'):
457 case MKTAG(
'a',
'v',
'i',
'h'):
473 case MKTAG(
's',
't',
'r',
'h'):
479 if (tag1 ==
MKTAG(
'p',
'a',
'd',
's')) {
488 st->
id = stream_index;
495 tag1 = stream_index ?
MKTAG(
'a',
'u',
'd',
's')
496 :
MKTAG(
'v',
'i',
'd',
's');
500 if (tag1 ==
MKTAG(
'i',
'a',
'v',
's') ||
501 tag1 ==
MKTAG(
'i',
'v',
'a',
's')) {
509 if (handler !=
MKTAG(
'd',
'v',
's',
'd') &&
510 handler !=
MKTAG(
'd',
'v',
'h',
'd') &&
511 handler !=
MKTAG(
'd',
'v',
's',
'l'))
522 if (CONFIG_DV_DEMUXER) {
535 if (ast->
scale > 0 && ast->
rate > 0 && dv_dur > 0) {
558 "scale/rate is %u/%u which is invalid. "
559 "(This file has been generated by broken software.)\n",
564 ast->
scale = frame_period;
584 av_dlog(s,
"%"PRIu32
" %"PRIu32
" %d\n",
588 case MKTAG(
'v',
'i',
'd',
's'):
593 case MKTAG(
'a',
'u',
'd',
's'):
596 case MKTAG(
't',
'x',
't',
's'):
599 case MKTAG(
'd',
'a',
't',
's'):
615 case MKTAG(
's',
't',
'r',
'f'):
624 if (cur_pos < list_end)
625 size =
FFMIN(size, list_end - cur_pos);
627 switch (codec_type) {
629 if (amv_file_format) {
639 if (tag1 ==
MKTAG(
'D',
'X',
'S',
'B') ||
640 tag1 ==
MKTAG(
'D',
'X',
'S',
'A')) {
647 if (size > 10 * 4 && size < (1 << 30) && size < avi->fsize) {
648 if (esize == size-1 && (esize&1)) {
675 for (i = 0; i < pal_size / 4; i++)
676 ast->
pal[i] = 0xFFU<<24 |
AV_RL32(pal_src+4*i);
717 "sample size (%d) != block align (%d)\n",
742 if (amv_file_format) {
771 case MKTAG(
's',
't',
'r',
'd'):
778 if (cur_pos < list_end)
779 size =
FFMIN(size, list_end - cur_pos);
792 case MKTAG(
'i',
'n',
'd',
'x'):
801 case MKTAG(
'v',
'p',
'r',
'p'):
802 if (stream_index < (
unsigned)s->
nb_streams && size > 9 * 4) {
818 if (active_aspect.
num && active_aspect.
den &&
819 active.
num && active.
den) {
821 av_dlog(s,
"vprp %d/%d %d/%d\n",
822 active_aspect.
num, active_aspect.
den,
829 case MKTAG(
's',
't',
'r',
'n'):
837 if (size > 1000000) {
839 "Something went wrong during header parsing, "
840 "I will ignore it and try to continue anyway.\n");
868 if (dict_entry && !strcmp(dict_entry->
value,
"PotEncoder"))
887 "Non-interleaved AVI without index, switching to interleaved\n");
904 if (pkt->
size >= 7 &&
913 0, NULL, NULL, NULL, NULL);
945 memset(pkt, 0,
sizeof(*pkt));
958 int64_t ts, next_ts, ts_min = INT64_MAX;
970 if (ts <= next_ts && ts < ts_min) {
990 if (d[0] >=
'0' && d[0] <=
'9' &&
991 d[1] >=
'0' && d[1] <=
'9') {
992 return (d[0] -
'0') * 10 + (d[1] -
'0');
1012 memset(d, -1,
sizeof(d));
1016 for (j = 0; j < 7; j++)
1020 size = d[4] + (d[5] << 8) + (d[6] << 16) + (d[7] << 24);
1023 av_dlog(s,
"%X %X %X %X %X %X %X %X %"PRId64
" %u %d\n",
1024 d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
1025 if (i*(avi->
io_fsize>0) + (uint64_t)size > avi->
fsize || d[0] > 127)
1029 if ((d[0] ==
'i' && d[1] ==
'x' && n < s->nb_streams) ||
1031 (d[0] ==
'J' && d[1] ==
'U' && d[2] ==
'N' && d[3] ==
'K') ||
1032 (d[0] ==
'i' && d[1] ==
'd' && d[2] ==
'x' && d[3] ==
'1')) {
1038 if (d[0] ==
'L' && d[1] ==
'I' && d[2] ==
'S' && d[3] ==
'T') {
1050 if (d[2] ==
'i' && d[3] ==
'x' && n < s->nb_streams) {
1056 if (n < s->nb_streams) {
1071 if ( d[2] ==
'w' && d[3] ==
'b'
1075 && ast->
prefix ==
'd'*256+
'c'
1082 "Invalid stream + prefix combination, assuming audio.\n");
1099 if (d[2] ==
'p' && d[3] ==
'c' && size <= 4 * 256 + 4) {
1101 int last = (k +
avio_r8(pb) - 1) & 0xFF;
1106 for (; k <= last; k++)
1112 d[2] < 128 && d[3] < 128) ||
1113 d[2] * 256 + d[3] == ast->
prefix
1118 if (d[2] * 256 + d[3] == ast->
prefix)
1121 ast->
prefix = d[2] * 256 + d[3];
1152 #if FF_API_DESTRUCT_PACKET
1156 if (CONFIG_DV_DEMUXER && avi->
dv_demux) {
1165 int best_stream_index = 0;
1168 int64_t best_ts = INT64_MAX;
1188 av_dlog(s,
"%"PRId64
" %d/%d %"PRId64
"\n", ts,
1189 st->time_base.num, st->time_base.den, ast->frame_offset);
1193 best_stream_index = i;
1199 best_ast = best_st->priv_data;
1200 best_ts = best_ast->frame_offset;
1201 if (best_ast->remaining) {
1209 best_ast->frame_offset = best_st->index_entries[i].timestamp;
1213 int64_t pos = best_st->index_entries[i].pos;
1214 pos += best_ast->packet_size - best_ast->remaining;
1218 av_assert0(best_ast->remaining <= best_ast->packet_size);
1221 if (!best_ast->remaining)
1222 best_ast->packet_size =
1223 best_ast->remaining = best_st->index_entries[i].size;
1230 if (avi->stream_index >= 0) {
1231 AVStream *st =
s->streams[avi->stream_index];
1262 "Failed to allocate data for palette\n");
1269 if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1271 #if FF_API_DESTRUCT_PACKET
1273 dstr =
pkt->destruct;
1278 #if FF_API_DESTRUCT_PACKET
1280 pkt->destruct = dstr;
1290 avi->stream_index = -1;
1300 "dts:%"PRId64
" offset:%"PRId64
" %d/%d smpl_siz:%d "
1301 "base:%d st:%d size:%d\n",
1324 for (i=0; i<
FFMIN(size,256); i++) {
1326 if (state == 0x1B6) {
1332 state= (state<<8) +
pkt->
data[i];
1347 avi->stream_index = -1;
1357 if (!avi->non_interleaved && st->
nb_index_entries>1 && avi->index_loaded>1) {
1361 avi->non_interleaved= 1;
1363 }
else if (avi->dts_max < dts)
1381 int nb_index_entries, i;
1385 unsigned last_pos = -1;
1386 unsigned last_idx = -1;
1387 int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1390 nb_index_entries = size / 16;
1391 if (nb_index_entries <= 0)
1402 first_packet_pos = 0;
1407 for (i = 0; i < nb_index_entries; i++) {
1415 av_dlog(s,
"%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
1416 i, tag, flags, pos, len);
1418 index = ((tag & 0xff) -
'0') * 10;
1419 index += (tag >> 8 & 0xff) -
'0';
1425 if (first_packet && first_packet_pos) {
1426 data_offset = first_packet_pos - pos;
1435 if (last_pos == pos)
1437 if (last_idx != pos && len) {
1447 for (index = 0; index < s->
nb_streams; index++) {
1459 int64_t last_start = 0;
1460 int64_t first_end = INT64_MAX;
1463 int64_t min_pos, pos;
1478 last_start = INT64_MAX;
1487 if (last_start > first_end)
1492 for (min_pos=pos=0; min_pos!=INT64_MAX; pos= min_pos+1LU) {
1493 int64_t max_dts = INT64_MIN/2, min_dts= INT64_MAX/2;
1494 min_pos = INT64_MAX;
1535 next =
avio_tell(pb) + size + (size & 1);
1537 av_dlog(s,
"tag=%c%c%c%c size=0x%x\n",
1544 if (tag ==
MKTAG(
'i',
'd',
'x',
'1') &&
1548 }
else if (tag ==
MKTAG(
'L',
'I',
'S',
'T')) {
1551 if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
1576 int64_t timestamp,
int flags)
1581 int64_t pos, pos_min;
1597 st = s->
streams[stream_index];
1604 av_log(s,
AV_LOG_DEBUG,
"Failed to find timestamp %"PRId64
" in index %"PRId64
" .. %"PRId64
"\n",
1615 av_dlog(s,
"XX %"PRId64
" %d %"PRId64
"\n",
1618 if (CONFIG_DV_DEMUXER && avi->
dv_demux) {
1739 .priv_class = &demuxer_class,