[FFmpeg-user] using libav to resample, alias effects

Jieyun Fu jieyunfu at gmail.com
Thu Apr 21 00:35:28 CEST 2011

Hi all,

I realized that when I am writing my own code to upsample a piece of audio
from 8000Hz to 22050Hz, I always get some alias effects: the sound got buzzy
(with some zee, zee in the background) and looking at the spectrogram we can
see the frequency mirrors around 8K Hz, which is a classical alias effects.

If I use ffmpeg binaries, I don't have this problem. But I do need to use
Libav to achieve that. You guys can download the original raw waveform and
the converted raw waveform from (
http://dl.dropbox.com/u/4363247/ffmpeg/before.raw and

There are two APIs to resample the audio but both produce these alias
effects. Please let me know if I am missing anything.

    newsize = (long) size * 22050 / 8000.0;
    ReSampleContext* context = av_audio_resample_init(1, 1, // out channels,
in channels
                                     22050, 8000,
                                     SAMPLE_FMT_S16, SAMPLE_FMT_S16,
                                     16, 0, 0, 0.8);
    int audio_resample_rc = audio_resample(context,
(short*)converted_samples, (short*)samples, size / 2);
    if (context)


        int out_rate = 22050;
        audio_cntx = av_resample_init( out_rate,    // out rate
            RATE,   // in rate
            16, // filter length
            0,  // phase count
            0,  // linear FIR filter
            0.8 );  // cutoff frequency
        assert( audio_cntx && "Failed to create resampling context!" );

        int samples_consumed = 0;
        int samples_output = av_resample( audio_cntx,
            bytes_read / 2,
            40000 * 4 / 2,
            0 );
        av_resample_close( audio_cntx );


More information about the ffmpeg-user mailing list