Program or script for timecode layout?

Sebaz wrote on 10/24/2010, 3:58 PM
Sorry if the title is not very descriptive but they only allow a few characters. Here's what I meant: I have footage from two Panasonic cameras, a great part of which is meant to go to a multicam track. So I set an A/V track for each camera, name them and then drag the footage from each camera onto its track. Then I open the first clip in the trimmer and go to the beginning of the clip to see what's the timecode on it, since I had set the timecode on both cameras to free run and to the current time. So if the timecode is, let's say, 11:35:20;14, I make sure the cursor is exactly at the beginning of the corresponding event in the timeline, and use the "Set Time At Cursor" feature to set it to that same timecode, and that allows me to align all the clips from both cameras perfectly, by opening each one in the trimmer and reading the timecode at the beginning, then moving cursor to that time and then the event to the exact point in the timeline.

Problem is that this takes quite a while because there are many events and I have to open each of them in the trimmer. Is there a 3rd party program or script that does this automatically? Reading the event's timecode and aligning it to the proper point in the timeline? That would be quite a time saver.

Comments

Sebaz wrote on 10/24/2010, 8:04 PM
OK, before anybody suggests this, I was just reading the manual's section on multicamera, and I saw the "Layout tracks using media timecode" command. So I opened a new project just to test this, I imported all the clips from the other project, hit Ctrl+A, and I chose that command from the menu. I heard the hard drive go ratatatatatatatat for a few seconds and then I was left with 296 tracks, half audio and half video. So obviously it doesn't work at least in the case of the metadata in Panasonic cameras, at least the AVCCAM ones, I don't know about the P2s.

Then I chose the "Layout tracks using date/media timestamp" and I got a popup dialog saying: "Some media did not have valid offset information and were skipped" and after I click OK to that, there's nothing new in the timeline.

Still, the footage has the timecode in it, since it shows in the trimmer. So I'm sure there has to be a way to automate laying out the events in the timeline.
jetdv wrote on 10/25/2010, 7:31 AM
Like this?


/**
* This script will move events to start at their timecode.
*
* Written By: Edward Troxel
* Modified: 07-04-2007
**/

using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.Reflection;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Sony.Vegas;

public class EntryPoint
{
Vegas myVegas;

public void FromVegas(Vegas vegas)
{
myVegas = vegas;

foreach (Track track in myVegas.Project.Tracks)
{
foreach(TrackEvent evnt in track.Events)
{
Media media = vegas.Project.MediaPool.Find(evnt.ActiveTake.MediaPath);
if (null == media)
{
MessageBox.Show("missing media");
throw new ArgumentException("missing media");
}

evnt.Start = media.TimecodeIn;
}
}

}



}

Sebaz wrote on 10/25/2010, 3:33 PM
Thanks, Ed. Unfortunately it didn't work. It scattered all the events at different places in the timeline, some in the wrong order. I'm guessing maybe there's something atypical about the way Panasonic AVCCAM camcorders save metadata? Or could it be that your script doesn't work only in Vegas 10? But thank you for posting it regardless.
jetdv wrote on 10/26/2010, 7:22 AM
The script isn't specific for Vegas Pro 10 - it should work fine in 10 but will also work fine in earlier version.

What the script does is look at the actual timecode reported for that clip and move it to that timecode. So if you go back to the original media and look at the timecode reported for that clip, that should be where it ends up on the timeline. Two things it does not take into consideration:

1. The timecode cannot be read
2. the offset if you first trimmed the clip.
kpauls wrote on 2/1/2018, 5:32 PM

Just in case this is of use to anyone in the future, I have implemented my own solution to this in Groovy (a JVM language).

It uses ffmpeg to replace the start timecode of all video files selected from a directory with codes relative to the creation date of the first file. The original files will still be there with ".orig" in the name. This scratches the itch for me so I won't be improving it, but feel free to use this code license CC0.

import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.attribute.FileTime
import java.time.Duration
import java.util.regex.Matcher

def filter = args.length && args[0] ? args[0] : '*.*'

FileTime ctime(String it) {
    Files.readAttributes(Paths.get(it), BasicFileAttributes).creationTime()
}

def files = new FileNameFinder().getFileNames('.', filter).toSorted { a, b ->
     ctime(a) <=> ctime(b)
}

def start = ctime(files[0]).toInstant()

String refind(Matcher m) {
    List result = m ? m[0] : null
    result ? result[1] : '0'
}

String dformat(String t) {
    def s = refind((t =~ /(\d+)S/))
    def m = refind((t =~ /(\d+)M/))
    def h = refind((t =~ /(\d+)H/))

    "$h:$m:$s.0"
}

files.each {
    def tc = dformat(Duration.between(start, ctime(it).toInstant()).toString())
    def ext = (it =~ /[^.]*$/)[0]
    def newname = it - ext + "new." + ext
    def oldname = it - ext + "orig." + ext
    "ffmpeg -i \"$it\" -timecode $tc -c copy \"$newname\"".execute().waitForProcessOutput()
    if ( !Files.setAttribute(Paths.get(newname), "basic:creationTime", ctime(it)) ) {
        return
    }
    if ( !Paths.get(it).renameTo(oldname) ) {
        return
    }
    if ( !Paths.get(newname).renameTo(it) ) {
        return
    }
}