<div dir="ltr"><div><div>Hi!<br><br></div>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.<br>
<br></div>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.<br>
<div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 2, 2013 at 2:33 AM, Roger Pack <span dir="ltr"><<a href="mailto:rogerdpack2@gmail.com" target="_blank">rogerdpack2@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">what if you just record locally (no UDP) does it die?<br>
<div><div class="h5"><br>
On 12/24/12, Taha Ansari <<a href="mailto:mtaha.ansari@gmail.com">mtaha.ansari@gmail.com</a>> wrote:<br>
> Hi!<br>
><br>
> I have a small test application that sends microphone audio over network.<br>
> But the audio playback is sometimes very choppy/lossy, and also I initially<br>
> need to 'seek' ffplay back to hear audio with minimum latency. I do this in<br>
> Windows, using dshow, zeranoe ffmpeg builds, MSVS; and here is custom code<br>
> of relevance (output file is in extension .mp2, and packets are sent on<br>
> udp. I tried AAC extension as well, but results are somewhat the same):<br>
><br>
> ***********  +  Decoding part:   +  *************<br>
> if(this->packet.stream_index == this->audioStream)<br>
>     {<br>
>         unsigned int samples_size= 0;<br>
>         AVCodecContext *c = outputCodecCtxAudio;<br>
>         int finalPTS = 0;<br>
>         samples = (short *) av_fast_realloc(samples, &samples_size,<br>
> FFMAX(packet.size, AVCODEC_MAX_AUDIO_FRAME_SIZE));<br>
>         finalPTS =  packet.pts;<br>
>         audiobufsize = AVCODEC_MAX_AUDIO_FRAME_SIZE*2;<br>
>         avcodec_decode_audio3(pCodecCtxAudio, samples, &audiobufsize,<br>
> &packet);<br>
><br>
><br>
>         if(pCodecCtxAudio->sample_rate != c->sample_rate ||<br>
> pCodecCtxAudio->channels != c->channels )<br>
>         {<br>
>             if ( rs == NULL)<br>
>             {<br>
>                 rs = av_audio_resample_init(c->channels,<br>
> pCodecCtxAudio->channels, c->sample_rate, pCodecCtxAudio->sample_rate,<br>
> AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16, 0,0,0,0);<br>
>             }<br>
>         }<br>
>         if(pCodecCtxAudio->sample_rate != c->sample_rate ||<br>
> pCodecCtxAudio->channels != c->channels)<br>
>         {<br>
>             int size_out = audio_resample(rs, (short *)buffer_resample,<br>
> samples, audiobufsize/ (pCodecCtxAudio->channels * 2) );<br>
>             av_fifo_generic_write(fifo, (uint8_t *)buffer_resample,<br>
> size_out * c->channels * 2, NULL );<br>
>         }<br>
>         else<br>
>         {<br>
>             av_fifo_generic_write(fifo, (uint8_t *)samples, audiobufsize,<br>
> NULL );<br>
>         }<br>
>     }<br>
> ***********  -  Decoding part:   -  *************<br>
><br>
> ***********  + Encoding part:   + ***************<br>
> if ( decoderData->audiobufsize )<br>
>     {<br>
>         AVPacket pkt;<br>
>         av_init_packet(&pkt);<br>
><br>
>         AVCodecContext* c = encoderData->audio_st->codec;<br>
><br>
>         int frame_bytes = c->frame_size * 2 * c->channels;<br>
><br>
>         while( av_fifo_size(decoderData->fifo) >= frame_bytes )<br>
>         {<br>
>             int ret = av_fifo_generic_read( decoderData->fifo, data_buf,<br>
> frame_bytes, NULL );<br>
>             /* encode the samples */<br>
>             pkt.size= avcodec_encode_audio(c, audio_out, frame_bytes<br>
> /*packet.size*/, (short *)data_buf);<br>
><br>
>             pkt.stream_index= encoderData->audio_st->index;<br>
>             pkt.data= audio_out;<br>
>             pkt.flags |= AV_PKT_FLAG_KEY;<br>
><br>
>             pkt.pts = pkt.dts = 0;<br>
>             /* write the compressed frame in the media file */<br>
>             if (av_interleaved_write_frame(encoderData->ocAud, &pkt) != 0)<br>
>             {<br>
>                 fprintf(stderr, "Error while writing audio frame\n");<br>
>                 exit(1);<br>
>             }<br>
>         }<br>
>     }<br>
> ***********  - Encoding part:   - ***************<br>
><br>
> Other code is similar to the muxing.c example that comes with the builds. I<br>
> know the functions used above are kind of outdated, but that is the best<br>
> working source I could find from the internet.<br>
><br>
> Can anyone kindly highlight how I could improve my code, or do I need to<br>
> tweak ffplay somehow for better results?<br>
><br>
> Thanks for your time,<br>
><br>
> Best regards<br>
><br>
</div></div>_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
</blockquote></div><br></div></div></div>