mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
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
This commit is contained in:
parent
7004ffb3d7
commit
b559b29b1f
@ -332,6 +332,8 @@ extern AVOutputFormat yuv4mpegpipe_oformat;
|
|||||||
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
|
#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))
|
#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_input_format(AVInputFormat *format);
|
||||||
void av_register_output_format(AVOutputFormat *format);
|
void av_register_output_format(AVOutputFormat *format);
|
||||||
AVOutputFormat *guess_stream_format(const char *short_name,
|
AVOutputFormat *guess_stream_format(const char *short_name,
|
||||||
|
@ -50,7 +50,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
|||||||
AVIContext *avi = s->priv_data;
|
AVIContext *avi = s->priv_data;
|
||||||
ByteIOContext *pb = &s->pb;
|
ByteIOContext *pb = &s->pb;
|
||||||
uint32_t tag, tag1;
|
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;
|
unsigned int size;
|
||||||
int i;
|
int i;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
@ -117,13 +117,29 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
|||||||
switch(tag1) {
|
switch(tag1) {
|
||||||
case MKTAG('v', 'i', 'd', 's'):
|
case MKTAG('v', 'i', 'd', 's'):
|
||||||
codec_type = CODEC_TYPE_VIDEO;
|
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); /* codec tag */
|
||||||
get_le32(pb); /* flags */
|
get_le32(pb); /* flags */
|
||||||
get_le16(pb); /* priority */
|
get_le16(pb); /* priority */
|
||||||
get_le16(pb); /* language */
|
get_le16(pb); /* language */
|
||||||
get_le32(pb); /* XXX: initial frame ? */
|
get_le32(pb); /* XXX: initial frame ? */
|
||||||
get_le32(pb); /* scale */
|
scale= get_le32(pb); /* scale */
|
||||||
get_le32(pb); /* rate */
|
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);
|
url_fskip(pb, size - 7 * 4);
|
||||||
break;
|
break;
|
||||||
case MKTAG('a', 'u', 'd', 's'):
|
case MKTAG('a', 'u', 'd', 's'):
|
||||||
@ -146,20 +162,26 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
|||||||
get_le32(pb); /* size */
|
get_le32(pb); /* size */
|
||||||
st->codec.width = get_le32(pb);
|
st->codec.width = get_le32(pb);
|
||||||
st->codec.height = 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); /* panes */
|
||||||
get_le16(pb); /* depth */
|
st->codec.bits_per_sample= get_le16(pb); /* depth */
|
||||||
tag1 = get_le32(pb);
|
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
|
#ifdef DEBUG
|
||||||
print_tag("video", tag1, 0);
|
print_tag("video", tag1, 0);
|
||||||
#endif
|
#endif
|
||||||
st->codec.codec_type = CODEC_TYPE_VIDEO;
|
st->codec.codec_type = CODEC_TYPE_VIDEO;
|
||||||
st->codec.codec_tag = tag1;
|
st->codec.codec_tag = tag1;
|
||||||
st->codec.codec_id = codec_get_id(codec_bmp_tags, 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;
|
break;
|
||||||
case CODEC_TYPE_AUDIO:
|
case CODEC_TYPE_AUDIO:
|
||||||
get_wav_header(pb, &st->codec, (size >= 18));
|
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;
|
AVIContext *avi = s->priv_data;
|
||||||
ByteIOContext *pb = &s->pb;
|
ByteIOContext *pb = &s->pb;
|
||||||
int n, d1, d2, size;
|
int n, d1, d2, size;
|
||||||
|
|
||||||
find_next:
|
find_next:
|
||||||
if (url_feof(pb) || url_ftell(pb) >= avi->movi_end)
|
if (url_feof(pb) || url_ftell(pb) >= avi->movi_end)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -237,6 +237,8 @@ static int avi_write_header(AVFormatContext *s)
|
|||||||
|
|
||||||
/* stream list */
|
/* stream list */
|
||||||
for(i=0;i<n;i++) {
|
for(i=0;i<n;i++) {
|
||||||
|
int gcd;
|
||||||
|
|
||||||
list2 = start_tag(pb, "LIST");
|
list2 = start_tag(pb, "LIST");
|
||||||
put_tag(pb, "strl");
|
put_tag(pb, "strl");
|
||||||
|
|
||||||
@ -252,8 +254,12 @@ static int avi_write_header(AVFormatContext *s)
|
|||||||
put_le16(pb, 0); /* priority */
|
put_le16(pb, 0); /* priority */
|
||||||
put_le16(pb, 0); /* language */
|
put_le16(pb, 0); /* language */
|
||||||
put_le32(pb, 0); /* initial frame */
|
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 */
|
put_le32(pb, 0); /* start */
|
||||||
avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
|
avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
|
||||||
put_le32(pb, nb_frames); /* length, XXX: fill later */
|
put_le32(pb, nb_frames); /* length, XXX: fill later */
|
||||||
|
@ -1316,6 +1316,11 @@ void av_frac_add(AVFrac *f, int64_t incr)
|
|||||||
f->num = num;
|
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
|
* register a new image format
|
||||||
* @param img_fmt Image format descriptor
|
* @param img_fmt Image format descriptor
|
||||||
|
Loading…
Reference in New Issue
Block a user