Answers.Body: <p>Although <a href="https://video.stackexchange.com/users/34287/farahats9">Farahats9</a> has said that their command worked, i have tried it out, and i believe that it is not doing what they think it should be doing. Namely it reencodes the data, when that was not what was needed. In addition to this, perhaps there was an error in copying the command, but they are mapping two video tracks with no audio tracks in sight.</p>
  <pre><code>ffmpeg -i 01.mkv -i 02.mkv -map_metadata 0 -map 1:v -map 0:a -c copy output.mkv
  </code></pre>
  <p>What this command does is it reads 01.mkv and 02.mkv, then it copies the video from 02.mkv (<code>-map 1:v</code>) and all audio tracks from 01.mkv (<code>-map 0:a</code>). If there are subtitle tracks that need to be copied, one would need to add <code>-map 0:s</code>, unfortunately ffmpeg will fail if there are no subtitle tags and you will try to copy them.</p>
  <p>Also note <code>-c copy</code>, this instruct <code>ffmpeg</code> to copy without reencoding, which is definitely what is needed in this case.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-11T06:29:41.893Z
Answers.LastActivityDate: 2021-12-11T06:29:41.893Z
Answers.UserDisplayName: v010dya
Answers.Body: <p>I ended up using this and it worked</p>
  <pre><code>ffmpeg -i &quot;original video file&quot; -i &quot;video file I want to insert&quot; -map_metadata 0 -map 0 -map -0:v:0 -map 1:v:0 output.mkv
  </code></pre>
  <p>this tells ffmpeg to remove the 1st video track from the 1st file and insert the 1st video track from the second file while retaining everything else as is.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-11T06:15:30.663Z
Answers.Text: Are you sure this worked? Are you sure this hasn't reencoded it for you? I do not see any directve to copy without reencoding.
Answers.UserDisplayName: v010dya
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-11T09:12:00.283Z
Answers.Text: It works well for me, I didn't notice if it is reencoding or not because both videos always have the same codec in my use case, I will check later and update the answer. And there is no need to add audio and subtitles manually, they are automatically included by `-map 0` this is important because I don't always know how many tracks will be in the file.
Answers.UserDisplayName: Farahats9
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-22T22:55:59.223Z
Answers.LastActivityDate: 2021-03-22T22:55:59.223Z
Answers.UserDisplayName: Farahats9
Body: <p>I want to use FFmpeg to replace a certain video track but keep everything else including chapters, audio, fonts etc…</p>
  <p>I know I should be using <code>-map</code> and <code>-map_metadata</code> but not sure how to do it.</p>
  
Tags: <ffmpeg>
Title: replace video track and keep everything else
UserDisplayName: Farahats9
ThreadText: # replace video track and keep everything else
  
  (Asked by: username_0 on 2021-03-22)
  
  I want to use FFmpeg to replace a certain video track but keep everything else including chapters, audio, fonts etc…
  
  I know I should be using `-map` and `-map_metadata` but not sure how to do it.
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-12-11. Score: 0
  
  Although [username_0](https://video.stackexchange.com/users/34287/username_0) has said that their command worked, i have tried it out, and i believe that it is not doing what they think it should be doing. Namely it reencodes the data, when that was not what was needed. In addition to this, perhaps there was an error in copying the command, but they are mapping two video tracks with no audio tracks in sight.
  
  ```
  ffmpeg -i 01.mkv -i 02.mkv -map_metadata 0 -map 1:v -map 0:a -c copy output.mkv
  
  ```
  
  What this command does is it reads 01.mkv and 02.mkv, then it copies the video from 02.mkv (`-map 1:v`) and all audio tracks from 01.mkv (`-map 0:a`). If there are subtitle tracks that need to be copied, one would need to add `-map 0:s`, unfortunately ffmpeg will fail if there are no subtitle tags and you will try to copy them.
  
  Also note `-c copy`, this instruct `ffmpeg` to copy without reencoding, which is definitely what is needed in this case.
  
  
  ---
  
  ### Answer by username_0 on 2021-03-22. Score: 0
  
  I ended up using this and it worked
  
  ```
  ffmpeg -i "original video file" -i "video file I want to insert" -map_metadata 0 -map 0 -map -0:v:0 -map 1:v:0 output.mkv
  
  ```
  
  this tells ffmpeg to remove the 1st video track from the 1st file and insert the 1st video track from the second file while retaining everything else as is.
  
  > **Comments:**
  > **username_1**: Are you sure this worked? Are you sure this hasn't reencoded it for you? I do not see any directve to copy without reencoding.  
  > **username_0**: It works well for me, I didn't notice if it is reencoding or not because both videos always have the same codec in my use case, I will check later and update the answer. And there is no need to add audio and subtitles manually, they are automatically included by `-map 0` this is important because I don't always know how many tracks will be in the file.  
  
  ---
  
  