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" };
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'))
473 if (ast->
scale > 0 && ast->
rate > 0 && dv_dur > 0) {
487 assert(stream_index < s->nb_streams);
497 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);
500 ast->
scale = frame_period;
519 case MKTAG(
'v',
'i',
'd',
's'):
524 case MKTAG(
'a',
'u',
'd',
's'):
527 case MKTAG(
't',
'x',
't',
's'):
530 case MKTAG(
'd',
'a',
't',
's'):
542 case MKTAG(
's',
't',
'r',
'f'):
548 if (cur_pos < list_end)
549 size =
FFMIN(size, list_end - cur_pos);
563 if (tag1 ==
MKTAG(
'D',
'X',
'S',
'B') || tag1 ==
MKTAG(
'D',
'X',
'S',
'A')) {
570 if(size > 10*4 && size<(1<<30)){
588 const uint8_t *pal_src;
593 for (i = 0; i < pal_size/4; i++)
596 memcpy(ast->
pal, pal_src, pal_size);
608 if(tag1 ==
MKTAG(
'A',
'V',
'R',
'n') &&
648 if (amv_file_format){
666 case MKTAG(
'i',
'n',
'd',
'x'):
674 case MKTAG(
'v',
'p',
'r',
'p'):
675 if(stream_index < (
unsigned)s->
nb_streams && size > 9*4){
691 if(active_aspect.
num && active_aspect.
den && active.
num && active.
den){
699 case MKTAG(
's',
't',
'r',
'n'):
707 "I will ignore it and try to continue anyway.\n");
758 if (pkt->
size >= 7 &&
798 memset(pkt, 0,
sizeof(*pkt));
822 if (ts <= next_ts && ts < ts_min) {
840 if( d[0] >=
'0' && d[0] <=
'9'
841 && d[1] >=
'0' && d[1] <=
'9'){
842 return (d[0] -
'0') * 10 + (d[1] -
'0');
858 memset(d, -1,
sizeof(d));
866 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
870 if(i + (uint64_t)size > avi->
fsize || d[0] > 127)
874 if( (d[0] ==
'i' && d[1] ==
'x' && n < s->nb_streams)
876 ||(d[0] ==
'J' && d[1] ==
'U' && d[2] ==
'N' && d[3] ==
'K')
877 ||(d[0] ==
'i' && d[1] ==
'd' && d[2] ==
'x' && d[3] ==
'1')){
884 if(d[0] ==
'L' && d[1] ==
'I' && d[2] ==
'S' && d[3] ==
'T'){
895 if(d[2] ==
'i' && d[3] ==
'x' && n < s->nb_streams){
901 if(n < s->nb_streams){
911 if( d[2] ==
'w' && d[3] ==
'b'
915 && ast->
prefix ==
'd'*256+
'c'
939 if (d[2] ==
'p' && d[3] ==
'c' && size<=4*256+4) {
941 int last = (k +
avio_r8(pb) - 1) & 0xFF;
945 for (; k <= last; k++)
949 }
else if( ((ast->
prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) ||
950 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;
1023 best_stream_index= i;
1150 int nb_index_entries, i;
1154 unsigned last_pos= -1;
1155 int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1157 nb_index_entries = size / 16;
1158 if (nb_index_entries <= 0)
1170 for(i = 0; i < nb_index_entries; i++) {
1175 av_dlog(s,
"%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
1176 i, tag, flags, pos, len);
1178 index = ((tag & 0xff) -
'0') * 10;
1179 index += ((tag >> 8) & 0xff) -
'0';
1185 if(first_packet && first_packet_pos && len) {
1186 data_offset = first_packet_pos - pos;
1210 int64_t min_pos, pos;
1216 memset(idx, 0, s->
nb_streams *
sizeof(*idx));
1218 for (min_pos = pos = 0; min_pos !=
INT64_MAX; pos = min_pos + 1LU) {
1221 int64_t max_buffer = 0;
1236 min_dts =
FFMIN(min_dts, dts);
1244 if (idx[i] && min_dts !=
INT64_MAX / 2) {
1249 max_dts =
FFMAX(max_dts, dts);
1250 max_buffer =
FFMAX(max_buffer,
1257 max_buffer > 1024 * 1024 * 8 * 8) {
1268 int64_t last_start=0;
1295 if (last_start > first_end)
1317 av_dlog(s,
"tag=%c%c%c%c size=0x%x\n",
1324 if (tag ==
MKTAG(
'i',
'd',
'x',
'1') &&
1369 st = s->
streams[stream_index];
static AVStream * get_subtitle_pkt(AVFormatContext *s, AVStream *next_st, AVPacket *pkt)
void * av_mallocz(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) + 'A')...
int64_t avio_size(AVIOContext *s)
Get the filesize.
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.
#define AV_LOG_WARNING
Something somehow does not look correct.
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)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
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 int check_stream_max_drift(AVFormatContext *s)
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)
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 int read_header(FFV1Context *f)
void av_free_packet(AVPacket *pkt)
Free a packet.
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
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).
enum CodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
void(* destruct)(struct AVPacket *)
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.
static AVDictionary * metadata
AVInputFormat * av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)
Guess the file format.
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
codec context
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.
int bit_rate
the average bitrate
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
#define AV_TIME_BASE
Internal time base represented as integer.
const AVCodecTag ff_codec_bmp_tags[]
int av_strcasecmp(const char *a, const char *b)
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() and chilren.
int width
picture width / height.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
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 int read_probe(AVProbeData *p)
static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
#define av_dlog(pctx,...)
av_dlog macros Useful to print debug messages that shouldn't get compiled in normally.
codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it ...
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'
static int read_gab2_sub(AVStream *st, AVPacket *pkt)
struct AVIStream AVIStream
enum AVMediaType codec_type
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static int get_stream_idx(int *d)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int avi_read_idx1(AVFormatContext *s, int size)
rational number numerator/denominator
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
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[]
discard useless packets like 0 size packets in avi
static int avi_load_index(AVFormatContext *s)
static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
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)
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)
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 av_read_packet(AVFormatContext *s, AVPacket *pkt)
Read a transport packet from a media file.
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.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define MKTAG(a, b, c, d)
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int ff_read_riff_info(AVFormatContext *s, int64_t size)
uint64_t avio_rl64(AVIOContext *s)
static int avi_sync(AVFormatContext *s, int exit_early)
DVDemuxContext * dv_demux