75 #define MAX_ODML_DEPTH 1000
95 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
' ' },
96 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
'X' },
97 {
'R',
'I',
'F',
'F',
'A',
'V',
'I', 0x19},
98 {
'O',
'N',
'2',
' ',
'O',
'N',
'2',
'f' },
99 {
'R',
'I',
'F',
'F',
'A',
'M',
'V',
' ' },
111 #define print_tag(str, tag, size) \
112 av_dlog(NULL, "%s: tag=%c%c%c%c size=0x%x\n", \
115 (tag >> 16) & 0xff, \
116 (tag >> 24) & 0xff, \
146 if(header[7] == 0x19)
147 av_log(s,
AV_LOG_INFO,
"This file has been generated by a totally broken muxer.\n");
156 int index_sub_type =
avio_r8(pb);
161 int stream_id= 10*((chunk_id&0xFF) -
'0') + (((chunk_id>>8)&0xFF) -
'0');
165 int64_t last_pos= -1;
166 int64_t filesize= avi->
fsize;
168 av_dlog(s,
"longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64
"\n",
169 longs_pre_entry,index_type, entries_in_use, chunk_id, base);
171 if(stream_id >= s->
nb_streams || stream_id < 0)
181 if(index_type && longs_pre_entry != 2)
186 if(filesize > 0 && base >= filesize){
188 if(base>>32 == (base & 0xFFFFFFFF) && (base & 0xFFFFFFFF) < filesize && filesize <= 0xFFFFFFFF)
194 for(i=0; i<entries_in_use; i++){
207 if(last_pos == pos || pos == base - 8)
231 if(
avio_seek(pb, offset+8, SEEK_SET) < 0)
258 int64_t pos,
size, ts;
263 while(max < 1024) max+=max;
269 for(j=0; j<
size; j+=max){
278 char key[5] = {0}, *
value;
282 if (size == UINT_MAX)
296 static const char months[12][4] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
297 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
301 char month[4], time[9],
buffer[64];
304 if (sscanf(date,
"%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d",
305 month, &day, time, &year) == 4) {
308 snprintf(buffer,
sizeof(buffer),
"%.4d-%.2d-%.2d %s",
309 year, i+1, day, time);
312 }
else if (date[4] ==
'/' && date[7] ==
'/') {
313 date[4] = date[7] =
'-';
324 case MKTAG(
'n',
'c',
't',
'g'): {
329 const char *
name = NULL;
332 FFMIN(size,
sizeof(buffer)-1));
334 case 0x03: name =
"maker";
break;
335 case 0x04: name =
"model";
break;
336 case 0x13: name =
"creation_time";
337 if (buffer[4] ==
':' && buffer[7] ==
':')
338 buffer[4] = buffer[7] =
'-';
358 unsigned int tag, tag1, handler;
364 int avih_width=0, avih_height=0;
365 int amv_file_format=0;
366 uint64_t list_end = 0;
395 case MKTAG(
'L',
'I',
'S',
'T'):
402 if (tag1 ==
MKTAG(
'm',
'o',
'v',
'i')) {
409 else if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
411 else if (tag1 ==
MKTAG(
'n',
'c',
'd',
't'))
415 case MKTAG(
'I',
'D',
'I',
'T'): {
416 unsigned char date[64] = {0};
423 case MKTAG(
'd',
'm',
'l',
'h'):
427 case MKTAG(
'a',
'm',
'v',
'h'):
429 case MKTAG(
'a',
'v',
'i',
'h'):
445 case MKTAG(
's',
't',
'r',
'h'):
451 if(tag1 ==
MKTAG(
'p',
'a',
'd',
's')){
460 st->
id = stream_index;
467 tag1 = stream_index ?
MKTAG(
'a',
'u',
'd',
's') :
MKTAG(
'v',
'i',
'd',
's');
471 if(tag1 ==
MKTAG(
'i',
'a',
'v',
's') || tag1 ==
MKTAG(
'i',
'v',
'a',
's')){
481 if (handler !=
MKTAG(
'd',
'v',
's',
'd') &&
482 handler !=
MKTAG(
'd',
'v',
'h',
'd') &&
483 handler !=
MKTAG(
'd',
'v',
's',
'l'))
494 if (CONFIG_DV_DEMUXER) {
506 if (ast->
scale > 0 && ast->
rate > 0 && dv_dur > 0) {
530 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);
533 ast->
scale = frame_period;
553 av_dlog(s,
"%"PRIu32
" %"PRIu32
" %d\n",
557 case MKTAG(
'v',
'i',
'd',
's'):
562 case MKTAG(
'a',
'u',
'd',
's'):
565 case MKTAG(
't',
'x',
't',
's'):
568 case MKTAG(
'd',
'a',
't',
's'):
584 case MKTAG(
's',
't',
'r',
'f'):
593 if (cur_pos < list_end)
594 size =
FFMIN(size, list_end - cur_pos);
608 if (tag1 ==
MKTAG(
'D',
'X',
'S',
'B') || tag1 ==
MKTAG(
'D',
'X',
'S',
'A')) {
615 if(size > 10*4 && size<(1<<30) && size < avi->fsize){
638 for (i = 0; i < pal_size/4; i++)
639 ast->
pal[i] = 0xFFU<<24 |
AV_RL32(pal_src+4*i);
686 if (amv_file_format){
715 case MKTAG(
's',
't',
'r',
'd'):
722 if (cur_pos < list_end)
723 size =
FFMIN(size, list_end - cur_pos);
740 case MKTAG(
'i',
'n',
'd',
'x'):
747 case MKTAG(
'v',
'p',
'r',
'p'):
748 if(stream_index < (
unsigned)s->
nb_streams && size > 9*4){
764 if(active_aspect.
num && active_aspect.
den && active.
num && active.
den){
766 av_dlog(s,
"vprp %d/%d %d/%d\n",
767 active_aspect.
num, active_aspect.
den,
774 case MKTAG(
's',
't',
'r',
'n'):
784 "I will ignore it and try to continue anyway.\n");
810 if (dict_entry && !strcmp(dict_entry->
value,
"PotEncoder"))
852 0, NULL, NULL, NULL, NULL);
883 memset(pkt, 0,
sizeof(*pkt));
895 int64_t ts, next_ts, ts_min = INT64_MAX;
907 if (ts <= next_ts && ts < ts_min) {
925 if( d[0] >=
'0' && d[0] <=
'9'
926 && d[1] >=
'0' && d[1] <=
'9'){
927 return (d[0] -
'0') * 10 + (d[1] -
'0');
947 memset(d, -1,
sizeof(d));
955 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
958 av_dlog(s,
"%X %X %X %X %X %X %X %X %"PRId64
" %u %d\n",
959 d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
960 if(i*(avi->
io_fsize>0) + (uint64_t)size > avi->
fsize || d[0] > 127)
964 if( (d[0] ==
'i' && d[1] ==
'x' && n < s->nb_streams)
966 ||(d[0] ==
'J' && d[1] ==
'U' && d[2] ==
'N' && d[3] ==
'K')
967 ||(d[0] ==
'i' && d[1] ==
'd' && d[2] ==
'x' && d[3] ==
'1')){
973 if(d[0] ==
'L' && d[1] ==
'I' && d[2] ==
'S' && d[3] ==
'T'){
984 if(d[2] ==
'i' && d[3] ==
'x' && n < s->nb_streams){
990 if(n < s->nb_streams){
1005 if( d[2] ==
'w' && d[3] ==
'b'
1009 && ast->
prefix ==
'd'*256+
'c'
1030 if (d[2] ==
'p' && d[3] ==
'c' && size<=4*256+4) {
1032 int last = (k +
avio_r8(pb) - 1) & 0xFF;
1036 for (; k <= last; k++)
1040 }
else if( ((ast->
prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) ||
1041 d[2]*256+d[3] == ast->
prefix
1047 if(d[2]*256+d[3] == ast->
prefix)
1050 ast->
prefix= d[2]*256+d[3];
1079 #if FF_API_DESTRUCT_PACKET
1083 if (CONFIG_DV_DEMUXER && avi->
dv_demux) {
1090 int best_stream_index = 0;
1093 int64_t best_ts= INT64_MAX;
1111 av_dlog(s,
"%"PRId64
" %d/%d %"PRId64
"\n", ts,
1112 st->time_base.num, st->time_base.den, ast->frame_offset);
1116 best_stream_index= i;
1122 best_ast = best_st->priv_data;
1123 best_ts = best_ast->frame_offset;
1124 if(best_ast->remaining)
1129 best_ast->frame_offset= best_st->index_entries[i].timestamp;
1133 int64_t pos= best_st->index_entries[i].pos;
1134 pos += best_ast->packet_size - best_ast->remaining;
1138 av_assert0(best_ast->remaining <= best_ast->packet_size);
1141 if(!best_ast->remaining)
1142 best_ast->packet_size=
1143 best_ast->remaining= best_st->index_entries[i].size;
1150 if(avi->stream_index >= 0){
1151 AVStream *st=
s->streams[ avi->stream_index ];
1185 if (CONFIG_DV_DEMUXER && avi->dv_demux) {
1187 #if FF_API_DESTRUCT_PACKET
1188 dstr =
pkt->destruct;
1192 #if FF_API_DESTRUCT_PACKET
1193 pkt->destruct = dstr;
1202 avi->stream_index = -1;
1211 av_dlog(
s,
"dts:%"PRId64
" offset:%"PRId64
" %d/%d smpl_siz:%d base:%d st:%d size:%d\n",
1229 for(i=0; i<
FFMIN(size,256); i++){
1237 state= (state<<8) +
pkt->
data[i];
1252 avi->stream_index= -1;
1262 if(!avi->non_interleaved && st->
nb_index_entries>1 && avi->index_loaded>1){
1266 avi->non_interleaved= 1;
1268 }
else if(avi->dts_max < dts)
1286 int nb_index_entries, i;
1290 unsigned last_pos= -1;
1291 unsigned last_idx= -1;
1292 int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1295 nb_index_entries = size / 16;
1296 if (nb_index_entries <= 0)
1308 first_packet_pos = 0;
1313 for(i = 0; i < nb_index_entries; i++) {
1321 av_dlog(s,
"%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
1322 i, tag, flags, pos, len);
1324 index = ((tag & 0xff) -
'0') * 10;
1325 index += ((tag >> 8) & 0xff) -
'0';
1331 if(first_packet && first_packet_pos && len) {
1332 data_offset = first_packet_pos - pos;
1343 if(last_idx != pos && len) {
1352 for (index = 0; index < s->
nb_streams; index++) {
1363 int64_t last_start=0;
1364 int64_t first_end= INT64_MAX;
1367 int64_t min_pos, pos;
1382 last_start= INT64_MAX;
1391 if (last_start > first_end)
1394 for (min_pos=pos=0; min_pos!=INT64_MAX; pos= min_pos+1LU) {
1395 int64_t max_dts = INT64_MIN/2, min_dts= INT64_MAX/2;
1396 min_pos = INT64_MAX;
1437 next =
avio_tell(pb) + size + (size & 1);
1439 av_dlog(s,
"tag=%c%c%c%c size=0x%x\n",
1446 if (tag ==
MKTAG(
'i',
'd',
'x',
'1') &&
1450 }
else if(tag ==
MKTAG(
'L',
'I',
'S',
'T')) {
1453 if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
1481 int64_t pos, pos_min;
1491 st = s->
streams[stream_index];
1496 av_log(s,
AV_LOG_DEBUG,
"Failed to find timestamp %"PRId64
" in index %"PRId64
" .. %"PRId64
"\n",
1507 av_dlog(s,
"XX %"PRId64
" %d %"PRId64
"\n",
1510 if (CONFIG_DV_DEMUXER && avi->
dv_demux) {
1627 .priv_class = &demuxer_class,