[Libav-user] Choppy dshow audio playback with ffplay
Taha Ansari
mtaha.ansari at gmail.com
Tue Apr 2 08:01:39 CEST 2013
Hi!
Thanks for your reply - I just tried your suggestion, and recorded
approximately 1.5 minutes of audio, and saved it to a file on hard-disk (no
UDP involved). There are no cut-offs or choppy playback; all voice is
apparently recorded fine.
So this means above mentioned routines are working properly. So that leaves
UDP channel and decoding/playback on other end. Since managing changing of
destination file (local vs. UDP) is something managed by FFmpeg itself (and
for testing purpose I am always on same network), there are more chances
there is something not optimized on the decoding end.
On Tue, Apr 2, 2013 at 2:33 AM, Roger Pack <rogerdpack2 at gmail.com> wrote:
> what if you just record locally (no UDP) does it die?
>
> On 12/24/12, Taha Ansari <mtaha.ansari at gmail.com> wrote:
> > Hi!
> >
> > I have a small test application that sends microphone audio over network.
> > But the audio playback is sometimes very choppy/lossy, and also I
> initially
> > need to 'seek' ffplay back to hear audio with minimum latency. I do this
> in
> > Windows, using dshow, zeranoe ffmpeg builds, MSVS; and here is custom
> code
> > of relevance (output file is in extension .mp2, and packets are sent on
> > udp. I tried AAC extension as well, but results are somewhat the same):
> >
> > *********** + Decoding part: + *************
> > if(this->packet.stream_index == this->audioStream)
> > {
> > unsigned int samples_size= 0;
> > AVCodecContext *c = outputCodecCtxAudio;
> > int finalPTS = 0;
> > samples = (short *) av_fast_realloc(samples, &samples_size,
> > FFMAX(packet.size, AVCODEC_MAX_AUDIO_FRAME_SIZE));
> > finalPTS = packet.pts;
> > audiobufsize = AVCODEC_MAX_AUDIO_FRAME_SIZE*2;
> > avcodec_decode_audio3(pCodecCtxAudio, samples, &audiobufsize,
> > &packet);
> >
> >
> > if(pCodecCtxAudio->sample_rate != c->sample_rate ||
> > pCodecCtxAudio->channels != c->channels )
> > {
> > if ( rs == NULL)
> > {
> > rs = av_audio_resample_init(c->channels,
> > pCodecCtxAudio->channels, c->sample_rate, pCodecCtxAudio->sample_rate,
> > AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16, 0,0,0,0);
> > }
> > }
> > if(pCodecCtxAudio->sample_rate != c->sample_rate ||
> > pCodecCtxAudio->channels != c->channels)
> > {
> > int size_out = audio_resample(rs, (short *)buffer_resample,
> > samples, audiobufsize/ (pCodecCtxAudio->channels * 2) );
> > av_fifo_generic_write(fifo, (uint8_t *)buffer_resample,
> > size_out * c->channels * 2, NULL );
> > }
> > else
> > {
> > av_fifo_generic_write(fifo, (uint8_t *)samples, audiobufsize,
> > NULL );
> > }
> > }
> > *********** - Decoding part: - *************
> >
> > *********** + Encoding part: + ***************
> > if ( decoderData->audiobufsize )
> > {
> > AVPacket pkt;
> > av_init_packet(&pkt);
> >
> > AVCodecContext* c = encoderData->audio_st->codec;
> >
> > int frame_bytes = c->frame_size * 2 * c->channels;
> >
> > while( av_fifo_size(decoderData->fifo) >= frame_bytes )
> > {
> > int ret = av_fifo_generic_read( decoderData->fifo, data_buf,
> > frame_bytes, NULL );
> > /* encode the samples */
> > pkt.size= avcodec_encode_audio(c, audio_out, frame_bytes
> > /*packet.size*/, (short *)data_buf);
> >
> > pkt.stream_index= encoderData->audio_st->index;
> > pkt.data= audio_out;
> > pkt.flags |= AV_PKT_FLAG_KEY;
> >
> > pkt.pts = pkt.dts = 0;
> > /* write the compressed frame in the media file */
> > if (av_interleaved_write_frame(encoderData->ocAud, &pkt) !=
> 0)
> > {
> > fprintf(stderr, "Error while writing audio frame\n");
> > exit(1);
> > }
> > }
> > }
> > *********** - Encoding part: - ***************
> >
> > Other code is similar to the muxing.c example that comes with the
> builds. I
> > know the functions used above are kind of outdated, but that is the best
> > working source I could find from the internet.
> >
> > Can anyone kindly highlight how I could improve my code, or do I need to
> > tweak ffplay somehow for better results?
> >
> > Thanks for your time,
> >
> > Best regards
> >
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130402/8bf84774/attachment.html>
More information about the Libav-user
mailing list