[Libav-user] recording screen activity with audio on android phone

Basim Ahmad pixar.basim at gmail.com
Wed Apr 24 09:34:39 CEST 2013

Hey all,
i have been working on an android application that records screen activity
of the phone along with user's speech. The video is working fine while the
audio is very noisy and giving a metallic sound. The code snippet for
performing the writing of audio frame by frame :-

static void write_audio_frame(AVFormatContext *oc, AVStream *st) {
AVCodecContext *c;
AVFrame *frame = avcodec_alloc_frame();
AVPacket pkt = { 0 }; // data and size must be 0;

int got_packet, ret;
c = st->codec;
// get_audio_frame(samples, audio_input_frame_size, c->channels);
frame->nb_samples = audio_input_frame_size;

avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt,
(uint8_t *) samples,
audio_input_frame_size * av_get_bytes_per_sample(c->sample_fmt)
* c->channels, 1);

ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet);

if (ret < 0) {
LOGE(3, "Error encoding audio frame: %s\n", av_err2str(ret));
if (!got_packet)
pkt.stream_index = st->index;
/* Write the compressed frame to the media file. */
ret = av_interleaved_write_frame(oc, &pkt);
if (ret != 0) {
LOGE(3, "Error while writing audio frame: %s\n", av_err2str(ret));

Any guidance will be appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130424/74f20aa3/attachment.html>

More information about the Libav-user mailing list