74 #define MAX_ODML_DEPTH 1000
94 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
' ' },
95 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
'X' },
96 {
'R',
'I',
'F',
'F',
'A',
'V',
'I', 0x19},
97 {
'O',
'N',
'2',
' ',
'O',
'N',
'2',
'f' },
98 {
'R',
'I',
'F',
'F',
'A',
'M',
'V',
' ' },
110 #define print_tag(str, tag, size) \
111 av_dlog(NULL, "%s: tag=%c%c%c%c size=0x%x\n", \
114 (tag >> 16) & 0xff, \
115 (tag >> 24) & 0xff, \
145 if(header[7] == 0x19)
146 av_log(s,
AV_LOG_INFO,
"This file has been generated by a totally broken muxer.\n");
155 int index_sub_type =
avio_r8(pb);
160 int stream_id= 10*((chunk_id&0xFF) -
'0') + (((chunk_id>>8)&0xFF) -
'0');
164 int64_t last_pos= -1;
165 int64_t filesize= avi->
fsize;
167 av_dlog(s,
"longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64
"\n",
168 longs_pre_entry,index_type, entries_in_use, chunk_id, base);
170 if(stream_id >= s->
nb_streams || stream_id < 0)
180 if(index_type && longs_pre_entry != 2)
185 if(filesize > 0 && base >= filesize){
187 if(base>>32 == (base & 0xFFFFFFFF) && (base & 0xFFFFFFFF) < filesize && filesize <= 0xFFFFFFFF)
193 for(i=0; i<entries_in_use; i++){
206 if(last_pos == pos || pos == base - 8)
230 if(
avio_seek(pb, offset+8, SEEK_SET) < 0)
257 int64_t pos,
size, ts;
262 while(max < 1024) max+=max;
268 for(j=0; j<
size; j+=max){
277 char key[5] = {0}, *
value;
281 if (size == UINT_MAX)
295 static const char months[12][4] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
296 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
300 char month[4], time[9],
buffer[64];
303 if (sscanf(date,
"%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d",
304 month, &day, time, &year) == 4) {
307 snprintf(buffer,
sizeof(buffer),
"%.4d-%.2d-%.2d %s",
308 year, i+1, day, time);
311 }
else if (date[4] ==
'/' && date[7] ==
'/') {
312 date[4] = date[7] =
'-';
323 case MKTAG(
'n',
'c',
't',
'g'): {
331 FFMIN(size,
sizeof(buffer)-1));
333 case 0x03: name =
"maker";
break;
334 case 0x04: name =
"model";
break;
335 case 0x13: name =
"creation_time";
336 if (buffer[4] ==
':' && buffer[7] ==
':')
337 buffer[4] = buffer[7] =
'-';
357 unsigned int tag, tag1, handler;
363 int avih_width=0, avih_height=0;
364 int amv_file_format=0;
365 uint64_t list_end = 0;
393 case MKTAG(
'L',
'I',
'S',
'T'):
400 if (tag1 ==
MKTAG(
'm',
'o',
'v',
'i')) {
407 else if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
409 else if (tag1 ==
MKTAG(
'n',
'c',
'd',
't'))
413 case MKTAG(
'I',
'D',
'I',
'T'): {
414 unsigned char date[64] = {0};
421 case MKTAG(
'd',
'm',
'l',
'h'):
425 case MKTAG(
'a',
'm',
'v',
'h'):
427 case MKTAG(
'a',
'v',
'i',
'h'):
443 case MKTAG(
's',
't',
'r',
'h'):
449 if(tag1 ==
MKTAG(
'p',
'a',
'd',
's')){
458 st->
id = stream_index;
465 tag1 = stream_index ?
MKTAG(
'a',
'u',
'd',
's') :
MKTAG(
'v',
'i',
'd',
's');
469 if(tag1 ==
MKTAG(
'i',
'a',
'v',
's') || tag1 ==
MKTAG(
'i',
'v',
'a',
's')){
479 if (handler !=
MKTAG(
'd',
'v',
's',
'd') &&
480 handler !=
MKTAG(
'd',
'v',
'h',
'd') &&
481 handler !=
MKTAG(
'd',
'v',
's',
'l'))
492 if (CONFIG_DV_DEMUXER) {
504 if (ast->
scale > 0 && ast->
rate > 0 && dv_dur > 0) {
528 av_log(s,
AV_LOG_WARNING,
"scale/rate is %u/%u which is invalid. (This file has been generated by broken software.)\n", ast->
scale, ast->
rate);
531 ast->
scale = frame_period;
551 av_dlog(s,
"%"PRIu32
" %"PRIu32
" %d\n",
555 case MKTAG(
'v',
'i',
'd',
's'):
560 case MKTAG(
'a',
'u',
'd',
's'):
563 case MKTAG(
't',
'x',
't',
's'):
566 case MKTAG(
'd',
'a',
't',
's'):
577 case MKTAG(
's',
't',
'r',
'f'):
586 if (cur_pos < list_end)
587 size =
FFMIN(size, list_end - cur_pos);
601 if (tag1 ==
MKTAG(
'D',
'X',
'S',
'B') || tag1 ==
MKTAG(
'D',
'X',
'S',
'A')) {
608 if(size > 10*4 && size<(1<<30) && size < avi->fsize){
631 for (i = 0; i < pal_size/4; i++)
632 ast->
pal[i] = 0xFFU<<24 |
AV_RL32(pal_src+4*i);
679 if (amv_file_format){
708 case MKTAG(
's',
't',
'r',
'd'):
715 if (cur_pos < list_end)
716 size =
FFMIN(size, list_end - cur_pos);
733 case MKTAG(
'i',
'n',
'd',
'x'):
740 case MKTAG(
'v',
'p',
'r',
'p'):
741 if(stream_index < (
unsigned)s->
nb_streams && size > 9*4){
757 if(active_aspect.
num && active_aspect.
den && active.
num && active.
den){
759 av_dlog(s,
"vprp %d/%d %d/%d\n",
760 active_aspect.
num, active_aspect.
den,
767 case MKTAG(
's',
't',
'r',
'n'):
777 "I will ignore it and try to continue anyway.\n");
866 memset(pkt, 0,
sizeof(*pkt));
878 int64_t ts, next_ts, ts_min = INT64_MAX;
890 if (ts <= next_ts && ts < ts_min) {
908 if( d[0] >=
'0' && d[0] <=
'9'
909 && d[1] >=
'0' && d[1] <=
'9'){
910 return (d[0] -
'0') * 10 + (d[1] -
'0');
930 memset(d, -1,
sizeof(d));
938 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
941 av_dlog(s,
"%X %X %X %X %X %X %X %X %"PRId64
" %u %d\n",
942 d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
943 if(i + (uint64_t)size > avi->
fsize || d[0] > 127)
947 if( (d[0] ==
'i' && d[1] ==
'x' && n < s->nb_streams)
949 ||(d[0] ==
'J' && d[1] ==
'U' && d[2] ==
'N' && d[3] ==
'K')
950 ||(d[0] ==
'i' && d[1] ==
'd' && d[2] ==
'x' && d[3] ==
'1')){
956 if(d[0] ==
'L' && d[1] ==
'I' && d[2] ==
'S' && d[3] ==
'T'){
967 if(d[2] ==
'i' && d[3] ==
'x' && n < s->nb_streams){
973 if(n < s->nb_streams){
988 if( d[2] ==
'w' && d[3] ==
'b'
992 && ast->
prefix ==
'd'*256+
'c'
1013 if (d[2] ==
'p' && d[3] ==
'c' && size<=4*256+4) {
1015 int last = (k +
avio_r8(pb) - 1) & 0xFF;
1019 for (; k <= last; k++)
1023 }
else if( ((ast->
prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) ||
1024 d[2]*256+d[3] == ast->
prefix
1030 if(d[2]*256+d[3] == ast->
prefix)
1033 ast->
prefix= d[2]*256+d[3];
1064 if (CONFIG_DV_DEMUXER && avi->
dv_demux) {
1071 int best_stream_index = 0;
1074 int64_t best_ts= INT64_MAX;
1092 av_dlog(s,
"%"PRId64
" %d/%d %"PRId64
"\n", ts,
1093 st->time_base.num, st->time_base.den, ast->frame_offset);
1097 best_stream_index= i;
1103 best_ast = best_st->priv_data;
1104 best_ts = best_ast->frame_offset;
1105 if(best_ast->remaining)
1110 best_ast->frame_offset= best_st->index_entries[i].timestamp;
1114 int64_t pos= best_st->index_entries[i].pos;
1115 pos += best_ast->packet_size - best_ast->remaining;
1119 av_assert0(best_ast->remaining <= best_ast->packet_size);
1122 if(!best_ast->remaining)
1123 best_ast->packet_size=
1124 best_ast->remaining= best_st->index_entries[i].size;
1131 if(avi->stream_index >= 0){
1132 AVStream *st= s->streams[ avi->stream_index ];
1166 if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1177 avi->stream_index = -1;
1186 av_dlog(s,
"dts:%"PRId64
" offset:%"PRId64
" %d/%d smpl_siz:%d base:%d st:%d size:%d\n",
1204 for(i=0; i<
FFMIN(size,256); i++){
1212 state= (state<<8) +
pkt->
data[i];
1227 avi->stream_index= -1;
1237 if(!avi->non_interleaved && st->
nb_index_entries>1 && avi->index_loaded>1){
1241 avi->non_interleaved= 1;
1243 }
else if(avi->dts_max < dts)
1261 int nb_index_entries, i;
1265 unsigned last_pos= -1;
1266 unsigned last_idx= -1;
1267 int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1270 nb_index_entries = size / 16;
1271 if (nb_index_entries <= 0)
1283 first_packet_pos = 0;
1288 for(i = 0; i < nb_index_entries; i++) {
1296 av_dlog(s,
"%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
1297 i, tag, flags, pos, len);
1299 index = ((tag & 0xff) -
'0') * 10;
1300 index += ((tag >> 8) & 0xff) -
'0';
1306 if(first_packet && first_packet_pos && len) {
1307 data_offset = first_packet_pos - pos;
1318 if(last_idx != pos && len) {
1327 for (index = 0; index < s->
nb_streams; index++) {
1338 int64_t last_start=0;
1339 int64_t first_end= INT64_MAX;
1342 int64_t min_pos, pos;
1357 last_start= INT64_MAX;
1366 if (last_start > first_end)
1369 for (min_pos=pos=0; min_pos!=INT64_MAX; pos= min_pos+1LU) {
1370 int64_t max_dts = INT64_MIN/2, min_dts= INT64_MAX/2;
1371 min_pos = INT64_MAX;
1411 next =
avio_tell(pb) + size + (size & 1);
1413 av_dlog(s,
"tag=%c%c%c%c size=0x%x\n",
1420 if (tag ==
MKTAG(
'i',
'd',
'x',
'1') &&
1424 }
else if(tag ==
MKTAG(
'L',
'I',
'S',
'T')) {
1427 if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
1455 int64_t pos, pos_min;
1465 st = s->
streams[stream_index];
1470 av_log(s,
AV_LOG_DEBUG,
"Failed to find timestamp %"PRId64
" in index %"PRId64
" .. %"PRId64
"\n",
1481 av_dlog(s,
"XX %"PRId64
" %d %"PRId64
"\n",
1484 if (CONFIG_DV_DEMUXER && avi->
dv_demux) {
1601 .priv_class = &demuxer_class,