<div dir="ltr">I'm using libavcodec libreries for my android app. <br>To recive/decode/save/play RTSP video stream from cameras.<br>Everything work well but avcodec_send_packet() working a little bit slow and cause video delay while try to play 1080p video stream.(no problem when playing smaller video streams) <br>is there any way to speed up avcodec_send_packet() execution? <br>Mayby multithread usage sample? Or something else. <br>Here is my usage code:<br><br># # # # # #<br><pre style="color:rgb(0,0,0);font-family:"Courier New""><span style="color:rgb(0,0,128);font-weight:bold">void </span>* <span style="color:rgb(0,128,128)">CameraConnection</span>::DecodeVideoStream() {<br>    <span style="color:rgb(55,31,128)">AVPacket </span>packet;<br>    <span style="color:rgb(0,0,128);font-weight:bold">while</span>(av_read_frame(<span style="color:rgb(102,14,122)">streamFormatContext</span>, &packet) >= <span style="color:rgb(0,0,255)">0 </span>|| <span style="color:rgb(102,14,122)">isConnected</span>) {<br>        <span style="color:rgb(128,128,128);font-style:italic">//check if frame from video stream<br></span><span style="color:rgb(128,128,128);font-style:italic">        </span><span style="color:rgb(0,0,128);font-weight:bold">if</span>(packet.<span style="color:rgb(102,14,122)">stream_index</span>==<span style="color:rgb(102,14,122)">videoStreamIdx</span>) { <span style="color:rgb(128,128,128);font-style:italic">// frame is video<br></span><span style="color:rgb(128,128,128);font-style:italic">            </span><span style="color:rgb(0,0,128);font-weight:bold">int </span>errorCode;<br>            errorCode = avcodec_send_packet(<span style="color:rgb(102,14,122)">streamVideoCodecContext</span>, &packet);<br>            <span style="color:rgb(0,0,128);font-weight:bold">if </span>(errorCode < <span style="color:rgb(0,0,255)">0</span>) {<br>                <span style="color:rgb(31,84,46);font-weight:bold">LOGE</span>(<span style="color:rgb(0,128,0);font-weight:bold">"Error sending a packet for decoding %s"</span>, <span style="color:rgb(31,84,46);font-weight:bold">stderr</span>);<br>                exit(<span style="color:rgb(0,0,255)">1</span>);<br>            }<br>            <span style="color:rgb(0,0,128);font-weight:bold">while </span>(errorCode >= <span style="color:rgb(0,0,255)">0</span>) {<br>                errorCode = avcodec_receive_frame(<span style="color:rgb(102,14,122)">streamVideoCodecContext</span>, <span style="color:rgb(102,14,122)">decodedFrame</span>);<br>                <span style="color:rgb(0,0,128);font-weight:bold">if </span>(errorCode == <span style="color:rgb(31,84,46);font-weight:bold">AVERROR</span>(<span style="color:rgb(31,84,46);font-weight:bold">EAGAIN</span>) || errorCode == <span style="color:rgb(31,84,46);font-weight:bold">AVERROR_EOF</span>) {<br>                    <span style="color:rgb(0,0,128);font-weight:bold">continue</span>;<br>                } <span style="color:rgb(0,0,128);font-weight:bold">else if </span>(errorCode < <span style="color:rgb(0,0,255)">0</span>) {<br>                    <span style="color:rgb(31,84,46);font-weight:bold">LOGE</span>(<span style="color:rgb(0,128,0);font-weight:bold">"Error during decoding %s"</span>, <span style="color:rgb(31,84,46);font-weight:bold">stderr</span>);<br>                    exit(<span style="color:rgb(0,0,255)">1</span>);<br>                }<br>                <span style="color:rgb(0,0,128);font-weight:bold">if</span>(<span style="color:rgb(102,14,122)">cameraRecord</span>) {<br>                    <span style="color:rgb(102,14,122)">cameraRecord</span>->AddPacket(packet);<br>                }<br>                <span style="color:rgb(0,0,128);font-weight:bold">if</span>(<span style="color:rgb(102,14,122)">cameraLiveVideo</span>) {<br>                    <span style="color:rgb(102,14,122)">cameraLiveVideo</span>->RenderFrame(&packet, <span style="color:rgb(102,14,122)">decodedFrame</span>);<br>                }<br>            }<br>        }<br><br>        <span style="color:rgb(128,128,128);font-style:italic">// Free the packet that was allocated by av_read_frame<br></span><span style="color:rgb(128,128,128);font-style:italic">        </span>av_packet_unref(&packet);<br>    }<br>    Disconnect();<br>    <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">0</span>;<br>}</pre># # # # # #  <div><br></div><div>Also will be happy if someone explane optimal value for:</div><div><span style="color:rgb(0,128,0);font-weight:bold;font-family:"Courier New"">reorder_queue_size and </span><span style="color:rgb(0,128,0);font-weight:bold;font-family:"Courier New"">buffer_size</span><span style="color:rgb(0,128,0);font-weight:bold;font-family:"Courier New""><br></span><br>P.S. Decoding process running in own thread<span style="color:rgb(0,0,0);font-family:"Courier New""><br></span><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="color:rgb(136,136,136)">Best regards,<br>Lobanov Ivan<br></div><div style="color:rgb(136,136,136)">GDG Perm Leader</div><div style="color:rgb(136,136,136)">Red Distribution</div><div style="color:rgb(136,136,136)">Тел.: <a value="+79129820101" style="color:rgb(17,85,204)">+7 961 759 89 71</a><br>Skype: ningen-des</div></div></div></div></div></div></div></div></div></div></div></div>