<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 04 Apr 2015, at 01:36, robotanarchy <<a href="mailto:robotanarchy@bingo-ev.de" class="">robotanarchy@bingo-ev.de</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Hello libav-users,<br class=""><br class="">I'm just getting started with using libav and it is hard to find any<br class="">sample code, except for what is in the doc/examples folder of the<br class="">source tree [1].<br class=""><br class="">More specifically, I'd like to create a RTP video streaming server in C.<br class="">The closest thing to an example code was this [2] on stackoverflow -<br class="">but it is said not to work well and also it doesn't compile with the<br class="">latest ffmpeg.<br class=""><br class="">I've also tried to fork ffserver, but it also won't compile outside of<br class="">the ffmpeg source tree. Its main file, ffserver.c [3], has this infront<br class="">of most of the header files:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">       </span>// FIXME those are internal headers, ffserver _really_<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>shouldn't use them<br class=""><br class="">...so this also doesn't seem to be a good starting point either. I'm<br class="">wondering if such an RTP server is even possible without these internal<br class="">headers.<br class=""><br class="">If it is, can someone please provide some readable example code, that<br class="">does nothing but serve a video over RTP?<br class=""><br class="">Kind regards,<br class="">robotanarchy<br class=""></div></blockquote><div><br class=""></div>We just did that recently and it worked quite well (we were streaming a live video source to an iPhone).</div><div><br class=""></div><div>For a very basic approach, you can simply look for examples on how to encode a video file with libx264.</div><div>All you need to do make RTP work is set the output URL as you would normally set a file.</div><div>Here’s a short snippet:</div><div><br class=""></div><div><div style="margin: 0px; font-family: Menlo; color: rgb(79, 129, 135);" class="">_pVideoOutputFmt<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">av_guess_format</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"rtp"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #d62a9c" class="">NULL</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #d62a9c" class="">NULL</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">);</span></div><p style="margin: 0px; font-family: Menlo; min-height: 14px;" class="">    </p><div style="margin: 0px; font-family: Menlo; color: rgb(61, 29, 129);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">_pVideoFormatCtx</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> = </span>avformat_alloc_context<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">();</span></div><div style="margin: 0px; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">avformat_alloc_output_context2</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(&</span>_pVideoFormatCtx<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span>_pVideoOutputFmt<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"rtp"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span>_url<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">c_str</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">());</span></div><p style="margin: 0px; font-family: Menlo; min-height: 14px;" class="">    <span style="color: rgb(79, 129, 135);" class="">    </span></p><div style="margin: 0px; font-family: Menlo; color: rgb(0, 132, 0);" class="">/* open the output file, if needed */ </div><div style="margin: 0px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="color: rgb(214, 42, 156);" class="">if</span> (!(<span style="color: rgb(79, 129, 135);" class="">_pVideoOutputFmt</span>-><span style="color: rgb(112, 61, 170);" class="">flags</span> & <span style="color: rgb(120, 73, 42);" class="">AVFMT_NOFILE</span>))</div><div style="margin: 0px; font-family: Menlo;" class="">    <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">avio_open</span>(&<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">_pVideoFormatCtx</span>-><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">pb</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">_url</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">c_str</span>(), <span style="font-variant-ligatures: no-common-ligatures; color: #78492a" class="">AVIO_FLAG_WRITE</span>);</div><div class=""><br class=""></div></div><div><br class=""></div><div>And don’t forget to do a <span style="color: rgb(61, 29, 129); font-family: Menlo;" class="">avformat_network_init</span><span style="font-family: Menlo;" class="">(); </span>or else RTP won’t work.</div><div><br class=""></div><div>Hope this helps getting you started!</div><div>Best regards,</div><div><br class=""></div><div>Flo</div></div></body></html>