<h2>Short answer specific to this problem:</h2>
<p>Use this option:</p>
<pre><code>-map_metadata 0:s:2
</code></pre>
<h2>Explanation:</h2>
<p>Timecode often comes in a format specific to the file format, so ffmpeg can't be expected to just 'copy' it without getting explicit instructions.</p>
<p>In Sony a7siii 4k 10bit footage mp4 file, there is a separate 'data' stream to which it is added as a metadata. It is usually stream indexed 2 (the third stream), but you can use this command to determine it for yourself:</p>
<pre class="lang-bash prettyprint-override"><code>ffmpeg -i inputfile.mp4
</code></pre>
<p>This will display info about all the input streams, including the metadata.</p>
<p>Example output (excerpts):</p>
<pre><code>ffmpeg version...
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'inputfile.mp4':
  Metadata:
...
  Stream #0:0(und): Video: h264...
...
  Stream #0:2(und): Data: none (rtmd / 0x646D7472), 2252 kb/s (default)
    Metadata:
      creation_time   : 2021-06-19T16:39:17.000000Z
      handler_name    : Timed Metadata Media Handler
      timecode        : 07:15:07:17
</code></pre>
<p>Now, note that timecode is attached as metadata to a separate 'data' stream, which needs to be present in the output for a simple <code>-map_metadata 0</code> to work. Since it cannot be copied, we need to map that metadata to the global metadata of the file itself.</p>
<p>Note down the stream number containing the timecode, in this example stream 2 of input 0, and map it to global metadata using <code>-map_metadata 0:s:2</code>.</p>
<pre class="lang-bash prettyprint-override"><code>ffmpeg -i inputfile.mp4 -map_metadata 0:s:2 -c copy outputfile.mov
</code></pre>
<p>This should map metadata of the stream indexed 2 (s:2) from the first input (0:) to the global (default) metadata of the output file, and copy audio-video streams as they are.</p>
<p>Note that the numbering and the meaning of 's' is different than how it is in other more common options. Check more info in the <a href="https://ffmpeg.org/ffmpeg-all.html#toc-Advanced-options" rel="noreferrer">advanced options part of the ffmpeg documentation</a>.</p>
<p>ffmpeg then reads whatever it understands from that stream's metadata (which includes timecode), converts it to the destination file format's ideal metadata format, and includes it in the output.</p>
<p><strong>The resulting file will have a timecode recognizable in editing software like DaVinci Resolve and Premiere Pro.</strong></p>
<p>I tried other options like <code>-write_tmcd</code> and several forms of  <code>-map 0</code> with and without <code>-copy_unknown</code> but they didn't work, probably because ffmpeg currently needs to understand what it is copying.</p>
<p>Note that this does not copy the whole data stream, just its metadata. For our current requirement this is okay.</p>
<p>Also, since I was converting to prores422hq, my exact command (that worked) was this:</p>
<pre><code>ffmpeg -i inputfile.mp4 -map_metadata 0:s:2 -c:v prores_ks -profile hq -c:a pcm_s16le outputfile.mov
</code></pre>

CC BY-SA 4.0
2021-07-07T01:16:37.093Z
Welcome! Thanks for an awesome, detailed first answer!
Michael Liebman
CC BY-SA 4.0
2021-07-06T19:35:46.803Z
2021-07-06T19:35:46.803Z
vaibhavbshete
<p>Just use copy for all streams i.e. </p>

<pre><code>ffmpeg -i [filename] -c copy -map 0 [outputDirectory]
</code></pre>

<hr>

<p><strong>Edit</strong>: Let's switch byte-order</p>

<pre><code>ffmpeg -i [filename] -c copy -c:a pcm_s16le -map 0 [outputDirectory]
</code></pre>

