75 #define MAX_ODML_DEPTH 1000
79 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
' ' },
80 {
'R',
'I',
'F',
'F',
'A',
'V',
'I',
'X' },
81 {
'R',
'I',
'F',
'F',
'A',
'V',
'I', 0x19 },
82 {
'O',
'N',
'2',
' ',
'O',
'N',
'2',
'f' },
83 {
'R',
'I',
'F',
'F',
'A',
'M',
'V',
' ' },
95 #define print_tag(str, tag, size) \
96 av_dlog(NULL, "%s: tag=%c%c%c%c size=0x%x\n", \
100 (tag >> 24) & 0xff, \
131 if (header[7] == 0x19)
133 "This file has been generated by a totally broken muxer.\n");
143 int index_sub_type =
avio_r8(pb);
148 int stream_id = ((chunk_id & 0xFF) -
'0') * 10 +
149 ((chunk_id >> 8 & 0xFF) -
'0');
153 int64_t last_pos = -1;
157 "longs_pre_entry:%d index_type:%d entries_in_use:%d "
158 "chunk_id:%X base:%16"PRIX64
"\n",
165 if (stream_id >= s->
nb_streams || stream_id < 0)
175 if (index_type && longs_pre_entry != 2)
180 if (filesize > 0 && base >= filesize) {
182 if (base >> 32 == (base & 0xFFFFFFFF) &&
183 (base & 0xFFFFFFFF) < filesize &&
184 filesize <= 0xFFFFFFFF)
190 for (i = 0; i < entries_in_use; i++) {
197 av_dlog(s,
"pos:%"PRId64
", len:%X\n", pos, len);
202 if (last_pos == pos || pos == base - 8)
250 int64_t pos,
size, ts;
262 for (j = 0; j <
size; j += max)
277 if (size == UINT_MAX)
291 static const char months[12][4] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
292 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
296 char month[4], time[9],
buffer[64];
299 if (sscanf(date,
"%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d",
300 month, &day, time, &year) == 4) {
301 for (i = 0; i < 12; i++)
303 snprintf(buffer,
sizeof(buffer),
"%.4d-%.2d-%.2d %s",
304 year, i + 1, day, time);
307 }
else if (date[4] ==
'/' && date[7] ==
'/') {
308 date[4] = date[7] =
'-';
319 case MKTAG(
'n',
'c',
't',
'g'):
328 FFMIN(size,
sizeof(buffer) - 1));
337 name =
"creation_time";
338 if (buffer[4] ==
':' && buffer[7] ==
':')
339 buffer[4] = buffer[7] =
'-';
359 unsigned int tag, tag1, handler;
365 int avih_width = 0, avih_height = 0;
366 int amv_file_format = 0;
367 uint64_t list_end = 0;
393 case MKTAG(
'L',
'I',
'S',
'T'):
400 if (tag1 ==
MKTAG(
'm',
'o',
'v',
'i')) {
408 }
else if (tag1 ==
MKTAG(
'I',
'N',
'F',
'O'))
410 else if (tag1 ==
MKTAG(
'n',
'c',
'd',
't'))
414 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')
468 :
MKTAG(
'v',
'i',
'd',
's');
472 if (tag1 ==
MKTAG(
'i',
'a',
'v',
's') ||
473 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'))
505 if (ast->
scale > 0 && ast->
rate > 0 && dv_dur > 0) {
517 assert(stream_index < s->nb_streams);
528 "scale/rate is %"PRIu32
"/%"PRIu32
" which is invalid. "
529 "(This file has been generated by broken software.)\n",
534 ast->
scale = frame_period;
550 av_dlog(s,
"%"PRIu32
" %"PRIu32
" %d\n",
554 case MKTAG(
'v',
'i',
'd',
's'):
559 case MKTAG(
'a',
'u',
'd',
's'):
562 case MKTAG(
't',
'x',
't',
's'):
565 case MKTAG(
'd',
'a',
't',
's'):
577 case MKTAG(
's',
't',
'r',
'f'):
583 if (cur_pos < list_end)
584 size =
FFMIN(size, list_end - cur_pos);
586 switch (codec_type) {
588 if (amv_file_format) {
598 if (tag1 ==
MKTAG(
'D',
'X',
'S',
'B') ||
599 tag1 ==
MKTAG(
'D',
'X',
'S',
'A')) {
606 if (size > 10 * 4 && size < (1 << 30)) {
636 for (i = 0; i < pal_size / 4; i++)
639 memcpy(ast->
pal, pal_src, pal_size);
654 if (tag1 ==
MKTAG(
'A',
'V',
'R',
'n') &&
684 "sample size (%d) != block align (%d)\n",
708 if (amv_file_format) {
726 case MKTAG(
'i',
'n',
'd',
'x'):
734 case MKTAG(
'v',
'p',
'r',
'p'):
735 if (stream_index < (
unsigned)s->
nb_streams && size > 9 * 4) {
751 if (active_aspect.
num && active_aspect.
den &&
752 active.
num && active.
den) {
754 av_dlog(s,
"vprp %d/%d %d/%d\n",
755 active_aspect.
num, active_aspect.
den,
762 case MKTAG(
's',
't',
'r',
'n'):
770 if (size > 1000000) {
772 "Something went wrong during header parsing, "
773 "I will ignore it and try to continue anyway.\n");
810 "Non-interleaved AVI without index, switching to interleaved\n");
827 if (pkt->
size >= 7 &&
868 memset(pkt, 0,
sizeof(*pkt));
881 int64_t ts, next_ts, ts_min = INT64_MAX;
893 if (ts <= next_ts && ts < ts_min) {
913 if (d[0] >=
'0' && d[0] <=
'9' &&
914 d[1] >=
'0' && d[1] <=
'9') {
915 return (d[0] -
'0') * 10 + (d[1] -
'0');
931 memset(d, -1,
sizeof(d));
935 for (j = 0; j < 7; j++)
939 size = d[4] + (d[5] << 8) + (d[6] << 16) + (d[7] << 24);
942 av_dlog(s,
"%X %X %X %X %X %X %X %X %"PRId64
" %u %d\n",
943 d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
944 if (i + (uint64_t)size > avi->
fsize || d[0] > 127)
948 if ((d[0] ==
'i' && d[1] ==
'x' && n < s->nb_streams) ||
950 (d[0] ==
'J' && d[1] ==
'U' && d[2] ==
'N' && d[3] ==
'K') ||
951 (d[0] ==
'i' && d[1] ==
'd' && d[2] ==
'x' && d[3] ==
'1')) {
957 if (d[0] ==
'L' && d[1] ==
'I' && d[2] ==
'S' && d[3] ==
'T') {
969 if (d[2] ==
'i' && d[3] ==
'x' && n < s->nb_streams) {
975 if (n < s->nb_streams) {
985 if (d[2] ==
'w' && d[3] ==
'b' && n == 0 &&
988 ast->
prefix ==
'd' * 256 +
'c' &&
989 (d[2] * 256 + d[3] == ast1->
prefix ||
995 "Invalid stream + prefix combination, assuming audio.\n");
1012 if (d[2] ==
'p' && d[3] ==
'c' && size <= 4 * 256 + 4) {
1014 int last = (k +
avio_r8(pb) - 1) & 0xFF;
1019 for (; k <= last; k++)
1025 d[2] < 128 && d[3] < 128) ||
1026 d[2] * 256 + d[3] == ast->
prefix
1031 if (d[2] * 256 + d[3] == ast->
prefix)
1034 ast->
prefix = d[2] * 256 + d[3];
1063 #if FF_API_DESTRUCT_PACKET
1076 int best_stream_index = 0;
1079 int64_t best_ts = INT64_MAX;
1099 av_dlog(s,
"%"PRId64
" %d/%d %"PRId64
"\n", ts,
1104 best_stream_index = i;
1172 "Failed to allocate data for palette\n");
1181 #if FF_API_DESTRUCT_PACKET
1188 #if FF_API_DESTRUCT_PACKET
1210 "dts:%"PRId64
" offset:%"PRId64
" %d/%d smpl_siz:%d "
1211 "base:%d st:%d size:%d\n",
1258 int nb_index_entries, i;
1262 unsigned last_pos = -1;
1263 int64_t idx1_pos, first_packet_pos = 0, data_offset = 0;
1265 nb_index_entries = size / 16;
1266 if (nb_index_entries <= 0)
1277 for (i = 0; i < nb_index_entries; i++) {
1282 av_dlog(s,
"%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
1283 i, tag, flags, pos, len);
1285 index = ((tag & 0xff) -
'0') * 10;
1286 index += (tag >> 8 & 0xff) -
'0';
1292 if (first_packet && first_packet_pos && len) {
1293 data_offset = first_packet_pos - pos;
1303 if (last_pos == pos)
1318 int64_t min_pos, pos;
1324 for (min_pos = pos = 0; min_pos != INT64_MAX; pos = min_pos + 1LU) {
1325 int64_t max_dts = INT64_MIN / 2;
1326 int64_t min_dts = INT64_MAX / 2;
1327 int64_t max_buffer = 0;
1329 min_pos = INT64_MAX;
1342 min_dts =
FFMIN(min_dts, dts);
1350 if (idx[i] && min_dts != INT64_MAX / 2) {
1355 max_dts =
FFMAX(max_dts, dts);
1356 max_buffer =
FFMAX(max_buffer,
1363 max_buffer > 1024 * 1024 * 8 * 8) {
1375 int64_t last_start = 0;
1376 int64_t first_end = INT64_MAX;
1392 last_start = INT64_MAX;
1402 if (last_start > first_end)
1424 av_dlog(s,
"tag=%c%c%c%c size=0x%x\n",
1431 if (tag ==
MKTAG(
'i',
'd',
'x',
'1') &&
1458 int64_t timestamp,
int flags)
1478 st = s->
streams[stream_index];
1490 av_dlog(s,
"XX %"PRId64
" %d %"PRId64
"\n",
1542 av_dlog(s,
"%"PRId64
" %d %"PRId64
"\n",
1594 .extensions =
"avi",
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) + 'A')...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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
#define AV_LOG_WARNING
Something somehow does not look correct.
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 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)
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)
attribute_deprecated void(* destruct)(struct AVPacket *)
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.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
static void clean_index(AVFormatContext *s)
int flags
Flags modifying the (de)muxer behaviour.
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#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).
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
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)
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
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,...)
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 associated with this stream.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
common internal API header
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
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.
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)
static int read_gab2_sub(AVStream *st, AVPacket *pkt)
#define AV_LOG_INFO
Standard information.
enum AVMediaType codec_type
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
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
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.
A reference to a data buffer.
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)
#define FF_DISABLE_DEPRECATION_WARNINGS
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 eof_reached
true if eof reached
#define FF_ENABLE_DEPRECATION_WARNINGS
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 void * av_mallocz_array(size_t nmemb, size_t size)
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
struct AVStream::@92 * info
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...
#define MKTAG(a, b, c, d)
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