On 2009-08-04 at 13:12:42 [+0200], Shujaat <[email protected]> wrote: > On Tue, Aug 4, 2009 at 3:24 PM, Shujaat <[email protected]> wrote: > > > hello all > > I read an an audio frame from mp3, decode it, resample it and then > > encode it using lame and add that packet to audio stream of an mp4 > > file, in which there is a video stream too. > > > > But the problem is that when I compile this file and then play it the > > video plays well but the audio speed is too slow and some what > > distroted, i mean there is some noise and cracks too. I increased the > > bit rat, sample rate etc but it didnt work. > > > > Anybody Please. > > > > > > Regards, > > Shujaat > > > > > > > Following are my codec settings : > > > > AVCodecContext *c; > > AVStream *st; > > st = av_new_stream(oc, 1); > > if (!st) > > { > > fprintf(stderr, "\nCould not alloc stream\n"); > > exit(1); > > } > > c = st->codec; > > c->codec_id = CODEC_ID_MP3; > > c->codec_type = CODEC_TYPE_AUDIO; > > > c->bit_rate = 128000; > > c->sample_rate = 44100; > > c->channels = 2; > > c->time_base.num = 1; > > c->time_base.den = c->sample_rate; > > c->rc_buffer_size = AUDIO_BUF_SIZE; > > > I initalize the resample context as : > > audio_rasample_init(output channels, input channels, output sample rate, > input sample rate); > > > But the resulting audio is too slow in terms of speed. and there are > cracks and noise.
I just learned how to encode audio yesterday, so I may be wrong, but what I had to do was use a FIFO buffer (see how it's done in ffmpeg.c) to compensate for the fact that encoded audio wants a certain number of frames (AVCodecContext->frame_size) per chunk, which may be different from the number of frames you decode, or simply hardcoded as buffer size. See ffmpeg.c do_audio_out(), towards the bottom, the if(enc->frame_size > 1) block. (If you do not understand what is happening there, don't be sad, I sympathise, basically, you have to know that frame_size is 1 for raw audio, in which case it is otherwise ignored.) Hope this helps & best regards, -Stephan _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
