Hi!<br><br>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):<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, 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, &packet);<br>
<br>            <br>        if(pCodecCtxAudio->sample_rate != c->sample_rate || pCodecCtxAudio->channels != c->channels )<br>        {<br>            if ( rs == NULL)<br>            {<br>                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);<br>
            }<br>        }<br>        if(pCodecCtxAudio->sample_rate != c->sample_rate || pCodecCtxAudio->channels != c->channels) <br>        {<br>            int size_out = audio_resample(rs, (short *)buffer_resample, samples, audiobufsize/ (pCodecCtxAudio->channels * 2) );<br>
            av_fifo_generic_write(fifo, (uint8_t *)buffer_resample, size_out * c->channels * 2, NULL );<br>        }<br>        else<br>        {<br>            av_fifo_generic_write(fifo, (uint8_t *)samples, audiobufsize, 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, frame_bytes, NULL );<br>            /* encode the samples */   <br>            pkt.size= avcodec_encode_audio(c, audio_out, frame_bytes /*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 know the functions used above are kind of outdated, but that is the best 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 tweak ffplay somehow for better results?<br><br>Thanks for your time,<br><br>Best regards<br>