CC BY-SA 3.0
2016-03-21T13:32:30.790Z
Thanks for the suggestion. I tried it and it copied the timecode, but it didn't copy the audio. I tried it like this " -acodec copy -c copy -map 0" but still no audio. 
It also gave this message on both your version and the one I modified:
[NULL @ 0000000005795f00] Unknown hldr_type for rtmd / 0x646D7472, writing dummy
user3185563
CC BY-SA 3.0
2016-03-21T13:43:14.560Z
Paste the full console output of the command you ran into the question.
Gyan
CC BY-SA 3.0
2016-03-22T11:43:05.267Z
http://pastebin.com/FRey8JZE
user3185563
CC BY-SA 3.0
2016-03-22T14:29:45.790Z
As per that readout, the audio was copied successfully. What does `ffprobe C0371.mov` say?
Gyan
CC BY-SA 3.0
2016-03-28T14:24:09.270Z
You're right, it did copy the audio. The problem I have is that the program I'm using, Davinci Resolve, will read the audio created  using the original command, "-vcodec copy -acodec copy",  but won't read the audio created using the modified version. That's a problem, because the sole reason I'm doing the conversion is so that Davinci Resolve will read the audio. This is the ffprobe output for both files http://pastebin.com/Wbkn3nat
user3185563
CC BY-SA 3.0
2016-03-28T14:44:49.433Z
Try new command in answer.
Gyan
CC BY-SA 3.0
2016-04-08T11:21:31.800Z
The first time I tried the new version, it told me that it couldn't find a compatible output format, so I changed the output file to have .mov extension. It created the output file but it doesn't have audio or timecode. This is the output: http://pastebin.com/vfcYd1uT  This is the test file I'm using: https://goo.gl/xilYd9
user3185563
CC BY-SA 3.0
2016-04-10T11:01:36.177Z
This looks to be a DaVinci issue rather than ffmpeg. I used your source file with my commands and the result plays with audio in Sony vegas and Premiere Pro CC but not in Resolve 11 (the version I have). I don't use Resolve for editing, so if you can find a guide to what Resolve needs in a MP4/MOV, I can tweak my command.
Gyan
CC BY-SA 3.0
2016-03-19T06:03:15.960Z
2016-03-28T14:44:10.743Z
2016-03-28T14:44:10.743Z
Gyan
<p>In case someone else comes looking for this, timecode in mp4 and mov files is often a &quot;data&quot; track, and ffmpeg usually drops data tracks. To keep all tracks, I usually use these switches to map tracks from the source to tracks in the destination</p>
<pre><code>-map 0:v (video switches)
-map 0:a (audio switches)
-map 0:d (this keeps the data track)
</code></pre>
<p>Which also has the advantage of keeping all the source audio tracks, rather than the default of only the first one. So your command might look like</p>
<pre><code>ffmpeg -i [filename] -map 0:v -codec:v copy -map 0:a -codec:a copy -map 0:d [outputDirectory]
</code></pre>
<p>EDIT: In modern ffmpeg you can also add a question mark (like -0:a?) which means ffmpeg will keep going if it doesn't find a track like you asked it to copy</p>

CC BY-SA 4.0
2017-11-15T05:54:58.713Z
2022-01-05T16:37:29.040Z
2022-01-05T16:37:29.040Z
electron.rotoscope
<p>Timecode and lot of other informations does not belong to video or audio streams, they are metadata attributes.</p>

<p>FFmpeg has lot of command to manipulate metadata attributes, for the specific question you can give a look to my previous question and relative answer: <a href="https://video.stackexchange.com/questions/16965/ffmpeg-cut-a-media-preserving-all-streams-but-also-all-metadata-timecodes-and-e">ffmpeg Cut a media preserving all streams but also all metadata, timecodes and everything else</a></p>

<p>Please consider that metadata tends to change from format to format, so probably you have to find the right metadata field on the original Sony .mp4, parse it properly and write it changed or renamed into the new .mov file, following the QuickTime .mov specifications for timecode definition.</p>

CC BY-SA 3.0
2016-03-19T01:31:50.930Z
2016-03-19T01:31:50.930Z
2017-04-13T12:46:08.110Z
user3450548
<p>I have <code>.mp4</code> files created by a Sony A7s camera. They're using the XAVC S codec. I'm converting them to <code>.mov</code> using the command below. The original files have a timecode but that is not present in the output file. The output files have their timecodes set to zero. Is there any way to preserve the timecode?</p>

<pre><code>ffmpeg -i [filenmae] -vcodec copy -acodec copy [outputDirectory]
</code></pre>

<ffmpeg><timecode>
ffmpeg: preserve timecode when converting mp4 to mov
user3185563
# ffmpeg: preserve timecode when converting mp4 to mov

(Asked by: username_0 on 2016-03-18)

I have .mp4 files created by a Sony A7s camera. They're using the XAVC S codec. I'm converting them to .mov using the command below. The original files have a timecode but that is not present in the output file. The output files have their timecodes set to zero. Is there any way to preserve the timecode?
ffmpeg -i [filenmae] -vcodec copy -acodec copy [outputDirectory]

**Tags:** ffmpeg, timecode


---

## 4 answers

### Answer by username_1 on 2021-07-06. Score: 6

Short answer specific to this problem:
Use this option:
-map_metadata 0:s:2

Explanation:
Timecode often comes in a format specific to the file format, so ffmpeg can't be expected to just 'copy' it without getting explicit instructions.
In Sony a7siii 4k 10bit footage mp4 file, there is a separate 'data' stream to which it is added as a metadata. It is usually stream indexed 2 (the third stream), but you can use this command to determine it for yourself:
ffmpeg -i inputfile.mp4

This will display info about all the input streams, including the metadata.
Example output (excerpts):
ffmpeg version...
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'inputfile.mp4':
  Metadata:
...
  Stream #0:0(und): Video: h264...
...
  Stream #0:2(und): Data: none (rtmd / 0x646D7472), 2252 kb/s (default)
    Metadata:
      creation_time   : 2021-06-19T16:39:17.000000Z
      handler_name    : Timed Metadata Media Handler
      timecode        : 07:15:07:17

