3

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]
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 [filenmae] -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

3

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]
8
  • 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 Mar 21 '16 at 13:32
  • Paste the full console output of the command you ran into the question.
    – Gyan
    Mar 21 '16 at 13:43
  • pastebin.com/FRey8JZE Mar 22 '16 at 11:43
  • As per that readout, the audio was copied successfully. What does ffprobe C0371.mov say?
    – Gyan
    Mar 22 '16 at 14:29
  • 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 pastebin.com/Wbkn3nat Mar 28 '16 at 14:24
2

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
1
  • Welcome! Thanks for an awesome, detailed first answer! Jul 7 at 1:16
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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.