Mercurial > libavformat.hg
changeset 75:78bec272ce3a libavformat
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
fixed framerate encoding & decoding hopefully, this should fix av sync on long AVIs
author | michaelni |
---|---|
date | Sat, 08 Mar 2003 10:57:44 +0000 |
parents | 4b501fe1539c |
children | d03c70b7b50d |
files | avformat.h avidec.c avienc.c utils.c |
diffstat | 4 files changed, 47 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/avformat.h Sat Mar 08 01:40:52 2003 +0000 +++ b/avformat.h Sat Mar 08 10:57:44 2003 +0000 @@ -332,6 +332,8 @@ #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24)) +int av_gcd(int a, int b); + void av_register_input_format(AVInputFormat *format); void av_register_output_format(AVOutputFormat *format); AVOutputFormat *guess_stream_format(const char *short_name,
--- a/avidec.c Sat Mar 08 01:40:52 2003 +0000 +++ b/avidec.c Sat Mar 08 10:57:44 2003 +0000 @@ -50,7 +50,7 @@ AVIContext *avi = s->priv_data; ByteIOContext *pb = &s->pb; uint32_t tag, tag1; - int codec_type, stream_index, frame_period, bit_rate; + int codec_type, stream_index, frame_period, bit_rate, scale, rate; unsigned int size; int i; AVStream *st; @@ -117,13 +117,29 @@ switch(tag1) { case MKTAG('v', 'i', 'd', 's'): codec_type = CODEC_TYPE_VIDEO; + + if (stream_index >= s->nb_streams) { + url_fskip(pb, size - 4); + break; + } + + st = s->streams[stream_index]; + get_le32(pb); /* codec tag */ get_le32(pb); /* flags */ get_le16(pb); /* priority */ get_le16(pb); /* language */ get_le32(pb); /* XXX: initial frame ? */ - get_le32(pb); /* scale */ - get_le32(pb); /* rate */ + scale= get_le32(pb); /* scale */ + rate= get_le32(pb); /* rate */ + + if(scale && rate) + st->codec.frame_rate= (rate * (uint64_t)FRAME_RATE_BASE + scale/2) / scale; + else if(frame_period) + st->codec.frame_rate = (1000000LL * FRAME_RATE_BASE + frame_period/2) / frame_period; + else + st->codec.frame_rate = 25 * FRAME_RATE_BASE; + url_fskip(pb, size - 7 * 4); break; case MKTAG('a', 'u', 'd', 's'): @@ -146,20 +162,26 @@ get_le32(pb); /* size */ st->codec.width = get_le32(pb); st->codec.height = get_le32(pb); - if (frame_period) - st->codec.frame_rate = (int64_t_C(1000000) * FRAME_RATE_BASE) / frame_period; - else - st->codec.frame_rate = 25 * FRAME_RATE_BASE; get_le16(pb); /* panes */ - get_le16(pb); /* depth */ + st->codec.bits_per_sample= get_le16(pb); /* depth */ tag1 = get_le32(pb); + get_le32(pb); /* ImageSize */ + get_le32(pb); /* XPelsPerMeter */ + get_le32(pb); /* YPelsPerMeter */ + get_le32(pb); /* ClrUsed */ + get_le32(pb); /* ClrImportant */ + + st->codec.extradata_size= size - 10*4; + st->codec.extradata= av_malloc(st->codec.extradata_size); //FIXME where should we free this? + get_buffer(pb, st->codec.extradata, st->codec.extradata_size); + #ifdef DEBUG print_tag("video", tag1, 0); #endif st->codec.codec_type = CODEC_TYPE_VIDEO; st->codec.codec_tag = tag1; st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1); - url_fskip(pb, size - 5 * 4); +// url_fskip(pb, size - 5 * 4); break; case CODEC_TYPE_AUDIO: get_wav_header(pb, &st->codec, (size >= 18)); @@ -197,7 +219,7 @@ AVIContext *avi = s->priv_data; ByteIOContext *pb = &s->pb; int n, d1, d2, size; - + find_next: if (url_feof(pb) || url_ftell(pb) >= avi->movi_end) return -1;
--- a/avienc.c Sat Mar 08 01:40:52 2003 +0000 +++ b/avienc.c Sat Mar 08 10:57:44 2003 +0000 @@ -237,6 +237,8 @@ /* stream list */ for(i=0;i<n;i++) { + int gcd; + list2 = start_tag(pb, "LIST"); put_tag(pb, "strl"); @@ -252,8 +254,12 @@ put_le16(pb, 0); /* priority */ put_le16(pb, 0); /* language */ put_le32(pb, 0); /* initial frame */ - put_le32(pb, 1000); /* scale */ - put_le32(pb, (1000 * stream->frame_rate) / FRAME_RATE_BASE); /* rate */ + + gcd= av_gcd(stream->frame_rate, FRAME_RATE_BASE); + + put_le32(pb, FRAME_RATE_BASE / gcd); /* scale */ + put_le32(pb, stream->frame_rate / gcd); /* rate */ + put_le32(pb, 0); /* start */ avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */ put_le32(pb, nb_frames); /* length, XXX: fill later */