Setting a Custom Timecode on Audio Events

In this tutorial we learn how to read the creation time and modified time from a file and use that time to set a custom “Timecode In” on the audio event. Even though this is not possible manually, it can be set using a script.

What scripts would you like to see? Any processes you’d like to see how to do using a script?

Please sign up here and leave comments with suggestions of tasks you would like to see automated. You can help guide the direction of these videos. Also, please subscribe to my YouTube channel.

14 thoughts on “Setting a Custom Timecode on Audio Events”

  1. Thanks for this great script, but is there a way to use the “TimeReference” (samples since midnight then calculated to proper TC) from BWF files instead of “CreationTime”?
    “TimeReference” does not seem to show up in the list of properties when you start to type in “CreationTime”, but I maybe overlooked it…

    Thanks,
    Nils

    1. Nils, if .NET does not allow you to reference the time, you will then need to calculate the time based on what .NET *will* allow you to access. For example, if you need the time since midnight, just ignore the date and use hour, minutes, seconds, milliseconds. That could easily be calculated to seconds using ((hour * 60) + min) * 60 + seconds + milliseconds.

      Or if the number you want is embedded in the file, you would then have to figure out how to read that number from the file.

      In short, you should be able to get what you want but it may not be directly available and you may need to calculate the value you want.

      Edward

      1. Thanks Edward for your quick reply!
        I will install the free .NET VS and try to find out, if “TimeReference” is accessable. At least it shows up under the media properties in Vegas, and Vegas can use this value when importing this file (but only then).

        The problem with using e.g. “CreationTime” is, that the BWF timecode does not necessarily refer to the actual time-of-day. So, TimeReference = 000000000 (in BWF standard called ‘midnight’) sometimes is just a start value.

        Nils

  2. Unforfunately not. Though, Vegas reads and also shows the “RIFF BroadcastExt Tags” including ‘TimeReference’ under the media properties, but I cannot access them through .NET. I couldn’t find it.

    The best solution would be, to figure out how to run ExifTool from a Vegas script, to get this info. But no idea how to do this.

    Or I manually import the file(s) through “Import BWF”, let it be placed to the correct timeline position and then use this position as custom ‘TimecodeIn’. But it looks like Vegas is converting the samples-since-midnight value to timecode incorrectly: the frame number always differs to a manual calculation. Maybe it uses a frame rate different from the project frame rate.

    1. I’m not sure how VEGAS looks at any of the information. It is possible to run an external application but getting the results back into the script may be tricky depending on how the external program is written. I don’t know anything about the Exiftool.
      Where are you seeing the information in VEGAS?
      Show me some calculations you’ve done that differ from how VEGAS is calculating the numbers.
      If you used Exiftool, what command would you use to extract the information you want?

      1. In Vegas, when I right click the file in “project media”, then “Properties”, then “General” under “File properties:” there is a section like this:
        —————————————————————————
        BWF information
        BWF version: 1
        Description: sFILENAME=180602_089_1_2.wav
        sTRK1=
        sTRK2=

        Originator:
        Originator ref.:
        Orig. date: 2018-06-02
        Orig. time: 19:41:29
        Time reference: 2227641728
        Coding history:
        ——————————————————————————

        When I manually convert 2227641728 samples with 96 kHz fs to timecode the result is 06:26:44,30 for 50 fps. Vegas 15 shows the same in the BWF import dialog and changes this depending on the project framerate (works correctly), but Vegas 18 always shows 06:26:44,14 independently from the project framerate (must be a bug). Haven’t tried Vegas 20 yet.

        Exiftool returns a string like this, which can easily be parsed:

        ———————————————————————————–
        ExifTool Version Number : 12.26
        File Name : 180602_089_1_2.wav
        Directory : R:/
        File Size : 1618 MiB
        File Modification Date/Time : 2018:06:02 23:00:52+02:00
        File Access Date/Time : 2023:01:15 15:48:36+01:00
        File Creation Date/Time : 2018:06:02 23:04:23+02:00
        File Permissions : -rw-rw-rw-
        File Type : WAV
        File Type Extension : wav
        MIME Type : audio/x-wav
        Encoding : Microsoft PCM
        Num Channels : 2
        Sample Rate : 96000
        Avg Bytes Per Sec : 576000
        Bits Per Sample : 24
        Description : sFILENAME=180602_089_1_2.wav..sTRK1= ..sTRK2= ..
        Originator :
        Originator Reference :
        Date/Time Original : 2018:06:02 19:41:29
        Time Reference : 2227641728 // This is the value I’m looking for
        BWF Version : 1
        BWF UMID : 0000000000000000000000000000000000000000000000000000000000000000
        Duration : 0:49:05
        ———————————————————————————————————–

        So, my idea was to run ExifTool with the BWF file as parameter, write the output to a temp file, read, parse (and then delete) the temp file to get the needed values into script variables.
        I used this method a lot in combination with ffmpeg, but only in batch files and not in c# Vegas scripts.

  3. “…but Vegas 18 always shows 06:26:44,14 independently from the project framerate (must be a bug). Haven’t tried Vegas 20 yet.”

    Ok, Vegas 20 behaves just like 15, no bug here anymore. So then, it might be easier to take the event position as custom ‘TimecodeIn’.

    1. I would really need to see more details such as a sample file and, possibly, the script you are using or how you are reading and calculating the value vs how VEGAS is calculating it. The WAV files I have don’t seem to have that information.

      So, a little research, it appears that the 2227641728 should be divided by the sample rate which is 96000 based on your output and that will give you a number of seconds. So I tried this:

      MessageBox.Show("time = " + Timecode.FromSeconds(2227641728/96000));

      Running that gave me a result of 6:26:44:00 with the timeline set to SMPTE Drop 29.97. Changing the timeline to 50fps changed the timeline to read 25 and the result is now 6:26:44:00 so that does not appear to make a difference in the calculation.

      Changing the code to this to force it to use fractional seconds (it, apparently, was rounding to the nearest integer since I did not include decimals):

      MessageBox.Show("time = " + Timecode.FromSeconds(2227641728.0/96000.0));

      That gave me a result of: 6:26:44:15 and swapping back to the 29.97 timeline/project, it gave me 6:26:44:18 so it DID change based on the project settings.

      Now, if I change the project back to 50fps AND I change the timeline to read “Time & Frames” instead, it gave me 6:26:44:30 (which is exactly what you are looking for).

      So right-click on the timecode above the timeline to the far left, choose “Time Format” and then choose “Time & Frames” (or Options – Ruler Format – Time & Frames). Does that give you what you want?

  4. Thanks for your efforts! I will send you a BWF WAV file by email for testing.
    Actually, I never did any tests with timeline events, I only used the “File>Import>Broadcast Wave Format” dialog, to see which timecode Vegas calculates from the ‘TimeReference’ sample count value. This was correct in V15 and V20, but not in V18.
    When I find the time I will first try to write a script that writes the TimeReference to a txt-file using ExifTool, then reads TimeReference from this file and sets it as TimecodeIn (after conversion from samples to TC).

  5. I got it working with the ExifTool, even without using a temp file with this method:

    static string GetTimeReference(string mediaFilePathTmp)
    {
    string exifToolParameter = mediaFilePathTmp + @” -s3 -timereference -samplerate”;

    Process processExifTool = new Process();
    processExifTool.StartInfo.FileName = @”C:\Program Files\ffmpeg\bin\exiftool.exe”;
    processExifTool.StartInfo.Arguments = exifToolParameter;
    processExifTool.StartInfo.UseShellExecute = false;
    processExifTool.StartInfo.RedirectStandardOutput = true;
    processExifTool.Start();

    string timeRefSampleRateTmp = processExifTool.StandardOutput.ReadToEnd();

    return timeRefSampleRateTmp;
    }

Leave a Reply