shaka-packager/html/tutorials/ffmpeg_piping.html

210 lines
9.7 KiB
HTML
Raw Normal View History

2018-02-10 23:37:42 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>FFmpeg piping &#8212; Shaka Packager documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/sphinxdoc_new.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../_static/graphviz.css" />
<link rel="stylesheet" type="text/css" href="../_static/table_styling.css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="HTTP upload" href="http_upload.html" />
<link rel="prev" title="Ad Insertion" href="ads.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="http_upload.html" title="HTTP upload"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="ads.html" title="Ad Insertion"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Shaka Packager documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="tutorials.html" accesskey="U">Tutorials</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">FFmpeg piping</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="ffmpeg-piping">
<h1>FFmpeg piping<a class="headerlink" href="#ffmpeg-piping" title="Permalink to this headline"></a></h1>
<p>We can use <em>FFmpeg</em> to redirect / pipe input not supported by <em>packager</em>
to <em>packager</em>, for example, input from webcam devices, or rtp input. The concept
depicted here can be applied to other <em>FFmpeg</em> supported device or protocols.</p>
<div class="section" id="piping-data-to-packager">
<h2>Piping data to packager<a class="headerlink" href="#piping-data-to-packager" title="Permalink to this headline"></a></h2>
<p>There are two options to pipe data to packager.</p>
<ul>
<li><p>UDP socket</p>
<blockquote>
<div><p><em>FFmpeg</em> supports writing to a UDP socket and <em>packager</em> supports reading
from UDP sockets (See <a class="reference internal" href="../options/udp_file_options.html"><span class="doc">UDP file options</span></a>):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ packager &#39;input=udp://127.0.0.1:40000,...&#39; ...
$ ffmpeg ... -f mpegts udp://127.0.0.1:40000
</pre></div>
</div>
<p>VP9 cannot be carried in mpegts. Another container, e.g. webm needs to be
used when outputs VP9. In this case, transcoding has to be started after
starting packager as the initialization segment is only transmitted in the
beginning of WebM output.</p>
</div></blockquote>
</li>
<li><p>pipe</p>
<blockquote>
<div><p>Similarily, pipe is also supported in both <em>FFmpeg</em> and <em>packager</em>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ mkfifo pipe1
$ packager &#39;input=pipe1,...&#39; ... --io_block_size 65536
$ ffmpeg ... -f mpegts pipe: &gt; pipe1
</pre></div>
</div>
</div></blockquote>
</li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Option -io_block_size 65536 tells packager to use an io_block_size of 65K
for threaded io file. This is necessary when using pipe as reading from pipe
blocks until the specified number of bytes, which is specified in
io_block_size for threaded io file, thus the value of io_block_size cannot
be too large.</p>
</div>
</div>
<div class="section" id="encoding-capture-command">
<h2>Encoding / capture command<a class="headerlink" href="#encoding-capture-command" title="Permalink to this headline"></a></h2>
<div class="section" id="camera-capture">
<h3>Camera capture<a class="headerlink" href="#camera-capture" title="Permalink to this headline"></a></h3>
<p>Refer to <a class="reference external" href="https://trac.ffmpeg.org/wiki/Capture/Webcam">FFmpeg Capture/Webcam</a>
on how to use <em>FFmpeg</em> to capture webmcam inputs.</p>
<p>The example assumes Mac OS X 10.7 (Lion) or later. It captures from the default
audio / video devices on the machine:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -f avfoundation -i &quot;default&quot; -f mpegts udp://127.0.0.1:40000
</pre></div>
</div>
<p>The command starts only after packager starts.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>After encoding starts, monitor encoding speed carefully. It should always be
1x and above. If not, adjust the encoding parameters to recude it.</p>
</div>
</div>
<div class="section" id="rtp-input">
<h3>RTP input<a class="headerlink" href="#rtp-input" title="Permalink to this headline"></a></h3>
<p>Assume there is an RTP input described by <cite>saved_sdp_file</cite>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -protocol_whitelist &quot;file,rtp,udp&quot; -i saved_sdp_file -vcodec h264 \
-tune zerolatency -f mpegts udp://127.0.0.1:40000
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>For testing, you can generate an RTP input from a static media file:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -re -stream_loop 100 -i &lt;static.mp4&gt; -vcodec copy -acodec \
2018-02-10 23:37:42 +00:00
copy -f rtp rtp://239.255.0.1:1234 -sdp_file saved_sdp_file
</pre></div>
</div>
</div>
<p>The command starts only after packager starts.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>After encoding starts, monitor encoding speed carefully. It should always be
2018-02-10 23:37:42 +00:00
1x or above. If not, adjust the encoding parameters to increase it.</p>
</div>
</div>
</div>
<div class="section" id="example-packaging-command-in-dash">
<h2>Example packaging command in DASH<a class="headerlink" href="#example-packaging-command-in-dash" title="Permalink to this headline"></a></h2>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ packager \
&#39;in=udp://127.0.0.1:40000,stream=audio,init_segment=live_cam_audio.mp4,segment_template=live_cam_audio_$Number$.m4s&#39; \
&#39;in=udp://127.0.0.1:40000,stream=video,init_segment=live_cam_video.mp4,segment_template=live_cam_video_$Number$.m4s&#39; \
--mpd_output live_cam.mpd
</pre></div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">FFmpeg piping</a><ul>
<li><a class="reference internal" href="#piping-data-to-packager">Piping data to packager</a></li>
<li><a class="reference internal" href="#encoding-capture-command">Encoding / capture command</a><ul>
<li><a class="reference internal" href="#camera-capture">Camera capture</a></li>
<li><a class="reference internal" href="#rtp-input">RTP input</a></li>
</ul>
</li>
<li><a class="reference internal" href="#example-packaging-command-in-dash">Example packaging command in DASH</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="ads.html"
title="previous chapter">Ad Insertion</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="http_upload.html"
title="next chapter">HTTP upload</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/tutorials/ffmpeg_piping.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="http_upload.html" title="HTTP upload"
>next</a> |</li>
<li class="right" >
<a href="ads.html" title="Ad Insertion"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Shaka Packager documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="tutorials.html" >Tutorials</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">FFmpeg piping</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2017, Google.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.4.3.
</div>
</body>
</html>