Align Timecodes

Align Timecodes is especially useful in the case where you create video with multiple cameras capable of recording a timecode in the metadata of each file. Let’s say we have recorded three videos at the same time at a concert with each camera set up at unique positions and at different angles. All of the cameras start recording at various times but were synchronized with the same master clock (Timecode Sync Generator or Jam Sync timecode) so that the recordings are timestamped with that synchronized time. For example, the 3 cameras have embedded metadata as follows:     camera 1 = 00:00:00:01     camera 2 = 00:00:10:07     camera 3 = 00:00:17:22

Figure 6.16: Before sync
Image timecode-01

Timecode synchronization is performed by the program when you choose the option Align Timecodes and works in 2 steps. The first automatic step is to locate the earliest timecode and the second step is to align the edits on the armed tracks using that time on the timeline.

When you load in the three files to different tracks, they'll be placed on a timeline that starts from 00 : 00 : 00 : 00 as usual. But, by middle mouse clicking (MMB) on any of the video tracks, you can view the timecode embedded at that point in that file.

To make it easy to align the videos onto the timeline manually, set the origin point, that is the leftmost time index, of the timebar to the timecode of the earliest video. For the 3 aforementioned cameras this would be camera 1 with a timeecode of 00 : 00 : 00 : 01. By using the clapboard button on the main timeline, you can set 00 : 00 : 00 : 01 as the start timecode. Then positioning the camera 1 video at the start of the timeline will line its frames up with the times on the timebar.

Figure 6.17: Clapperboard button
Image timecode-02

Similarly, using the middle mouse button to view the other 2 camera’s timecodes, you can position them so their timecodes line up and now all three tracks will be in sync. You can do this manually or simply do it automatically with the option under: Tracks Align Timecodes. See figure 6.18

Figure 6.18: After sync
Image timecode-03

Timecode synchronization in CINELERRA-GG is based on the inclusion of an actual timecode saved in the media as can be seen using the ffprobe or mediainfo command line. Examples are shown here:

# ffprobe
handler_name:	VideoHandler
timecode:		00:00:20:01

# mediainfo mtb.mp4
Time code of first frame:	11:05:49:41
Time code, striped:		Yes
Title:				GoPro AVC

Many newer cameras and media in a MOV container have valid timecodes often with SMPTE compliant start Timecode in Quicktime format, whereas others do not. Most low end cameras do not. When no timecode is present, various clock time values may be used to synchronize instead.

There are various types of timecodes and they are written in metadata in various ways. Because it is not clear which timecode in the file is the one to use or there is none, the precedence as described next is followed. The contexts, packets, streams, and data refer to the corresponding ffmpeg data or metadata objects:

  1. if the format context has a timecode use: fmt_ctx timecode - 0
  2. if the layer/channel has a timecode use: st timecode - (start_time -nudge)
  3. find the first program stream with video stream, and if the video stream has a timecode use: st timecode - (start_time-nudge)
  4. find timecode in any stream use: st timecode
  5. read 100 packets, save ofs=pkt.pts*st time_base - st nudge:
  6. if the filename/url scans *date_time.ext use: date_time (yr, month, day, hr, min, sec, nanosecond)
  7. if stat (display file status) works on the filename/url use: mtime (modification time)
  8. finally, if none of the above are usable, then return failure

Operation of Align Timecodes includes the following options to help in your setup and review (figure 6.19):

Figure 6.19: Timecode via MMB on track and via Resources windows/Info
Image timecode-04


ffmpeg -i originalfile.mp4 -metadata timecode="14:36:08:29" -c copy newfile.mp4

# where "-i" is followed by the input filename
# where "-metadata timecode" is followed by the timecode key
# where "-c copy" just copies the video/audio to the following output filename

The CINELERRA-GG Community, 2021