[Ffmpeg-devel] noise in wav converted from mp2
Alex
alex.ctn
Tue Jul 5 11:31:45 CEST 2005
I have a raw mp2 file whose sample rate is 44100hz, with bitrate
128kb/s. It's okay to be played by RealPlayer or iTune. My following
code snippet converts it to wav file. It works, but there is also
some noise. Could you tell me what's wrong?
Thanks.
------------------------------------------
av_register_all();
codec = avcodec_find_decoder(CODEC_ID_MP2);
c = avcodec_alloc_context();
avcodec_open(c, codec);
ReSampleContext * rsc = audio_resample_init(1, 1, 8000, 44100);
while (size = GetPacket(inbuf) > 0) { // raw mp2 packet
inbuf_ptr = inbuf;
while (size > 0) {
len = avcodec_decode_audio(c, (short *)outbuf, &out_size, inbuf_ptr, size);
if (out_size > 0) {
pcm_out_size = 2 * audio_resample(rsc, (short*)pcm_outbuf,
(short*)outbuf, out_size / 2);
SaveWAV(pcm_outbuf, pcm_out_size);
}
size -= len;
inbuf_ptr += len;
}
}
More information about the ffmpeg-devel
mailing list