71 #define MAX_ODML_DEPTH 1000
75 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
' ' },
76 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
'X' },
77 {
'R',
'I',
'F',
'F',
'A',
'V',
'I', 0x19},
78 {
'O',
'N',
'2',
' ',
'O',
'N',
'2',
'f' },
79 {
'R',
'I',
'F',
'F',
'A',
'M',
'V',
' ' },
91 #define print_tag(str, tag, size) \
92 av_dlog(NULL, "%s: tag=%c%c%c%c size=0x%x\n", \
126 if(header[7] == 0x19)
127 av_log(s,
AV_LOG_INFO,
"This file has been generated by a totally broken muxer.\n");
136 int index_sub_type =
avio_r8(pb);
141 int stream_id= 10*((chunk_id&0xFF) -
'0') + (((chunk_id>>8)&0xFF) -
'0');
145 int64_t last_pos= -1;
148 av_dlog(s,
"longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64
"\n",
149 longs_pre_entry,index_type, entries_in_use, chunk_id, base);
151 if(stream_id >= s->
nb_streams || stream_id < 0)
161 if(index_type && longs_pre_entry != 2)
166 if(filesize > 0 && base >= filesize){
168 if(base>>32 == (base & 0xFFFFFFFF) && (base & 0xFFFFFFFF) < filesize && filesize <= 0xFFFFFFFF)
174 for(i=0; i<entries_in_use; i++){
181 av_dlog(s,
"pos:%"PRId64
", len:%X\n", pos, len);
186 if(last_pos == pos || pos == base - 8)
232 int64_t pos,
size, ts;
237 while(max < 1024) max+=max;
243 for(j=0; j<
size; j+=max){
252 char key[5] = {0}, *value;
256 if (size == UINT_MAX)
270 static const char months[12][4] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
271 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
275 char month[4], time[9],
buffer[64];
278 if (sscanf(date,
"%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d",
279 month, &day, time, &year) == 4) {
282 snprintf(buffer,
sizeof(buffer),
"%.4d-%.2d-%.2d %s",
283 year, i+1, day, time);
286 }
else if (date[4] ==
'/' && date[7] ==
'/') {
287 date[4] = date[7] =
'-';
298 case MKTAG(
'n',
'c',
't',
'g'): {
306 FFMIN(size,
sizeof(buffer)-1));
308 case 0x03: name =
"maker";
break;
309 case 0x04: name =
"model";
break;
310 case 0x13: name =
"creation_time";
311 if (buffer[4] ==
':' && buffer[7] ==
':')
312 buffer[4] = buffer[7] =
'-';
332 unsigned int tag, tag1, handler;
338 int avih_width=0, avih_height=0;
339 int amv_file_format=0;
340 uint64_t list_end = 0;
365 case MKTAG(
'L',
'I',
'S',
'T'):
372 if (tag1 ==
MKTAG(
'm',
'o',
'v',
'i')) {
379 else if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
381 else if (tag1 ==
MKTAG(
'n',
'c',
'd',
't'))
385 case MKTAG(
'I',
'D',
'I',
'T'): {
386 unsigned char date[64] = {0};
393 case MKTAG(
'd',
'm',
'l',
'h'):
397 case MKTAG(
'a',
'm',
'v',
'h'):
399 case MKTAG(
'a',
'v',
'i',
'h'):
415 case MKTAG(
's',
't',
'r',
'h'):
421 if(tag1 ==
MKTAG(
'p',
'a',
'd',
's')){
430 st->
id = stream_index;
437 tag1 = stream_index ?
MKTAG(
'a',
'u',
'd',
's') :
MKTAG(
'v',
'i',
'd',
's');
441 if(tag1 ==
MKTAG(
'i',
'a',
'v',
's') || tag1 ==
MKTAG(
'i',
'v',
'a',
's')){
451 if (handler !=
MKTAG(
'd',
'v',
's',
'd') &&
452 handler !=
MKTAG(
'd',
'v',
'h',
'd') &&
453 handler !=
MKTAG(
'd',
'v',
's',
'l'))
475 if (ast->
scale > 0 && ast->
rate > 0 && dv_dur > 0) {
489 assert(stream_index < s->nb_streams);
499 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);
502 ast->
scale = frame_period;
518 av_dlog(s,
"%"PRIu32
" %"PRIu32
" %d\n",
522 case MKTAG(
'v',
'i',
'd',
's'):
527 case MKTAG(
'a',
'u',
'd',
's'):
530 case MKTAG(
't',
'x',
't',
's'):
533 case MKTAG(
'd',
'a',
't',
's'):
545 case MKTAG(
's',
't',
'r',
'f'):
551 if (cur_pos < list_end)
552 size =
FFMIN(size, list_end - cur_pos);
566 if (tag1 ==
MKTAG(
'D',
'X',
'S',
'B') || tag1 ==
MKTAG(
'D',
'X',
'S',
'A')) {
573 if(size > 10*4 && size<(1<<30)){
596 for (i = 0; i < pal_size/4; i++)
599 memcpy(ast->
pal, pal_src, pal_size);
611 if(tag1 ==
MKTAG(
'A',
'V',
'R',
'n') &&
651 if (amv_file_format){
669 case MKTAG(
'i',
'n',
'd',
'x'):
677 case MKTAG(
'v',
'p',
'r',
'p'):
678 if(stream_index < (
unsigned)s->
nb_streams && size > 9*4){
694 if(active_aspect.
num && active_aspect.
den && active.
num && active.
den){
696 av_dlog(s,
"vprp %d/%d %d/%d\n",
697 active_aspect.
num, active_aspect.
den,
704 case MKTAG(
's',
't',
'r',
'n'):
712 "I will ignore it and try to continue anyway.\n");
759 if (pkt->
size >= 7 &&
799 memset(pkt, 0,
sizeof(*pkt));
811 int64_t ts, next_ts, ts_min = INT64_MAX;
823 if (ts <= next_ts && ts < ts_min) {
841 if( d[0] >=
'0' && d[0] <=
'9'
842 && d[1] >=
'0' && d[1] <=
'9'){
843 return (d[0] -
'0') * 10 + (d[1] -
'0');
859 memset(d, -1,
sizeof(d));
867 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
870 av_dlog(s,
"%X %X %X %X %X %X %X %X %"PRId64
" %u %d\n",
871 d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
872 if(i + (uint64_t)size > avi->
fsize || d[0] > 127)
876 if( (d[0] ==
'i' && d[1] ==
'x' && n < s->nb_streams)
878 ||(d[0] ==
'J' && d[1] ==
'U' && d[2] ==
'N' && d[3] ==
'K')
879 ||(d[0] ==
'i' && d[1] ==
'd' && d[2] ==
'x' && d[3] ==
'1')){
885 if(d[0] ==
'L' && d[1] ==
'I' && d[2] ==
'S' && d[3] ==
'T'){
896 if(d[2] ==
'i' && d[3] ==
'x' && n < s->nb_streams){
902 if(n < s->nb_streams){
912 if( d[2] ==
'w' && d[3] ==
'b'
916 && ast->
prefix ==
'd'*256+
'c'
940 if (d[2] ==
'p' && d[3] ==
'c' && size<=4*256+4) {
942 int last = (k +
avio_r8(pb) - 1) & 0xFF;
946 for (; k <= last; k++)
950 }
else if( ((ast->
prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) ||
951 d[2]*256+d[3] == ast->
prefix
957 if(d[2]*256+d[3] == ast->
prefix)
960 ast->
prefix= d[2]*256+d[3];
998 int best_stream_index = 0;
1001 int64_t best_ts= INT64_MAX;
1019 av_dlog(s,
"%"PRId64
" %d/%d %"PRId64
"\n", ts,
1020 st->time_base.num, st->time_base.den, ast->frame_offset);
1024 best_stream_index= i;
1032 if(best_ast->remaining)
1037 best_ast->frame_offset= best_st->index_entries[i].timestamp;
1041 int64_t pos= best_st->index_entries[i].pos;
1042 pos += best_ast->packet_size - best_ast->remaining;
1045 assert(best_ast->remaining <= best_ast->packet_size);
1048 if(!best_ast->remaining)
1049 best_ast->packet_size=
1050 best_ast->remaining= best_st->index_entries[i].size;
1055 if(avi->stream_index >= 0){
1056 AVStream *st= s->streams[ avi->stream_index ];
1078 if(ast->
has_pal && pkt->data && pkt->size<(
unsigned)INT_MAX/2){
1090 dstr = pkt->destruct;
1092 pkt->data, pkt->size);
1093 pkt->destruct = dstr;
1100 avi->stream_index = -1;
1109 av_dlog(s,
"dts:%"PRId64
" offset:%"PRId64
" %d/%d smpl_siz:%d base:%d st:%d size:%d\n",
1112 pkt->stream_index = avi->stream_index;
1133 avi->stream_index= -1;
1151 int nb_index_entries, i;
1155 unsigned last_pos= -1;
1156 int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1158 nb_index_entries = size / 16;
1159 if (nb_index_entries <= 0)
1171 for(i = 0; i < nb_index_entries; i++) {
1176 av_dlog(s,
"%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
1177 i, tag, flags, pos, len);
1179 index = ((tag & 0xff) -
'0') * 10;
1180 index += ((tag >> 8) & 0xff) -
'0';
1186 if(first_packet && first_packet_pos && len) {
1187 data_offset = first_packet_pos - pos;
1209 int64_t last_start=0;
1210 int64_t first_end= INT64_MAX;
1226 last_start= INT64_MAX;
1235 return last_start > first_end;
1254 av_dlog(s,
"tag=%c%c%c%c size=0x%x\n",
1261 if (tag ==
MKTAG(
'i',
'd',
'x',
'1') &&
1306 st = s->
streams[stream_index];
1316 av_dlog(s,
"XX %"PRId64
" %d %"PRId64
"\n",
1364 av_dlog(s,
"%"PRId64
" %d %"PRId64
"\n",
int ff_read_riff_info(AVFormatContext *s, int64_t size)
codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it ...
static AVStream * get_subtitle_pkt(AVFormatContext *s, AVStream *next_st, AVPacket *pkt)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
unsigned int stream_codec_tag
fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + ...
int64_t avio_size(AVIOContext *s)
Get the filesize.
void av_free_packet(AVPacket *pkt)
Free a packet.
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.
AVFormatContext * sub_ctx
unsigned char * buf_ptr
Current position in the buffer.
unsigned char * buf_end
End of the data, may be less than buffer+buffer_size if the read function returned less data than req...
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int dshow_block_align
block align variable used to emulate bugs in the MS dshow demuxer
int index
stream index in AVFormatContext
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
static int sync(AVFormatContext *s, uint8_t *header)
Read input until we find the next ident.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
enum AVMediaType codec_type
static int get_duration(AVIStream *ast, int len)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
struct AVStream::@75 * info
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.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static const AVMetadataConv avi_metadata_conv[]
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Opaque data information usually continuous.
static int avi_read_close(AVFormatContext *s)
unsigned int avio_rb32(AVIOContext *s)
#define AVFMT_FLAG_IGNIDX
enum AVStreamParseType need_parsing
int id
Format-specific stream ID.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
static void clean_index(AVFormatContext *s)
static av_cold int read_close(AVFormatContext *ctx)
#define MKTAG(a, b, c, d)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_DICT_DONT_STRDUP_VAL
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AVIF_MUSTUSEINDEX
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, 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.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
unsigned int avio_rl32(AVIOContext *s)
int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
static int read_braindead_odml_indx(AVFormatContext *s, int frame_num)
static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag, uint32_t size)
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
AVInputFormat * av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)
Guess the file format.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
unsigned int nb_streams
A list of all streams in the file.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
const AVCodecTag ff_codec_bmp_tags[]
int av_strcasecmp(const char *a, const char *b)
int width
picture width / height.
static int avi_read_header(AVFormatContext *s)
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
static const char months[12][4]
static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
static int read_header(FFV1Context *f)
static const char avi_headers[][8]
static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
int prefix
normally 'd'<<8 + 'c' or 'w'<<8 + 'b'
#define AVSEEK_FLAG_BACKWARD
static int read_gab2_sub(AVStream *st, AVPacket *pkt)
struct AVIStream AVIStream
enum AVMediaType codec_type
AVIOContext * pb
I/O context.
static int get_stream_idx(int *d)
#define CONFIG_DV_DEMUXER
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static int avi_read_idx1(AVFormatContext *s, int size)
rational number numerator/denominator
#define FF_INPUT_BUFFER_PADDING_SIZE
discard useless packets like 0 size packets in avi
static int avi_probe(AVProbeData *p)
This structure contains the data a format has to probe a 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.
const AVMetadataConv ff_riff_info_conv[]
static int avi_load_index(AVFormatContext *s)
AVInputFormat ff_avi_demuxer
int64_t duration
Decoding: duration of the stream, in stream time base.
unsigned int avio_rl16(AVIOContext *s)
static void avi_read_nikon(AVFormatContext *s, uint64_t end)
static void avi_metadata_creation_time(AVDictionary **metadata, char *date)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
int64_t start_time
Decoding: pts of the first frame of the stream, in stream time base.
int error_recognition
Error recognition; higher values will detect more errors but may misdetect some more or less valid pa...
static int get_riff(AVFormatContext *s, AVIOContext *pb)
#define AVPROBE_SCORE_MAX
int64_t nb_frames
number of frames in this stream if known or 0
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
int eof_reached
true if eof reached
static int guess_ni_flag(AVFormatContext *s)
void * priv_data
Format private data.
#define print_tag(str, tag, size)
int ff_get_bmp_header(AVIOContext *pb, AVStream *st)
Read BITMAPINFOHEADER structure and set AVStream codec width, height and bits_per_encoded_sample fiel...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
int64_t duration
Decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
This structure stores compressed data.
uint64_t avio_rl64(AVIOContext *s)
static int avi_sync(AVFormatContext *s, int exit_early)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
DVDemuxContext * dv_demux