wiki/cli.ffmpeg.html
2022-07-29 15:41:17 +00:00

41 lines
18 KiB
HTML

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Command line: FFmpeg</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
MathJax = {
tex: {
inlineMath: [ [&#x27;$&#x27;,&#x27;$&#x27;], [&#x27;\(&#x27;,&#x27;\)&#x27;] ],
displayMath: [ [&#x27;$$&#x27;,&#x27;$$&#x27;], [&#x27;[&#x27;,&#x27;]&#x27;] ]
},
options = {
processHtmlClass = &quot;math&quot;
}
}
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Command line: FFmpeg</h1><section class="post-metadata"><span>Date: <!-- -->2021-05-09 16:40:50 +08:00</span><span>Date modified: <!-- -->2021-07-20 23:30:49 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/cli.ffmpeg#options" class="toc-link toc-link-h1">Options</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cli.ffmpeg#examples" class="toc-link toc-link-h1">Examples</a><ol class="toc-level toc-level-2"><li class="toc-item toc-item-h2"><a href="/wiki/cli.ffmpeg#convert-an-mp3-to-ogg" class="toc-link toc-link-h2">Convert an MP3 to OGG</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.ffmpeg#transrate-an-audio-file" class="toc-link toc-link-h2">Transrate an audio file</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.ffmpeg#list-all-available-options" class="toc-link toc-link-h2">List all available options</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.ffmpeg#capture-video-device" class="toc-link toc-link-h2">Capture video device</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.ffmpeg#extract-a-segment-from-a-file" class="toc-link toc-link-h2">Extract a segment from a file</a></li></ol></li></ol></nav><p>The swiss army knife for interacting with multimedia files (except images because ImageMagick).
</p><h1 id="options">Options</h1><p>The FFmpeg command line interface is mostly picky because of order.
Whatever options are given will be processed with those options in order.
</p><ul><li><p><code class="inline-verbatim">-hide_banner</code> - hide the annoying banner
</p></li><li><p><code class="inline-verbatim">-loglevel [level] | -v [level]</code> - set the verbosity level
</p></li><li><p><code class="inline-verbatim">-codecs</code> - list all codecs
</p></li><li><p><code class="inline-verbatim">-devices</code> - list all devices
</p></li><li><p><code class="inline-verbatim">-i [file]</code> - the input file
</p></li><li><p><code class="inline-verbatim">c [codec]</code> - set the codec
</p></li><li><p><code class="inline-verbatim">-b [rate]</code> - set the bitrate
</p></li><li><p><code class="inline-verbatim">-o [file]</code> - set the output
</p></li></ul><p>Certain options have the option of specifying whether you&#x27;re interacting with the audio or video track.
For example, <code class="inline-verbatim">-codec:audio</code> (<code class="inline-verbatim">-c:a</code>) to set the audio codec.
</p><h1 id="examples">Examples</h1><p>FFmpeg is comprehensive and so needs some specific examples to fill my monkey brain.
</p><h2 id="convert-an-mp3-to-ogg">Convert an MP3 to OGG</h2><pre class="src-block"><code class="language-shell">ffmpeg -i $INPUT.mp3 -o $OUTPUT.ogg
</code></pre><p>By default, FFmpeg will guess if certain things are missing.
In this case, it guessed the input file is an MP3 and wants to convert OGG.
Sometimes, it will also use default options for converting between two formats such as the default bitrate and codec.
</p><h2 id="transrate-an-audio-file">Transrate an audio file</h2><pre class="src-block"><code class="language-shell">ffmpeg -i $INPUT -c $CODE -b:a $BITRATE $OUTPUT
</code></pre><h2 id="list-all-available-options">List all available options</h2><p>FFmpeg has compile options, heaps of them.
You may want to know what codecs are available.
</p><pre class="src-block"><code class="language-shell">ffmpeg -codecs
</code></pre><p>It tends to be a large list so prepare to send it through a pager.
</p><p>You should also know FFmpeg can print out devices.
</p><pre class="src-block"><code class="language-shell">ffmpeg -devices
</code></pre><h2 id="capture-video-device">Capture video device</h2><pre class="src-block"><code class="language-shell"># Assuming /dev/video0 is your webcam.
ffmpeg -f video4linux2 -i /dev/video0 cringe-at-yourself.mpg
</code></pre><h2 id="extract-a-segment-from-a-file">Extract a segment from a file</h2><p>The timestamps are essentially seeking to a file.
For more information, see <a href="https://trac.ffmpeg.org/wiki/Seeking">FFmpeg documentation</a>.
</p><pre class="src-block"><code class="language-shell">ffmpeg -nostdin -i $INPUT -ss 00:05:22 -to 00:22:43 $OUTPUT
</code></pre></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2021-05-09 16:40:50 +08:00\"","date_modified":"\"2021-07-20 23:30:49 +08:00\"","language":"en","source":""},"title":"Command line: FFmpeg","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"options"},"children":[{"type":"text","value":"Options"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.ffmpeg#options"},"children":[{"type":"text","value":"Options"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.ffmpeg#examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"convert-an-mp3-to-ogg"},"children":[{"type":"text","value":"Convert an MP3 to OGG"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.ffmpeg#convert-an-mp3-to-ogg"},"children":[{"type":"text","value":"Convert an MP3 to OGG"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"transrate-an-audio-file"},"children":[{"type":"text","value":"Transrate an audio file"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.ffmpeg#transrate-an-audio-file"},"children":[{"type":"text","value":"Transrate an audio file"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"list-all-available-options"},"children":[{"type":"text","value":"List all available options"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.ffmpeg#list-all-available-options"},"children":[{"type":"text","value":"List all available options"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"capture-video-device"},"children":[{"type":"text","value":"Capture video device"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.ffmpeg#capture-video-device"},"children":[{"type":"text","value":"Capture video device"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"extract-a-segment-from-a-file"},"children":[{"type":"text","value":"Extract a segment from a file"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.ffmpeg#extract-a-segment-from-a-file"},"children":[{"type":"text","value":"Extract a segment from a file"}]}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The swiss army knife for interacting with multimedia files (except images because ImageMagick).\n"}]},{"type":"element","tagName":"h1","properties":{"id":"options"},"children":[{"type":"text","value":"Options"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The FFmpeg command line interface is mostly picky because of order.\nWhatever options are given will be processed with those options in order.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-hide_banner"}]},{"type":"text","value":" - hide the annoying banner\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-loglevel [level] | -v [level]"}]},{"type":"text","value":" - set the verbosity level\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-codecs"}]},{"type":"text","value":" - list all codecs\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-devices"}]},{"type":"text","value":" - list all devices\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-i [file]"}]},{"type":"text","value":" - the input file\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"c [codec]"}]},{"type":"text","value":" - set the codec\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-b [rate]"}]},{"type":"text","value":" - set the bitrate\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-o [file]"}]},{"type":"text","value":" - set the output\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Certain options have the option of specifying whether you're interacting with the audio or video track.\nFor example, "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-codec:audio"}]},{"type":"text","value":" ("},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-c:a"}]},{"type":"text","value":") to set the audio codec.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"FFmpeg is comprehensive and so needs some specific examples to fill my monkey brain.\n"}]},{"type":"element","tagName":"h2","properties":{"id":"convert-an-mp3-to-ogg"},"children":[{"type":"text","value":"Convert an MP3 to OGG"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"ffmpeg -i $INPUT.mp3 -o $OUTPUT.ogg\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"By default, FFmpeg will guess if certain things are missing.\nIn this case, it guessed the input file is an MP3 and wants to convert OGG.\nSometimes, it will also use default options for converting between two formats such as the default bitrate and codec.\n"}]},{"type":"element","tagName":"h2","properties":{"id":"transrate-an-audio-file"},"children":[{"type":"text","value":"Transrate an audio file"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"ffmpeg -i $INPUT -c $CODE -b:a $BITRATE $OUTPUT\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"list-all-available-options"},"children":[{"type":"text","value":"List all available options"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"FFmpeg has compile options, heaps of them.\nYou may want to know what codecs are available.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"ffmpeg -codecs\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"It tends to be a large list so prepare to send it through a pager.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You should also know FFmpeg can print out devices.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"ffmpeg -devices\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"capture-video-device"},"children":[{"type":"text","value":"Capture video device"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"# Assuming /dev/video0 is your webcam.\nffmpeg -f video4linux2 -i /dev/video0 cringe-at-yourself.mpg\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"extract-a-segment-from-a-file"},"children":[{"type":"text","value":"Extract a segment from a file"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The timestamps are essentially seeking to a file.\nFor more information, see "},{"type":"element","tagName":"a","properties":{"href":"https://trac.ffmpeg.org/wiki/Seeking"},"children":[{"type":"text","value":"FFmpeg documentation"}]},{"type":"text","value":".\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"ffmpeg -nostdin -i $INPUT -ss 00:05:22 -to 00:22:43 $OUTPUT\n"}]}]}]},"backlinks":[]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["cli.ffmpeg"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html>