Try testing your program by reading a raw PCM file from disk, to see if it is ffmpeg's encoding routines (which seems likely if the S16_LE format is working). If you are able to record flawless raw audio with your program, then you'd probably get better answers by asking on the ffmpeg list. Mike Bourgeous On 4/3/07, Mik Ngo <mik.ngo@xxxxxxxxx> wrote: > Hello, > > I am trying to capture the "default" audio output using alsa API and use > ffmpeg to compress the raw stream. I set the captured format to be > SND_PCM_FORMAT_S16_LE and use CODEC_ID_MP2 from ffmpeg to compress the > captured stream. For some reasons, the output stream is corrupted and I can > hear periodic bursting noise in the resulted audio. When I tell ffmpeg to > use CODEC_ID_PCM_S16LE to compress the captured stream, the output stream is > good. Is there any kind of post processing I need to do to the captured > stream before I can compress? Here is roughly what my code looks like: > > ret = snd_pcm_open(&handle, "default", > SND_PCM_STREAM_CAPTURE, 0); > snd_pcm_hw_params_alloca(¶ms); > snd_pcm_hw_params_any(handle, params); > snd_pcm_hw_params_set_access(handle, params, > SND_PCM_ACCESS_RW_INTERLEAVED); > snd_pcm_hw_params_set_format(handle, params, > SND_PCM_FORMAT_S16_LE); > snd_pcm_hw_params_set_channels(handle, params, 2); > snd_pcm_hw_params_set_rate_near(handle, params, > &val, &dir); > frames = 32; > snd_pcm_hw_params_set_period_size_near(handle, > params, &frames, &dir); > audio_buffer_size = frames * 4; /* 2 bytes/sample, 2 channels */ > audio_buffer = av_malloc(audio_buffer_size); > ret = snd_pcm_hw_params(handle, params); > snd_pcm_hw_params_get_period_size(params, > &frames, &dir); > > /* .................... */ > > /* ffmpeg */ > audio_st = av_new_stream(formatContext, 1); > if (!audio_st) { > fprintf(stderr, "Could not alloc audio stream\n"); > exit(1); > } > pAudioCxt = audio_st->codec; > pAudioCxt->codec_id = pOutputFmt->audio_codec; > pAudioCxt->codec_type = CODEC_TYPE_AUDIO; > > /* sample parameters */ > pAudioCxt->bit_rate = 64000; > pAudioCxt->sample_rate = 44100; > pAudioCxt->channels = 2; > > /* find audio codec */ > /*pAudioCodec = > avcodec_find_encoder(pAudioCxt->codec_id);*/ > > /* capture */ > ret = snd_pcm_readi(handle, audio_buffer, frames); > > /* encode */ > out_size = avcodec_encode_audio(pAudioContext, > enc_aud_buff, > audio_buffer_size, (short *)audio_buffer); > > Thanks, > Mik > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Alsa-user mailing list > Alsa-user@xxxxxxxxxxxxxxxxxxxxx > https://lists.sourceforge.net/lists/listinfo/alsa-user > > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Alsa-user mailing list Alsa-user@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/alsa-user