title: Set RTSP/UDP buffer size in FFmpeg/LibAV
body: <p><strong><em>Note</strong>: I'm aware ffmpeg and libav are <a href="https://libav.org/about.html#history" rel="noreferrer">different libraries</a>. This is a problem common to both.</em></p>
  
  <p><strong><em>Disclaimer</strong>: Duplicate of <a href="https://stackoverflow.com/questions/14593531/too-small-ffmpeg-rtsp-decoding-buffer">SO question</a> marked as answered but actually didn't give a proper solution.</em></p>
  
  <hr>
  
  <p>Insufficient UDP buffer size causes broken streams for several high resolution video streams. In LibAV/FFMPEG it's possible to set the udp buffer size for udp urls (udp://...) by appending some <a href="https://www.ffmpeg.org/ffmpeg-protocols.html#udp" rel="noreferrer">options (buffer_size)</a> to it.</p>
  
  <p>However, for RTSP urls this is <a href="https://www.ffmpeg.org/ffmpeg-protocols.html#rtsp" rel="noreferrer">not supported</a>.</p>
  
  <p>These are the only solutions I've found:</p>
  
  <ul>
  <li>Rebuilding ffmpeg/libav changing the UDP_MAX_PKT_SIZE in the <a href="https://libav.org/doxygen/release/0.8/udp_8c_source.html" rel="noreferrer">udp.c</a> source file.</li>
  <li>Using a <a href="https://lists.libav.org/pipermail/libav-api/2015-January/000962.html" rel="noreferrer">nasty hack</a> to find and modify the required value, by casting some private structs.</li>
  <li>Using a different decoding library (proposed solution to aforementioned related SO <a href="https://stackoverflow.com/questions/14593531/too-small-ffmpeg-rtsp-decoding-buffer">question</a>).</li>
  </ul>
  
  <p>None of these is actually a solution. From what I found it should be possible to use the API's <a href="https://www.ffmpeg.org/doxygen/2.2/group__avoptions.html" rel="noreferrer"><code>AVOptions</code></a> to find and set this value. Or else, the <a href="https://libav.org/doxygen/master/group__lavu__dict.html" rel="noreferrer">AVDictionary</a>. </p>
  
  <p>It's very difficult to find how to set these throughout the documentation of either libav or ffmpeg.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>The following patches have been submited to Libav tackling this topic, thanks to Libav developer <em>@lu_zero</em> :</p>
  
  <ul>
  <li><a href="https://patches.libav.org/patch/57165/" rel="noreferrer">Add a buffer_size option</a></li>
  <li><a href="https://patches.libav.org/patch/57163/" rel="noreferrer">Map the urloptions to AVOptions</a></li>
  </ul>
  
  <p>Which should offer a hint on how to implement those, still these are not yet available through the official stable API. </p>