Now, note that timecode is attached as metadata to a separate 'data' stream, which needs to be present in the output for a simple -map_metadata 0 to work. Since it cannot be copied, we need to map that metadata to the global metadata of the file itself.
Note down the stream number containing the timecode, in this example stream 2 of input 0, and map it to global metadata using -map_metadata 0:s:2.
ffmpeg -i inputfile.mp4 -map_metadata 0:s:2 -c copy outputfile.mov

This should map metadata of the stream indexed 2 (s:2) from the first input (0:) to the global (default) metadata of the output file, and copy audio-video streams as they are.
Note that the numbering and the meaning of 's' is different than how it is in other more common options. Check more info in the advanced options part of the ffmpeg documentation.
ffmpeg then reads whatever it understands from that stream's metadata (which includes timecode), converts it to the destination file format's ideal metadata format, and includes it in the output.
The resulting file will have a timecode recognizable in editing software like DaVinci Resolve and Premiere Pro.
I tried other options like -write_tmcd and several forms of  -map 0 with and without -copy_unknown but they didn't work, probably because ffmpeg currently needs to understand what it is copying.
Note that this does not copy the whole data stream, just its metadata. For our current requirement this is okay.
Also, since I was converting to prores422hq, my exact command (that worked) was this:
ffmpeg -i inputfile.mp4 -map_metadata 0:s:2 -c:v prores_ks -profile hq -c:a pcm_s16le outputfile.mov

> **Comments:**
> **username_2**: Welcome! Thanks for an awesome, detailed first answer!  

---

### Answer by username_3 on 2016-03-19. Score: 4

Just use copy for all streams i.e. 
ffmpeg -i [filename] -c copy -map 0 [outputDirectory]


Edit: Let's switch byte-order
ffmpeg -i [filename] -c copy -c:a pcm_s16le -map 0 [outputDirectory]

> **Comments:**
> **username_0**: Thanks for the suggestion. I tried it and it copied the timecode, but it didn't copy the audio. I tried it like this " -acodec copy -c copy -map 0" but still no audio.  It also gave this message on both your version and the one I modified: [NULL @ 0000000005795f00] Unknown hldr_type for rtmd / 0x646D7472, writing dummy  
> **username_3**: Paste the full console output of the command you ran into the question.  
> **username_0**: http://pastebin.com/FRey8JZE  
> **username_3**: As per that readout, the audio was copied successfully. What does `ffprobe C0371.mov` say?  
> **username_0**: You're right, it did copy the audio. The problem I have is that the program I'm using, Davinci Resolve, will read the audio created  using the original command, "-vcodec copy -acodec copy",  but won't read the audio created using the modified version. That's a problem, because the sole reason I'm doing the conversion is so that Davinci Resolve will read the audio. This is the ffprobe output for both files http://pastebin.com/Wbkn3nat  
> **username_3**: Try new command in answer.  
> **username_0**: The first time I tried the new version, it told me that it couldn't find a compatible output format, so I changed the output file to have .mov extension. It created the output file but it doesn't have audio or timecode. This is the output: http://pastebin.com/vfcYd1uT  This is the test file I'm using: https://goo.gl/xilYd9  
> **username_3**: This looks to be a DaVinci issue rather than ffmpeg. I used your source file with my commands and the result plays with audio in Sony vegas and Premiere Pro CC but not in Resolve 11 (the version I have). I don't use Resolve for editing, so if you can find a guide to what Resolve needs in a MP4/MOV, I can tweak my command.  

---

### Answer by username_4 on 2017-11-15. Score: 4

In case someone else comes looking for this, timecode in mp4 and mov files is often a "data" track, and ffmpeg usually drops data tracks. To keep all tracks, I usually use these switches to map tracks from the source to tracks in the destination
-map 0:v (video switches)
-map 0:a (audio switches)
-map 0:d (this keeps the data track)

Which also has the advantage of keeping all the source audio tracks, rather than the default of only the first one. So your command might look like
ffmpeg -i [filename] -map 0:v -codec:v copy -map 0:a -codec:a copy -map 0:d [outputDirectory]

EDIT: In modern ffmpeg you can also add a question mark (like -0:a?) which means ffmpeg will keep going if it doesn't find a track like you asked it to copy


---

### Answer by username_5 on 2016-03-19. Score: 0

Timecode and lot of other informations does not belong to video or audio streams, they are metadata attributes.

FFmpeg has lot of command to manipulate metadata attributes, for the specific question you can give a look to my previous question and relative answer: [ffmpeg Cut a media preserving all streams but also all metadata, timecodes and everything else](https://video.stackexchange.com/questions/16965/ffmpeg-cut-a-media-preserving-all-streams-but-also-all-metadata-timecodes-and-e)

Please consider that metadata tends to change from format to format, so probably you have to find the right metadata field on the original Sony .mp4, parse it properly and write it changed or renamed into the new .mov file, following the QuickTime .mov specifications for timecode definition.


---

