summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2003-03-08 10:57:44 +0000
committerMichael Niedermayer <michaelni@gmx.at>2003-03-08 10:57:44 +0000
commitb559b29b1f9a8ce38f6d23fa4740b74bd5566bd5 (patch)
tree1f8dd705ad49af0d0afde2f98145be56a760e5a8
parent7004ffb3d7274fe95fab7a699b75cc4e6d9092e3 (diff)
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
fixed framerate encoding & decoding hopefully, this should fix av sync on long AVIs Originally committed as revision 1646 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/avformat.h2
-rw-r--r--libavformat/avidec.c42
-rw-r--r--libavformat/avienc.c10
-rw-r--r--libavformat/utils.c5
4 files changed, 47 insertions, 12 deletions
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index a58e73c4fa..f9d435a9b2 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -332,6 +332,8 @@ extern AVOutputFormat yuv4mpegpipe_oformat;
#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,
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 11fe838bcb..cfbcc37911 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -50,7 +50,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
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 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
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 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
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 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
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;
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 9b930f346a..04bc9e6964 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -237,6 +237,8 @@ static int avi_write_header(AVFormatContext *s)
/* stream list */
for(i=0;i<n;i++) {
+ int gcd;
+
list2 = start_tag(pb, "LIST");
put_tag(pb, "strl");
@@ -252,8 +254,12 @@ static int avi_write_header(AVFormatContext *s)
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 */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 93048490fb..5642894ec9 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1316,6 +1316,11 @@ void av_frac_add(AVFrac *f, int64_t incr)
f->num = num;
}
+int av_gcd(int a, int b){
+ if(b) return av_gcd(b, a%b);
+ else return a;
+}
+
/**
* register a new image format
* @param img_fmt Image format descriptor