<div dir="ltr">Hello all,<div><br></div><div>I'm looking for pointers on how to reduce the latency of h.264-based multimedia stream decoding on Windows platform. I receive a data stream from a scientific instrument via the UDP multicast, so there is very little (mainly GOP size) that I can change on the encoding side.</div><div><br></div><div>On the client side I am using a bare-bones application based on the code from "<a href="https://stackoverflow.com/questions/10715170/receiving-rtsp-stream-using-ffmpeg-library">https://stackoverflow.com/questions/10715170/receiving-rtsp-stream-using-ffmpeg-library</a>". The only change is a replacement of "avcodec_decode_video2" with "avcodec_send_packet/avcodec_receive_frame" pair. I'm also using FFmpeg DLLs compiled on the same machine. My FFmpeg configure options are at the end of this email [1].</div><div><br></div><div>So far I have these settings in my AVFormatContext:</div><div><div>format_ctx->max_delay = 0;</div><div>format_ctx->probesize = 64;</div></div><div><br></div><div>Are there any other options that I can tweak to reduce the latency? I'm fine with having a lower quality picture / higher CPU usage if that reduces the overall latency.</div><div><br></div><div>To test the actual glass-to-glass latency, I'm using an external measuring instrument. So far my best result is ~182 ms. Using a Windows PerformanceCounter method [2] I measure some of the critical parts of the code. For these tests, I'm running the code compiled in x64 Release mode. The values bellow are sliding window averages over 100 measurements:</div><div><br></div><div>1) <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">avcodec_send_packet/avcodec_receive_frame -> ~6-7 ms;</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">2) sws_scale (YUV -> RGB) -> ~0.8 ms;</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">3) Rendering (Creating a compatible bitmap, and then rendering in a Hwnd) -> ~8 ms.</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div>I'm running my benchmarks against a test application 

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">(FFmpeg based, no access to the source code) </span>provided with an instrument, which consistently delivers a glass-to-glass delay of appx. 138 ms. So even if data conversion 

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">from the YUV to RGB </span>and rendering in my app was perfect (instantaneous), my application is still appx. 36 ms. behind.</div><div><br></div><div>To answer beforehand why I'm not using the test application provided with the instrument - I need to do extra processing of the video feed before rendering it.</div><div><br></div><div>Thanks for any input!</div><div>~J</div><div><br></div><div>[1] - FFmpeg configure options and output</div><div><div>$ ./configure --toolchain=msvc --enable-shared --prefix=/c/ffmpeg --enable-asm --arch=i686</div><div>install prefix  Â  Â  Â  Â  Â  /c/ffmpeg</div><div>source path  Â  Â  Â  Â  Â  Â  Â .</div><div>C compiler  Â  Â  Â  Â  Â  Â  Â  cl</div><div>C library  Â  Â  Â  Â  Â  Â  Â  Â msvcrt</div><div>ARCH  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  x86 (generic)</div><div>big-endian  Â  Â  Â  Â  Â  Â  Â  no</div><div>runtime cpu detection  Â  Â yes</div><div>standalone assembly  Â  Â  Â yes</div><div>x86 assembler  Â  Â  Â  Â  Â  Â nasm</div><div>MMX enabled  Â  Â  Â  Â  Â  Â  Â yes</div><div>MMXEXT enabled  Â  Â  Â  Â  Â  yes</div><div>3DNow! enabled  Â  Â  Â  Â  Â  yes</div><div>3DNow! extended enabled  Â yes</div><div>SSE enabled  Â  Â  Â  Â  Â  Â  Â yes</div><div>SSSE3 enabled  Â  Â  Â  Â  Â  Â yes</div><div>AESNI enabled  Â  Â  Â  Â  Â  Â yes</div><div>AVX enabled  Â  Â  Â  Â  Â  Â  Â yes</div><div>AVX2 enabled  Â  Â  Â  Â  Â  Â  yes</div><div>AVX-512 enabled  Â  Â  Â  Â  Â yes</div><div>XOP enabled  Â  Â  Â  Â  Â  Â  Â yes</div><div>FMA3 enabled  Â  Â  Â  Â  Â  Â  yes</div><div>FMA4 enabled  Â  Â  Â  Â  Â  Â  yes</div><div>i686 features enabled  Â  Â yes</div><div>CMOV is fast  Â  Â  Â  Â  Â  Â  yes</div><div>EBX available  Â  Â  Â  Â  Â  Â no</div><div>EBP available  Â  Â  Â  Â  Â  Â no</div><div>debug symbols  Â  Â  Â  Â  Â  Â yes</div><div>strip symbols  Â  Â  Â  Â  Â  Â no</div><div>optimize for size  Â  Â  Â  Â no</div><div>optimizations  Â  Â  Â  Â  Â  Â yes</div><div>static  Â  Â  Â  Â  Â  Â  Â  Â  Â  no</div><div>shared  Â  Â  Â  Â  Â  Â  Â  Â  Â  yes</div><div>postprocessing support  Â  no</div><div>network support  Â  Â  Â  Â  Â yes</div><div>threading support  Â  Â  Â  Â w32threads</div><div>safe bitstream reader  Â  Â yes</div><div>texi2html enabled  Â  Â  Â  Â no</div><div>perl enabled  Â  Â  Â  Â  Â  Â  no</div><div>pod2man enabled  Â  Â  Â  Â  Â no</div><div>makeinfo enabled  Â  Â  Â  Â  no</div><div>makeinfo supports HTML  Â  no</div></div><div><br></div><div>[2] - <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx">https://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx</a></div><div><br></div></div>