<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Ffmpeg on Haseeb Majid</title>
    <link>https://haseebmajid.dev/tags/ffmpeg/</link>
    <description>Haseeb Majid&#39;s blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Fri, 20 Nov 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://haseebmajid.dev/tags/ffmpeg/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>TIL - How to Combine Audio and Video Without Re-encoding</title>
      <link>https://haseebmajid.dev/posts/2026-11-20-til-how-to-combine-audio-and-video-without-re-encoding/</link>
      <pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate>
      <author>Haseeb Majid</author>
      <guid>https://haseebmajid.dev/posts/2026-11-20-til-how-to-combine-audio-and-video-without-re-encoding/</guid>
      <description>&lt;p&gt;Recently I had some recordings where the audio and video were downloaded as separate files. I wanted to combine
them into one MP4 without having to re-encode everything.&lt;/p&gt;
&lt;p&gt;You can do this with ffmpeg using &lt;code&gt;-c copy&lt;/code&gt; &lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;https://haseebmajid.dev/posts/2026-11-20-til-how-to-combine-audio-and-video-without-re-encoding/#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;div class=&#34;lab-neovim&#34; data-code-lines=&#34;2&#34; data-code-filename=&#34;snippet.sh&#34; data-code-lang=&#34;bash&#34;&gt;
  &lt;div class=&#34;lab-code-tab&#34;&gt;
    &lt;span class=&#34;lab-code-filename&#34; title=&#34;snippet.sh&#34;&gt;snippet.sh&lt;/span&gt;
  &lt;/div&gt;
  &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ffmpeg -n -i video.mp4 -i audio.mp4 &lt;span class=&#34;se&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  -map 0:v:0 -map 1:a:0 -c copy combined.mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
  &lt;div class=&#34;lab-code-bar&#34;&gt;
    &lt;b class=&#34;lab-code-lang&#34;&gt;bash&lt;/b&gt;
    &lt;span class=&#34;lab-code-lines&#34;&gt;2 lines&lt;/span&gt;
    &lt;span class=&#34;lab-code-copy&#34;&gt;&lt;/span&gt;
  &lt;/div&gt;
  &lt;div class=&#34;lab-code-command&#34; role=&#34;status&#34;&gt;&#34;snippet.sh&#34; 2L&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;-map 0:v:0&lt;/code&gt; takes the first video stream from the first file, and &lt;code&gt;-map 1:a:0&lt;/code&gt; takes the first audio stream
from the second file. &lt;code&gt;-c copy&lt;/code&gt; copies both streams without re-encoding, so there is no quality loss from encoding
again. The &lt;code&gt;-n&lt;/code&gt; stops ffmpeg from overwriting an existing output file.&lt;/p&gt;</description><content:encoded><![CDATA[<p>Recently I had some recordings where the audio and video were downloaded as separate files. I wanted to combine
them into one MP4 without having to re-encode everything.</p>
<p>You can do this with ffmpeg using <code>-c copy</code> <sup id="fnref:1"><a href="https://haseebmajid.dev/posts/2026-11-20-til-how-to-combine-audio-and-video-without-re-encoding/#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>:</p>
<div class="lab-neovim" data-code-lines="2" data-code-filename="snippet.sh" data-code-lang="bash">
  <div class="lab-code-tab">
    <span class="lab-code-filename" title="snippet.sh">snippet.sh</span>
  </div>
  <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ffmpeg -n -i video.mp4 -i audio.mp4 <span class="se">\
</span></span></span><span class="line"><span class="cl">  -map 0:v:0 -map 1:a:0 -c copy combined.mp4</span></span></code></pre></div>
  <div class="lab-code-bar">
    <b class="lab-code-lang">bash</b>
    <span class="lab-code-lines">2 lines</span>
    <span class="lab-code-copy"></span>
  </div>
  <div class="lab-code-command" role="status">"snippet.sh" 2L</div>
</div>
<p>The <code>-map 0:v:0</code> takes the first video stream from the first file, and <code>-map 1:a:0</code> takes the first audio stream
from the second file. <code>-c copy</code> copies both streams without re-encoding, so there is no quality loss from encoding
again. The <code>-n</code> stops ffmpeg from overwriting an existing output file.</p>
<p>Note the codecs need to be supported by the output container. In my case the video was H.264 and the audio was AAC,
which both work in an MP4.</p>
<p>That&rsquo;s it!</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p><a href="https://ffmpeg.org/ffmpeg.html#Streamcopy">https://ffmpeg.org/ffmpeg.html#Streamcopy</a>&#160;<a href="https://haseebmajid.dev/posts/2026-11-20-til-how-to-combine-audio-and-video-without-re-encoding/#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
