{
  "created": "2021-05-16T05:25:33Z",
  "hierarchy": [
    {
      "name": "ROOT",
      "type": "folder",
      "uri": "/ROOT"
    },
    {
      "name": "FFMpeg Cheatsheet",
      "type": "article",
      "uri": "FFMpeg_Cheatsheet"
    }
  ],
  "html": "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"/><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/><meta name=\"name\" content=\"Nikhil's Personal Wiki\"/><meta name=\"description\" content=\"FFMpeg Cheatsheet – Nikhil's Personal Wiki\"/><meta name=\"author\" content=\"Nikhil Anand\"/><meta name=\"theme-color\" content=\"#ffe9a00\"/><meta property=\"og:title\" content=\"FFMpeg Cheatsheet – Nikhil's Personal Wiki\"/><meta property=\"og:description\" content=\"FFMpeg Cheatsheet – Nikhil's Personal Wiki\"/><meta property=\"og:type\" content=\"website\"/><meta property=\"og:image\" content=\"/img/logo512.png\"/><meta property=\"og:site_name\" content=\"Nikhil's Personal Wiki\"/><link rel=\"og:image\" href=\"/img/logo512.png\"/><link rel=\"icon\" href=\"/img/favicon.png\"/><link rel=\"apple-touch-icon\" href=\"/img/logo192.png\"/><link rel=\"stylesheet\" href=\"/css/styles.css\"/><title>FFMpeg Cheatsheet – Nikhil's Personal Wiki</title><script defer data-domain=\"wiki.nikhil.io\" src=\"https://plausible.io/js/plausible.js\"></script></head><body><noscript>👉 A few things won't work if you have JavaScript disabled.</noscript><div class=\"container article\"><header><nav><ul><li><a href=\"/archive\" class title=\"Archive\"><span>Archive</span></a></li><li><a href=\"/Home\" class title=\"Home\"><span>Home</span></a></li><li><a href=\"/random\" class title=\"See a random article\"><span>Random</span></a></li><li><a href=\"/FFMpeg_Cheatsheet/raw.txt\" title=\"View Source\"><span>Raw</span></a></li><li><a href=\"/FFMpeg_Cheatsheet/revisions\" class title=\"View revisions\"><span>Revisions</span></a></li><li><a href=\"/FFMpeg_Cheatsheet/index.json\" title=\"View JSON Object\"><span>JSON</span></a></li></ul></nav></header><main><article><article-hierarchy><ul><li><a data-entity-type=\"folder\" href=\"/ROOT\" title=\"ROOT\">Root</a></li><li><a data-entity-type=\"article\" href=\"/FFMpeg_Cheatsheet\" title=\"FFMpeg Cheatsheet\">FFMpeg Cheatsheet</a></li></ul></article-hierarchy><header><h1>FFMpeg Cheatsheet</h1></header><article-content><p><a href=\"https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730\">Source</a></p>\n<hr />\n<h2 id=\"basic-conversion\">Basic conversion</h2>\n<pre><code>ffmpeg -i in.mp4 out.avi\n</code></pre>\n<h2 id=\"see-a-list-of-codecs\">See a List of Codecs</h2>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">ffmpeg -codecs\n</span></span></code></pre><h3 id=\"remux-an-mkv-file-into-mp4\">Remux an MKV file into MP4</h3>\n<pre><code>ffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n</code></pre>\n<h3 id=\"high-quality-encoding\">High-quality encoding</h3>\n<p>Use the <code>crf</code> (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to <code>-crf 18</code>. Use the <code>preset</code> parameter to control the speed of the compression process. Additional info: <a href=\"https://trac.ffmpeg.org/wiki/Encode/H.264\">https://trac.ffmpeg.org/wiki/Encode/H.264</a></p>\n<pre><code>ffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n</code></pre>\n<h2 id=\"trimming\">Trimming</h2>\n<p>Without re-encoding:</p>\n<pre><code>ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n</code></pre>\n<ul>\n<li><a href=\"http://ffmpeg.org/ffmpeg-all.html#Main-options\"><code>-ss</code></a> specifies the start time, e.g. <code>00:01:23.000</code> or <code>83</code> (in seconds)</li>\n<li><a href=\"http://ffmpeg.org/ffmpeg-all.html#Main-options\"><code>-t</code></a> specifies the duration of the clip (same format).</li>\n<li>Recent <code>ffmpeg</code> also has a flag to supply the end time with <code>-to</code>.</li>\n<li><a href=\"http://ffmpeg.org/ffmpeg-all.html#Main-options\"><code>-c</code></a> copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won&rsquo;t harm the quality and make the command run within seconds.</li>\n</ul>\n<p>With re-encoding:</p>\n<p>If you leave out the <code>-c copy</code> option, <code>ffmpeg</code> will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the <a href=\"https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide\">x264 Encoding Guide</a> and the <a href=\"http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide\">AAC Encoding Guide</a>, respectively.</p>\n<p>For example:</p>\n<pre><code>ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n</code></pre>\n<h2 id=\"mux-video-and-audio-from-another-video\">Mux video and audio from another video</h2>\n<p>To copy the video from in0.mp4 and audio from in1.mp4:</p>\n<pre><code>ffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n</code></pre>\n<ul>\n<li>With <a href=\"http://ffmpeg.org/ffmpeg.html#Stream-copy\">-c copy</a> the streams will be <code>stream copied</code>, not re-encoded, so there will be no quality loss. If you want to re-encode, see <a href=\"https://trac.ffmpeg.org/wiki/Encode/H.264\">FFmpeg Wiki: H.264 Encoding Guide</a>.</li>\n<li>The <code>-shortest</code> option will cause the output duration to match the duration of the shortest input stream.</li>\n<li>See the <a href=\"http://ffmpeg.org/ffmpeg.html#Advanced-options\"><code>-map</code> option documentation</a> for more info.</li>\n</ul>\n<h2 id=\"concatenation\">Concatenation</h2>\n<p>First, make a text file.</p>\n<pre><code>file 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n</code></pre>\n<p>Then, run <code>ffmpeg</code>:</p>\n<pre><code>ffmpeg -f concat -i list.txt -c copy out.mp4\n</code></pre>\n<p><em>Or</em>,</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">ffmpeg -f concat -safe <span class=\"m\">0</span> -i &lt;<span class=\"o\">(</span><span class=\"k\">for</span> f in ./*.mp3<span class=\"p\">;</span> <span class=\"k\">do</span> <span class=\"nb\">echo</span> <span class=\"s2\">&#34;file &#39;</span><span class=\"nv\">$PWD</span><span class=\"s2\">/</span><span class=\"nv\">$f</span><span class=\"s2\">&#39;&#34;</span><span class=\"p\">;</span> <span class=\"k\">done</span><span class=\"o\">)</span> -c copy output.mp3\n</span></span></code></pre><h2 id=\"delay-audiovideo\">Delay audio/video</h2>\n<p>Delay video by 3.84 seconds:</p>\n<pre><code>ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n</code></pre>\n<p>Delay audio by 3.84 seconds:</p>\n<pre><code>ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n</code></pre>\n<h2 id=\"burn-subtitles\">Burn subtitles</h2>\n<p>Use the <a href=\"http://ffmpeg.org/ffmpeg.html#ass\">libass</a> library (make sure your ffmpeg install has the library in the configuration <code>--enable-libass</code>).</p>\n<p>First convert the subtitles to .ass format:</p>\n<pre><code>ffmpeg -i sub.srt sub.ass\n</code></pre>\n<p>Then add them using a video filter:</p>\n<pre><code>ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n</code></pre>\n<h2 id=\"extract-the-frames-from-a-video\">Extract the frames from a video</h2>\n<p>To extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:</p>\n<pre><code>ffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n</code></pre>\n<p>To extract one frame per second only:</p>\n<pre><code>ffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n</code></pre>\n<h2 id=\"rotate-a-video\">Rotate a video</h2>\n<p>Rotate 90 clockwise:</p>\n<pre><code>ffmpeg -i in.mov -vf &quot;transpose=1&quot; out.mov\n</code></pre>\n<p>For the transpose parameter you can pass:</p>\n<pre><code>0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n</code></pre>\n<p>Use <code>-vf &quot;transpose=2,transpose=2&quot;</code> for 180 degrees.</p>\n<h2 id=\"download-transport-stream-video-streams\">Download &ldquo;Transport Stream&rdquo; video streams</h2>\n<ol>\n<li>Locate the playlist file, e.g. using Chrome &gt; F12 &gt; Network &gt; Filter: m3u8</li>\n<li>Download and concatenate the video fragments:</li>\n</ol>\n<pre><code>ffmpeg -i &quot;path_to_playlist.m3u8&quot; -c copy -bsf:a aac_adtstoasc out.mp4\n</code></pre>\n<p>If you get a &ldquo;Protocol &lsquo;https not on whitelist &lsquo;file,crypto&rsquo;!&rdquo; error, add the <code>protocol_whitelist</code> option:</p>\n<pre><code>ffmpeg -protocol_whitelist &quot;file,http,https,tcp,tls&quot; -i &quot;path_to_playlist.m3u8&quot; -c copy -bsf:a aac_adtstoasc out.mp4\n</code></pre>\n<h2 id=\"mute-some-of-the-audio\">Mute some of the audio</h2>\n<p>To replace the first 90 seconds of audio with silence:</p>\n<pre><code>ffmpeg -i in.mp4 -vcodec copy -af &quot;volume=enable='lte(t,90)':volume=0&quot; out.mp4\n</code></pre>\n<p>To replace all audio between 1'20&quot; and 1'30&quot; with silence:</p>\n<pre><code>ffmpeg -i in.mp4 -vcodec copy -af &quot;volume=enable='between(t,80,90)':volume=0&quot; out.mp4\n</code></pre>\n<h2 id=\"deinterlace\">Deinterlace</h2>\n<p>Deinterlacing using &ldquo;yet another deinterlacing filter&rdquo;.</p>\n<pre><code>ffmpeg -i in.mp4 -vf yadif out.mp4\n</code></pre>\n<h2 id=\"create-a-video-slideshow-from-images\">Create a video slideshow from images</h2>\n<p>Parameters: <code>-r</code> marks the image framerate (inverse time of each image); <code>-vf fps=25</code> marks the true framerate of the output.</p>\n<pre><code>ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n</code></pre>\n<h2 id=\"extract-images-from-a-video\">Extract images from a video</h2>\n<ul>\n<li>Extract all frames: <code>ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner</code></li>\n<li>Extract a frame each second: <code>ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner</code></li>\n<li>Extract only one frame: <code>ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg</code></li>\n</ul>\n<h2 id=\"metadata-change-the-title\">Metadata: Change the title</h2>\n<pre><code>ffmpeg -i in.mp4 -map_metadata -1 -metadata title=&quot;My Title&quot; -c:v copy -c:a copy out.mp4\n</code></pre>\n<h2 id=\"with-yt-dlp-make-a-clip-of-a-video\">With <code>yt-dlp</code>, make a clip of a video</h2>\n<p><code>-ss</code> is the start time, and <code>-s</code> is the duration. More info <a href=\"https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo\">here</a>.</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Using seconds</span>\n</span></span><span class=\"line\"><span class=\"cl\">yt-dlp <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  -f <span class=\"m\">18</span> <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  --external-downloader ffmpeg <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  --external-downloader-args <span class=\"s2\">&#34;ffmpeg_i:-ss 00:04:56.00 -t 5&#34;</span> <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  <span class=\"s2\">&#34;https://www.youtube.com/watch?v=rSc9xYPMAQY&#34;</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Using timestamp</span>\n</span></span><span class=\"line\"><span class=\"cl\">yt-dlp <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  -f <span class=\"m\">18</span> <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  --external-downloader ffmpeg <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  --external-downloader-args <span class=\"s2\">&#34;ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00&#34;</span> <span class=\"se\">\\\n</span></span></span><span class=\"line\"><span class=\"cl\"><span class=\"se\"></span>  <span class=\"s2\">&#34;https://www.youtube.com/watch?v=rSc9xYPMAQY&#34;</span>\n</span></span></code></pre><h2 id=\"creating-time-lapse-videos\">Creating Time-Lapse Videos</h2>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Reduce to a smaller size (1080p) since</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># &#34;MPEG-1 does not support resolutions above 4095x4095&#34;</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"k\">for</span> image in *.JPG<span class=\"p\">;</span> <span class=\"k\">do</span> ffmpeg -i <span class=\"nv\">$image</span> -vf <span class=\"nv\">scale</span><span class=\"o\">=</span>1920:-1 <span class=\"si\">${</span><span class=\"nv\">image</span><span class=\"p\">%.JPG</span><span class=\"si\">}</span>.PNG<span class=\"p\">;</span> <span class=\"k\">done</span>\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Create a movie!</span>\n</span></span><span class=\"line\"><span class=\"cl\">ffmpeg -f image2 -pattern_type glob -i <span class=\"s2\">&#34;*.PNG&#34;</span> output.mpg\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># A lossless movie!</span>\n</span></span><span class=\"line\"><span class=\"cl\">ffmpeg -pattern_type glob -i <span class=\"s2\">&#34;*.PNG&#34;</span> -c:v mjpeg -qscale:v <span class=\"m\">0</span> output.mov\n</span></span></code></pre><h2 id=\"convert-flac-to-m4a\">Convert FLAC to M4A</h2>\n<p>This is for macOS. You&rsquo;ll need FFMpeg with <a href=\"https://github.com/mstorsjo/fdk-aac\">this encoder</a>. The &lsquo;regular&rsquo; FFMPeg from HomeBrew will not work for <a href=\"https://stackoverflow.com/a/55108365\">reasons</a>.</p>\n<p>👉 Do <em>not</em> install <code>fdk-aac-encoder</code> to fix this issue!</p>\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"line\"><span class=\"cl\">brew tap homebrew-ffmpeg/ffmpeg\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># or &#39;upgrade&#39;. The &#34;--HEAD&#34; will fetch the latest release.</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Might save you trouble with ImageMagick versions.</span>\n</span></span><span class=\"line\"><span class=\"cl\">brew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac --HEAD\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Convert!</span>\n</span></span><span class=\"line\"><span class=\"cl\">find . -name <span class=\"s1\">&#39;*.flac&#39;</span> -exec sh -c <span class=\"s1\">&#39;ffmpeg -i &#34;$1&#34; -c:a libfdk_aac -b:a 320k &#34;${1%.flac}.m4a&#34;&#39;</span> _ <span class=\"o\">{}</span> <span class=\"se\">\\;</span>\n</span></span></code></pre><h3 id=\"problems\">Problems</h3>\n<h4 id=\"imagemagick-version\">ImageMagick Version</h4>\n<p>Just install the latest ImageMagick and FFmpeg with <code>--HEAD</code>.</p>\n<h4 id=\"could-not-find-tag-for-codec-h264-in-stream-0-codec\">Could not find tag for codec h264 in stream #0 codec</h4>\n<p>FFmpeg is <a href=\"https://stackoverflow.com/a/52370948\">trying to transcode any cover art</a>. To fix, just add a <code>-c:v copy</code> to the command above.</p>\n<hr />\n<h2 id=\"references\">References</h2>\n<ul>\n<li><a href=\"https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg\">Scaling with ffmpeg</a></li>\n<li><a href=\"http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence\">Video from images</a></li>\n<li><a href=\"http://stackoverflow.com/questions/4839303/convert-image-sequence-to-lossless-movie\">Making a lossless movie</a></li>\n</ul>\n</article-content></article></main><footer><p></p><ul><li>7,907 bytes</li><li>Created on Sunday, 16 May 2021 at 05:25 UTC</li><li>Modified on Monday, 21 September 2026 at 12:39 UTC</li><br/><li><a href=\"https://github.com/afreeorange/wiki.nikhil.io.articles/edit/master/FFMpeg Cheatsheet.md\" title=\"Edit this article\">Edit this article</a></li><li><a href=\"https://github.com/afreeorange/bock\" title=\"View the project that generates this wiki on Github\"><span>bock 6.3.0-alpha</span></a></li></ul></footer></div><script src=\"/js/table-sort.js\" defer></script><script type=\"text/javascript\">\n        document.body.addEventListener(\n          \"keypress\", (e) => e.key === \"f\"\n          ? window.location.assign(\"/archive\")\n          : null);\n      </script></body></html>",
  "id": "836f0dd7-82fa-5066-8f9d-6dd15ce8c581",
  "modified": "2026-09-21T12:39:52Z",
  "revisions": [
    {
      "authorEmail": "anand.nikhil@gmail.com",
      "authorName": "afreeorange",
      "date": "2026-09-21T12:39:52Z",
      "id": "4b6f5463b7b33178441bb8347a8ca3b464858a24",
      "shortId": "4b6f5463",
      "subject": "Add inline concat command\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n## See a List of Codecs\n\n```bash\nffmpeg -codecs\n```\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n## Concatenation\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\n\nThen, run `ffmpeg`:\n\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n_Or_,\n\n```bash\nffmpeg -f concat -safe 0 -i <(for f in ./*.mp3; do echo \"file '$PWD/$f'\"; done) -c copy output.mp3\n```\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n\n## Creating Time-Lapse Videos\n\n```bash\n# Reduce to a smaller size (1080p) since\n# \"MPEG-1 does not support resolutions above 4095x4095\"\nfor image in *.JPG; do ffmpeg -i $image -vf scale=1920:-1 ${image%.JPG}.PNG; done\n\n# Create a movie!\nffmpeg -f image2 -pattern_type glob -i \"*.PNG\" output.mpg\n\n# A lossless movie!\nffmpeg -pattern_type glob -i \"*.PNG\" -c:v mjpeg -qscale:v 0 output.mov\n```\n\n## Convert FLAC to M4A\n\nThis is for macOS. You'll need FFMpeg with [this encoder](https://github.com/mstorsjo/fdk-aac). The 'regular' FFMPeg from HomeBrew will not work for [reasons](https://stackoverflow.com/a/55108365).\n\n👉 Do _not_ install `fdk-aac-encoder` to fix this issue!\n\n```bash\nbrew tap homebrew-ffmpeg/ffmpeg\n\n# or 'upgrade'. The \"--HEAD\" will fetch the latest release.\n# Might save you trouble with ImageMagick versions.\nbrew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac --HEAD\n\n# Convert!\nfind . -name '*.flac' -exec sh -c 'ffmpeg -i \"$1\" -c:a libfdk_aac -b:a 320k \"${1%.flac}.m4a\"' _ {} \\;\n```\n\n### Problems\n\n#### ImageMagick Version\n\nJust install the latest ImageMagick and FFmpeg with `--HEAD`.\n\n#### Could not find tag for codec h264 in stream #0 codec\n\nFFmpeg is [trying to transcode any cover art](https://stackoverflow.com/a/52370948). To fix, just add a `-c:v copy` to the command above.\n\n---\n\n## References\n\n- [Scaling with ffmpeg](https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg)\n- [Video from images](http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence)\n- [Making a lossless movie](http://stackoverflow.com/questions/4839303/convert-image-sequence-to-lossless-movie)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2026-05-28T13:06:15Z",
      "id": "1b124d0ff7fe0093ab68a62ddeff2be857c6d6f5",
      "shortId": "1b124d0f",
      "subject": "Formatting fixes -- Claude\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n## See a List of Codecs\n\n```bash\nffmpeg -codecs\n```\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n\n## Creating Time-Lapse Videos\n\n```bash\n# Reduce to a smaller size (1080p) since\n# \"MPEG-1 does not support resolutions above 4095x4095\"\nfor image in *.JPG; do ffmpeg -i $image -vf scale=1920:-1 ${image%.JPG}.PNG; done\n\n# Create a movie!\nffmpeg -f image2 -pattern_type glob -i \"*.PNG\" output.mpg\n\n# A lossless movie!\nffmpeg -pattern_type glob -i \"*.PNG\" -c:v mjpeg -qscale:v 0 output.mov\n```\n\n## Convert FLAC to M4A\n\nThis is for macOS. You'll need FFMpeg with [this encoder](https://github.com/mstorsjo/fdk-aac). The 'regular' FFMPeg from HomeBrew will not work for [reasons](https://stackoverflow.com/a/55108365).\n\n👉 Do _not_ install `fdk-aac-encoder` to fix this issue!\n\n```bash\nbrew tap homebrew-ffmpeg/ffmpeg\n\n# or 'upgrade'. The \"--HEAD\" will fetch the latest release.\n# Might save you trouble with ImageMagick versions.\nbrew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac --HEAD\n\n# Convert!\nfind . -name '*.flac' -exec sh -c 'ffmpeg -i \"$1\" -c:a libfdk_aac -b:a 320k \"${1%.flac}.m4a\"' _ {} \\;\n```\n\n### Problems\n\n#### ImageMagick Version\n\nJust install the latest ImageMagick and FFmpeg with `--HEAD`.\n\n#### Could not find tag for codec h264 in stream #0 codec\n\nFFmpeg is [trying to transcode any cover art](https://stackoverflow.com/a/52370948). To fix, just add a `-c:v copy` to the command above.\n\n---\n\n## References\n\n- [Scaling with ffmpeg](https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg)\n- [Video from images](http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence)\n- [Making a lossless movie](http://stackoverflow.com/questions/4839303/convert-image-sequence-to-lossless-movie)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2026-01-13T18:47:28Z",
      "id": "2436477560f26e23d00a24add1cbfeafdca4af78",
      "shortId": "24364775",
      "subject": "No compression\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n## See a List of Codecs\n\n```bash\nffmpeg -codecs\n```\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n\n## Creating Time-Lapse Videos\n\n```bash\n# Reduce to a smaller size (1080p) since\n# \"MPEG-1 does not support resolutions above 4095x4095\"\nfor image in *.JPG; do ffmpeg -i $image -vf scale=1920:-1 ${image%.JPG}.PNG; done\n\n# Create a movie!\nffmpeg -f image2 -pattern_type glob -i \"*.PNG\" output.mpg\n\n# A lossless movie!\nffmpeg -pattern_type glob -i \"*.PNG\" -c:v mjpeg -qscale:v 0 output.mov\n```\n\n## Convert FLAC to M4A\n\nThis is for macOS. You'll need FFMpeg with [this encoder](https://github.com/mstorsjo/fdk-aac). The 'regular' FFMPeg from HomeBrew will not work for [reasons](https://stackoverflow.com/a/55108365).\n\n👉 Do _not_ install `fdk-aac-encoder` to fix this issue!\n\n```bash\nbrew tap homebrew-ffmpeg/ffmpeg\n\n# or 'upgrade'. The \"--HEAD\" will fetch the latest release.\n# Might save you trouble with ImageMagick versions.\nbrew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac --HEAD\n\n# Convert!\nfind . -name '*.flac' -exec sh -c 'ffmpeg -i \"$1\" -c:a libfdk_aac -b:a 320k \"${1%.flac}.m4a\"' _ {} \\;\n```\n\n### Problems\n\n#### ImageMagick Version\n\nJust install the latest ImageMagick and FFmpeg with `--HEAD`.\n\n#### Could not find tag for codec h264 in stream #0 codec\n\nFFmpeg is [trying to transcode any cover art](https://stackoverflow.com/a/52370948). To fix, just add a `-c:v copy` to the command above.\n\n---\n\n## References\n\n- [Scaling with ffmpeg](https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg)\n- [Video from images](http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence)\n- [Making a lossless movie](http://stackoverflow.com/questions/4839303/convert-image-sequence-to-lossless-movie)\n\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-12-27T23:30:31Z",
      "id": "a9c18b12944bbbdb95dceabe573daab90f04215e",
      "shortId": "a9c18b12",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n## See a List of Codecs\n\n```bash\nffmpeg -codecs\n```\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n\n## Creating Time-Lapse Videos\n\n```bash\n# Reduce to a smaller size (1080p) since\n# \"MPEG-1 does not support resolutions above 4095x4095\"\nfor image in *.JPG; do ffmpeg -i $image -vf scale=1920:-1 ${image%.JPG}.PNG; done\n\n# Create a movie!\nffmpeg -f image2 -pattern_type glob -i \"*.PNG\" output.mpg\n\n# A lossless movie!\nffmpeg -pattern_type glob -i \"*.PNG\" -c:v mjpeg -qscale:v 0 output.mov\n```\n\n## Convert FLAC to M4A\n\nThis is for macOS. You'll need FFMpeg with [this encoder](https://github.com/mstorsjo/fdk-aac). The 'regular' FFMPeg from HomeBrew will not work for [reasons](https://stackoverflow.com/a/55108365).\n\n👉 Do _not_ install `fdk-aac-encoder` to fix this issue!\n\n```bash\nbrew tap homebrew-ffmpeg/ffmpeg\n\n# or 'upgrade'. The \"--HEAD\" will fetch the latest release.\n# Might save you trouble with ImageMagick versions.\nbrew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac --HEAD\n\n# Convert!\nfind . -name '*.flac' -exec sh -c 'ffmpeg -i \"$1\" -c:a libfdk_aac -b:a 320k \"${1%.flac}.m4a\"' _ {} \\;\n```\n\n### Problems\n\n#### ImageMagick Version\n\nJust install the latest ImageMagick and FFmpeg with `--HEAD`.\n\n#### Could not find tag for codec h264 in stream #0 codec\n\nFFmpeg is [trying to transcode any cover art](https://stackoverflow.com/a/52370948). To fix, just add a `-c:v copy` to the command above.\n\n---\n\n## References\n\n- [Scaling with ffmpeg](https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg)\n- [Video from images](http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence)\n- [Making a lossless movie](http://stackoverflow.com/questions/4839303/convert-image-sequence-to-lossless-movie)\n\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-12-27T23:30:21Z",
      "id": "8ee3054ef045c088b5165e4ec56324112569b4e6",
      "shortId": "8ee3054e",
      "subject": "Initial commit\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n## See a List of Codecs\n\n```bash\nffmpeg -codecs\n```\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-11-23T22:22:31Z",
      "id": "f9f334be71f378b904e48087229b23ab20d87f17",
      "shortId": "f9f334be",
      "subject": "Merge contents of two other articles\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n## See a List of Codecs\n\n```bash\nffmpeg -codecs\n```\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n\n## Creating Time-Lapse Videos\n\n```bash\n# Reduce to a smaller size (1080p) since\n# \"MPEG-1 does not support resolutions above 4095x4095\"\nfor image in *.JPG; do ffmpeg -i $image -vf scale=1920:-1 ${image%.JPG}.PNG; done\n\n# Create a movie!\nffmpeg -f image2 -pattern_type glob -i \"*.PNG\" output.mpg\n\n# A lossless movie!\nffmpeg -pattern_type glob -i \"*.PNG\" -c:v mjpeg -qscale:v 0 output.mov\n```\n\n## Convert FLAC to M4A\n\nThis is for macOS. You'll need FFMpeg with [this encoder](https://github.com/mstorsjo/fdk-aac). The 'regular' FFMPeg from HomeBrew will not work for [reasons](https://stackoverflow.com/a/55108365).\n\n👉 Do _not_ install `fdk-aac-encoder` to fix this issue!\n\n```bash\nbrew tap homebrew-ffmpeg/ffmpeg\n\n# or 'upgrade'. The \"--HEAD\" will fetch the latest release.\n# Might save you trouble with ImageMagick versions.\nbrew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac --HEAD\n\n# Convert!\nfind . -name '*.flac' -exec sh -c 'ffmpeg -i \"$1\" -c:a libfdk_aac -b:a 320k \"${1%.flac}.m4a\"' _ {} \\;\n```\n\n### Problems\n\n#### ImageMagick Version\n\nJust install the latest ImageMagick and FFmpeg with `--HEAD`.\n\n#### Could not find tag for codec h264 in stream #0 codec\n\nFFmpeg is [trying to transcode any cover art](https://stackoverflow.com/a/52370948). To fix, just add a `-c:v copy` to the command above.\n\n---\n\n## References\n\n- [Scaling with ffmpeg](https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg)\n- [Video from images](http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence)\n- [Making a lossless movie](http://stackoverflow.com/questions/4839303/convert-image-sequence-to-lossless-movie)\n\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-11-14T15:45:19Z",
      "id": "d3819acc261c291e98008a3e2e352258f3d5f3f0",
      "shortId": "d3819acc",
      "subject": "Note on codecs list\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n## See a List of Codecs\n\n```bash\nffmpeg -codecs\n```\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2024-06-26T10:57:17Z",
      "id": "e88b1161e751b88d199972763d6c5f8a3751dca6",
      "shortId": "e88b1161",
      "subject": "Note on the Sock\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2022-12-25T00:00:50Z",
      "id": "eb9aa198f5dc1f093c79f2a003bec5eb061e016e",
      "shortId": "eb9aa198",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2022-12-19T18:40:53Z",
      "id": "726ae616259cb18d47d2400fa9c19c23c1f42331",
      "shortId": "726ae616",
      "subject": "Merge branch 'master' of github.com:afreeorange/wiki.nikhil.io.articles\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2022-12-19T18:40:44Z",
      "id": "d72fb1fe5c61b71cdc22743bca333fcf136ba492",
      "shortId": "d72fb1fe",
      "subject": "Initial commit\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 00:00:5.00\" \\\n  \"https://www.youtube.com/watch?v=-5ZIQ0bDlU8\"\n```\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2022-11-17T22:23:21Z",
      "id": "9f5c3dc428a9e1f48727e411da8584de59d6bfb6",
      "shortId": "9f5c3dc4",
      "subject": "More clicky YouTube sample ID\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2022-11-16T18:30:48Z",
      "id": "3d043cb82a456f99d8f596b637e31ed7a6b742fc",
      "shortId": "3d043cb8",
      "subject": "Update trim examples\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=-5ZIQ0bDlU8\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=-5ZIQ0bDlU8\"\n```\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2022-11-01T20:05:42Z",
      "id": "8300bac3e5452bfb4b107e7b3697a1be0bf1db25",
      "shortId": "8300bac3",
      "subject": "Update link, Monterey note\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 00:00:5.00\" \\\n  \"https://www.youtube.com/watch?v=-5ZIQ0bDlU8\"\n```\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2022-07-21T21:45:17Z",
      "id": "4d562e6a3fe4727b80f29cc1fba31dbc31138c2d",
      "shortId": "4d562e6a",
      "subject": "Add note on clipping YT video\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 00:00:5.00\" \\\n  \"https://www.youtube.com/watch?v=-5ZIQ0bDlU8\"\n```\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2022-06-13T23:23:48Z",
      "id": "ca643eb884a3127da90b1767928876fe4b3d0d0d",
      "shortId": "ca643eb8",
      "subject": "Update config.yml\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2021-05-16T05:25:33Z",
      "id": "c691790c4951279d716f7fbd2122249294128b2e",
      "shortId": "c691790c",
      "subject": "Create FFMpeg Cheatsheet.md\n",
      "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n"
    }
  ],
  "sizeInBytes": 7907,
  "source": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n## See a List of Codecs\n\n```bash\nffmpeg -codecs\n```\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n## Concatenation\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\n\nThen, run `ffmpeg`:\n\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n_Or_,\n\n```bash\nffmpeg -f concat -safe 0 -i <(for f in ./*.mp3; do echo \"file '$PWD/$f'\"; done) -c copy output.mp3\n```\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```bash\n# Using seconds\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 5\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n\n# Using timestamp\nyt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -to 00:05:23.00\" \\\n  \"https://www.youtube.com/watch?v=rSc9xYPMAQY\"\n```\n\n## Creating Time-Lapse Videos\n\n```bash\n# Reduce to a smaller size (1080p) since\n# \"MPEG-1 does not support resolutions above 4095x4095\"\nfor image in *.JPG; do ffmpeg -i $image -vf scale=1920:-1 ${image%.JPG}.PNG; done\n\n# Create a movie!\nffmpeg -f image2 -pattern_type glob -i \"*.PNG\" output.mpg\n\n# A lossless movie!\nffmpeg -pattern_type glob -i \"*.PNG\" -c:v mjpeg -qscale:v 0 output.mov\n```\n\n## Convert FLAC to M4A\n\nThis is for macOS. You'll need FFMpeg with [this encoder](https://github.com/mstorsjo/fdk-aac). The 'regular' FFMPeg from HomeBrew will not work for [reasons](https://stackoverflow.com/a/55108365).\n\n👉 Do _not_ install `fdk-aac-encoder` to fix this issue!\n\n```bash\nbrew tap homebrew-ffmpeg/ffmpeg\n\n# or 'upgrade'. The \"--HEAD\" will fetch the latest release.\n# Might save you trouble with ImageMagick versions.\nbrew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac --HEAD\n\n# Convert!\nfind . -name '*.flac' -exec sh -c 'ffmpeg -i \"$1\" -c:a libfdk_aac -b:a 320k \"${1%.flac}.m4a\"' _ {} \\;\n```\n\n### Problems\n\n#### ImageMagick Version\n\nJust install the latest ImageMagick and FFmpeg with `--HEAD`.\n\n#### Could not find tag for codec h264 in stream #0 codec\n\nFFmpeg is [trying to transcode any cover art](https://stackoverflow.com/a/52370948). To fix, just add a `-c:v copy` to the command above.\n\n---\n\n## References\n\n- [Scaling with ffmpeg](https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg)\n- [Video from images](http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence)\n- [Making a lossless movie](http://stackoverflow.com/questions/4839303/convert-image-sequence-to-lossless-movie)\n",
  "title": "FFMpeg Cheatsheet",
  "untracked": false,
  "uri": "/FFMpeg_Cheatsheet",
  "relativePath": "FFMpeg Cheatsheet.md"
}
