[Ffmpeg-devel] ffmpeg encode audio problem

Phuoc Do pdo.cloud
Mon Apr 2 05:10:21 CEST 2007


I posted an email describing the problem I have on the user list but haven't
got any reply. Further investigation reveals the more details about the
problem I have. My captured audio input came in as CODEC_ID_PCM_S16LE
format. I am trying to encode the captured audio to CODEC_ID_MP2 format. But
the output mp2 is corrupted and I can hear the burst sound happening
periodically in the stream. Here is roughly what my initialization code
looks like:

    /* ffmpeg audio */
    aStream = av_new_stream(pFormatCtx, 1);
    if (!aStream) {
        fprintf(stderr, "Could not alloc audio stream\n");
    pAudioContext = aStream->codec;
    pAudioContext->codec_id = pOutputFmt->audio_codec;
    pAudioContext->codec_type = CODEC_TYPE_AUDIO;

    /* sample parameters */
    pAudioContext->bit_rate = 64000;
    pAudioContext->sample_rate = 44100;
    pAudioContext->channels = 2;

    /* find audio codec */
    pAudioCodec = avcodec_find_encoder(pAudioContext->codec_id);

If I replace pAudioContext->codec_id with CODEC_ID_PCM_S16LE (no MP2
encoding, just output), the stream audio stream does not have any corrupted
noise. When I use the command line ffmpeg to transcode to MP2 format, the
audio stream is also fine. I read through the thread archives and learned
that I need to do something with the frame_size for PCM_S16LE format. But
it's kinda confusing.

Any suggestion for me?


More information about the ffmpeg-devel mailing list