diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2004-11-06 19:11:34 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2004-11-06 19:11:34 +0000 |
commit | 359fa0febc878066cbb31102e1ee709374054015 (patch) | |
tree | 6162497090306a8e6d99ebff0b19a15aae119d11 /libavformat | |
parent | 70122f2902c815e395be44bc4097cbf6164ef3f5 (diff) | |
download | ffmpeg-359fa0febc878066cbb31102e1ee709374054015.tar.gz |
cbr audio muxing fix
Originally committed as revision 3661 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/avienc.c | 57 | ||||
-rw-r--r-- | libavformat/wav.c | 2 |
2 files changed, 22 insertions, 37 deletions
diff --git a/libavformat/avienc.c b/libavformat/avienc.c index 5f53df6368..30721ec1fe 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -251,33 +251,24 @@ void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags put_byte(pb, 0); } -static void parse_specific_params(AVCodecContext *stream, int *au_byterate, int *au_ssize, int *au_scale) +static void parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale) { - switch(stream->codec_id) { - case CODEC_ID_PCM_S16LE: - *au_scale = *au_ssize = 2*stream->channels; - *au_byterate = *au_ssize * stream->sample_rate; - break; - case CODEC_ID_PCM_U8: - case CODEC_ID_PCM_ALAW: - case CODEC_ID_PCM_MULAW: - *au_scale = *au_ssize = stream->channels; - *au_byterate = *au_ssize * stream->sample_rate; - break; - case CODEC_ID_MP2: - *au_ssize = 1; - *au_scale = 1; - *au_byterate = stream->bit_rate / 8; - case CODEC_ID_MP3: - *au_ssize = 1; - *au_scale = 1; - *au_byterate = stream->bit_rate / 8; - default: - *au_ssize = 1; - *au_scale = 1; - *au_byterate = stream->bit_rate / 8; - break; + int gcd; + + *au_ssize= stream->block_align; + if(stream->frame_size && stream->sample_rate){ + *au_scale=stream->frame_size; + *au_rate= stream->sample_rate; + }else if(stream->codec_type == CODEC_TYPE_VIDEO){ + *au_scale= stream->frame_rate_base; + *au_rate = stream->frame_rate; + }else{ + *au_scale= stream->block_align ? stream->block_align*8 : 8; + *au_rate = stream->bit_rate; } + gcd= ff_gcd(*au_scale, *au_rate); + *au_scale /= gcd; + *au_rate /= gcd; } static offset_t avi_start_new_riff(AVIContext *avi, ByteIOContext *pb, @@ -595,18 +586,12 @@ static int avi_write_idx1(AVFormatContext *s) if (avi->frames_hdr_strm[n] != 0) { stream = &s->streams[n]->codec; url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET); - if (stream->codec_type == CODEC_TYPE_VIDEO) { - put_le32(pb, stream->frame_number); - if (nb_frames < stream->frame_number) - nb_frames = stream->frame_number; + parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); + if (au_ssize == 0) { + put_le32(pb, stream->frame_number); + nb_frames += stream->frame_number; } else { - if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) { - put_le32(pb, stream->frame_number); - nb_frames += stream->frame_number; - } else { - parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); - put_le32(pb, avi->audio_strm_length[n] / au_ssize); - } + put_le32(pb, avi->audio_strm_length[n] / au_ssize); } } } diff --git a/libavformat/wav.c b/libavformat/wav.c index 4528c8356d..3497126e67 100644 --- a/libavformat/wav.c +++ b/libavformat/wav.c @@ -71,7 +71,7 @@ int put_wav_header(ByteIOContext *pb, AVCodecContext *enc) } if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) { - blkalign = 1; + blkalign = enc->frame_size; //this is wrong, but seems many demuxers dont work if this is set correctly //blkalign = 144 * enc->bit_rate/enc->sample_rate; } else if (enc->block_align != 0) { /* specified by the codec */ blkalign = enc->block_align; |