Keep timecode in ffmpeg?

13k views Asked by At

Im running a script that makes proress 422 proxies for editing in ffmpeg, but the timecode on the files seems to get lost or nulled out.

The parameters I am using:

ffmpeg -i file.mov -vcodec prores -profile:v 0 -an file.mov

Is there any way of preserving the timecode from the raw files?

I have also come over ffmbc wich seems be more suited for this, but it's for linux only. Any way this can be compiled for osx?

I am on osx 10.8.4

3

There are 3 answers

1
szatmary On

from man page: http://ffmpeg.org/ffmpeg.html

‘-copyts’
Do not process input timestamps, but keep their values without trying to sanitize them. In particular, do not remove the initial start time offset value.

Note that, depending on the ‘vsync’ option or on specific muxer processing (e.g. in case the format option ‘avoid_negative_ts’ is enabled) the output timestamps may mismatch with the input timestamps even when this option is selected.

‘-copytb mode’
Specify how to set the encoder timebase when stream copying. mode is an integer numeric value, and can assume one of the following values:

‘1’
Use the demuxer timebase.

The time base is copied to the output encoder from the corresponding input demuxer. This is sometimes required to avoid non monotonically increasing timestamps when copying video streams with variable frame rate.

‘0’
Use the decoder timebase.

The time base is copied to the output encoder from the corresponding input decoder.

‘-1’
Try to make the choice automatically, in order to generate a sane output.

Default value is -1.
0
mivk On

Recent versions of ffmpeg do preserve the timecode by default. I just tested it:

ffmpeg -i A152C001_131008UZ.MXF -an -vcodec prores -profile:v 0 testtc.mov
ffmpeg version 2.0.1-tessus Copyright (c) 2000-2013 the FFmpeg developers
  built on Aug 10 2013 21:25:56 with llvm-gcc 4.2.1 (LLVM build 2336.1.00)
  configuration: --prefix=/Users/tessus/data/ext/ffmpeg/sw --as=yasm --extra-version=tessus --disable-shared --enable-static --disable-ffplay --enable-gpl --enable-pthreads --enable-postproc --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libxavs --enable-version3 --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvpx --enable-libgsm --enable-libopus --enable-fontconfig --enable-libfreetype --enable-libass --enable-libbluray --enable-filters --enable-runtime-cpudetect
  libavutil      52. 38.100 / 52. 38.100
  libavcodec     55. 18.102 / 55. 18.102
  libavformat    55. 12.100 / 55. 12.100
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 79.101 /  3. 79.101
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
...
Input #0, mxf, from 'A152C001_131008UZ.MXF':
  Metadata:
...
    timecode        : 18:56:52:22
...
Output #0, mov, to 'testtc.mov':
  Metadata:
...
    timecode        : 18:56:52:22
...

And the resulting Quicktime does have the correct timecode (as shown by QT7).

I got my Mac OS X binary of ffmpeg from http://www.evermeet.cx/ffmpeg/

And ffmbc is available for Mac OS X through homebrew (brew install ffmbc). However, it does not preserve the timecode by default. You need to specify it with the -timecode hh:mm:ss:ff option.

If you do install homebrew, you can also use it to install ffmpeg.

0
vaibhavbshete On

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.

Sometimes it is added as a global metadata of the file, sometimes it is added specifically to the video stream, sometimes there may be a separate 'data' stream to which it is added as a metadata.

You need to find what stream the original timecode is in.

You can determine this by running

ffmpeg -i INPUT

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

This will display info about all the input streams, including the metadata. Then 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.

For exapmple, this will map metadata of the stream indexed 2 (s:2) from the first input (0:) to the global (default) metadata of the file, and copy audio-video streams to output:

ffmpeg -i INPUT -map_metadata 0:s:2 -c copy OUTPUT

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 ffmpeg documentation.

ffmpeg then reads whatever it understands from that stream (which mostly includes timecode), converts it to the destination file format's specified metadata format, and includes it in the output.

The resulting file will have a timecode recognizable in editing software, like DaVinci Resolve or Premiere Pro.