237 lines
9.7 KiB
HTML
237 lines
9.7 KiB
HTML
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Media Encoding — 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="prev" title="Shaka Packager Library (Continued)" href="../library_details.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="../library_details.html" title="Shaka Packager Library (Continued)"
|
|
accesskey="P">previous</a> |</li>
|
|
<li class="nav-item nav-item-0"><a href="../index.html">Shaka Packager documentation</a> »</li>
|
|
<li class="nav-item nav-item-this"><a href="">Media Encoding</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body" role="main">
|
|
|
|
<div class="section" id="media-encoding">
|
|
<h1>Media Encoding<a class="headerlink" href="#media-encoding" title="Permalink to this headline">¶</a></h1>
|
|
<p>Shaka Packager does not do transcoding internally. The contents need to be
|
|
pre-encoded before passing to Shaka Packager.</p>
|
|
<div class="section" id="general-guidelines-of-how-contents-should-be-encoded">
|
|
<h2>General guidelines of how contents should be encoded<a class="headerlink" href="#general-guidelines-of-how-contents-should-be-encoded" title="Permalink to this headline">¶</a></h2>
|
|
<ul class="simple">
|
|
<li><p>Encode multiple bitrates or resolutions of the same content. Shaka Packager
|
|
can then package the content into DASH / HLS formats, allowing different
|
|
bitrates of the content to be served for different network conditions,
|
|
achieving adaptive bitrate streaming.</p></li>
|
|
<li><p>Not a must, but the multibirate content is recommended to have aligned GOPs
|
|
across the different bitrate streams. This makes bitrate switching easier and
|
|
smoother.</p></li>
|
|
<li><p>We recommend setting GOP size to 5s or less. The streams are usually
|
|
switchable only at GOP boundaries. A smaller GOP size results in faster
|
|
switching when network condition changes.</p></li>
|
|
<li><p>In the same stream, the bitrate should be more or less the same in the
|
|
inter-GOP level.</p></li>
|
|
</ul>
|
|
</div>
|
|
<div class="section" id="sample-commands-to-generate-multi-bitrate-content">
|
|
<h2>Sample commands to generate multi-bitrate content<a class="headerlink" href="#sample-commands-to-generate-multi-bitrate-content" title="Permalink to this headline">¶</a></h2>
|
|
<p>Let us say we have a 1080p original content <cite>original.mp4</cite> containing an audio
|
|
track in <cite>AAC</cite> and a video track in <cite>H264</cite>. The frame rate is 24. We want to
|
|
encode the contents into four resolutions: 360p, 480p, 720p and 1080p with GOP
|
|
size 72, i.e. 3 seconds.</p>
|
|
<p>We use <a class="reference external" href="https://www.ffmpeg.org/">ffmpeg</a> here, which is a common tool used for
|
|
transcoding.</p>
|
|
<div class="section" id="h264-encoding">
|
|
<h3>H264 encoding<a class="headerlink" href="#h264-encoding" title="Permalink to this headline">¶</a></h3>
|
|
<ul>
|
|
<li><p>360p:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -i original.mp4 -c:a copy \
|
|
-vf "scale=-2:360" \
|
|
-c:v libx264 -profile:v baseline -level:v 3.0 \
|
|
-x264-params scenecut=0:open_gop=0:min-keyint=72:keyint=72 \
|
|
-minrate 600k -maxrate 600k -bufsize 600k -b:v 600k \
|
|
-y h264_baseline_360p_600.mp4
|
|
</pre></div>
|
|
</div>
|
|
</li>
|
|
<li><p>480p:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -i original.mp4 -c:a copy \
|
|
-vf "scale=-2:480" \
|
|
-c:v libx264 -profile:v main -level:v 3.1 \
|
|
-x264-params scenecut=0:open_gop=0:min-keyint=72:keyint=72 \
|
|
-minrate 1000k -maxrate 1000k -bufsize 1000k -b:v 1000k \
|
|
-y h264_main_480p_1000.mp4
|
|
</pre></div>
|
|
</div>
|
|
</li>
|
|
<li><p>720p:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -i original.mp4 -c:a copy \
|
|
-vf "scale=-2:720" \
|
|
-c:v libx264 -profile:v main -level:v 4.0 \
|
|
-x264-params scenecut=0:open_gop=0:min-keyint=72:keyint=72 \
|
|
-minrate 3000k -maxrate 3000k -bufsize 3000k -b:v 3000k \
|
|
-y h264_main_720p_3000.mp4
|
|
</pre></div>
|
|
</div>
|
|
</li>
|
|
<li><p>1080p:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -i original.mp4 -c:a copy \
|
|
-vf "scale=-2:1080" \
|
|
-c:v libx264 -profile:v high -level:v 4.2 \
|
|
-x264-params scenecut=0:open_gop=0:min-keyint=72:keyint=72 \
|
|
-minrate 6000k -maxrate 6000k -bufsize 6000k -b:v 6000k \
|
|
-y h264_high_1080p_6000.mp4
|
|
</pre></div>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section" id="vp9-encoding">
|
|
<h3>VP9 encoding<a class="headerlink" href="#vp9-encoding" title="Permalink to this headline">¶</a></h3>
|
|
<p>The audio is encoded into <cite>opus</cite>.</p>
|
|
<ul>
|
|
<li><p>360p:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -i original.mp4 \
|
|
-strict -2 -c:a opus \
|
|
-vf "scale=-2:360" \
|
|
-c:v libvpx-vp9 -profile:v 0 \
|
|
-keyint_min 72 -g 72 \
|
|
-tile-columns 4 -frame-parallel 1 -speed 1 \
|
|
-auto-alt-ref 1 -lag-in-frames 25 \
|
|
-b:v 300k \
|
|
-y vp9_360p_300.webm
|
|
</pre></div>
|
|
</div>
|
|
</li>
|
|
<li><p>480p:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -i original.mp4 \
|
|
-strict -2 -c:a opus \
|
|
-vf "scale=-2:480" \
|
|
-c:v libvpx-vp9 -profile:v 0 \
|
|
-keyint_min 72 -g 72 \
|
|
-tile-columns 4 -frame-parallel 1 -speed 1 \
|
|
-auto-alt-ref 1 -lag-in-frames 25 \
|
|
-b:v 500k \
|
|
-y vp9_480p_500.webm
|
|
</pre></div>
|
|
</div>
|
|
</li>
|
|
<li><p>720p:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -i original.mp4 \
|
|
-strict -2 -c:a opus \
|
|
-vf "scale=-2:720" \
|
|
-c:v libvpx-vp9 -profile:v 0 \
|
|
-keyint_min 72 -g 72 \
|
|
-tile-columns 4 -frame-parallel 1 -speed 1 \
|
|
-auto-alt-ref 1 -lag-in-frames 25 \
|
|
-b:v 1500k \
|
|
-y vp9_720p_1500.webm
|
|
</pre></div>
|
|
</div>
|
|
</li>
|
|
<li><p>1080p:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ffmpeg -i original.mp4 \
|
|
-strict -2 -c:a opus \
|
|
-vf "scale=-2:1080" \
|
|
-c:v libvpx-vp9 -profile:v 0 \
|
|
-keyint_min 72 -g 72 \
|
|
-tile-columns 4 -frame-parallel 1 -speed 1 \
|
|
-auto-alt-ref 1 -lag-in-frames 25 \
|
|
-b:v 3000k \
|
|
-y vp9_1080p_3000.webm
|
|
</pre></div>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</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="#">Media Encoding</a><ul>
|
|
<li><a class="reference internal" href="#general-guidelines-of-how-contents-should-be-encoded">General guidelines of how contents should be encoded</a></li>
|
|
<li><a class="reference internal" href="#sample-commands-to-generate-multi-bitrate-content">Sample commands to generate multi-bitrate content</a><ul>
|
|
<li><a class="reference internal" href="#h264-encoding">H264 encoding</a></li>
|
|
<li><a class="reference internal" href="#vp9-encoding">VP9 encoding</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<h4>Previous topic</h4>
|
|
<p class="topless"><a href="../library_details.html"
|
|
title="previous chapter">Shaka Packager Library (Continued)</a></p>
|
|
<div role="note" aria-label="source link">
|
|
<h3>This Page</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="../_sources/tutorials/encoding.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="../library_details.html" title="Shaka Packager Library (Continued)"
|
|
>previous</a> |</li>
|
|
<li class="nav-item nav-item-0"><a href="../index.html">Shaka Packager documentation</a> »</li>
|
|
<li class="nav-item nav-item-this"><a href="">Media Encoding</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer" role="contentinfo">
|
|
© Copyright 2017, Google.
|
|
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.4.3.
|
|
</div>
|
|
</body>
|
|
</html> |