Subtitle related scripts for Vegas 5

barleycorn wrote on 4/21/2004, 7:06 AM
Not sure what the form is for requesting scripts but the following would be welcome:

Import Subtitles as Regions (i.e. the reverse of the Export Regions as Subtitles script included with Vegas 5)
Import Subtitles as Commands (i.e. as command markers - specifically 'TEXT')

I don't think this functionality is available at the moment.

Comments

roger_74 wrote on 4/21/2004, 7:21 AM
I'll do it this weekend if no one else has by then, it's not very complicated but I'm swamped.
barleycorn wrote on 4/21/2004, 8:50 AM
Thank you very much. Looking forward to it.
roger_74 wrote on 4/24/2004, 4:46 PM
Download:

//Import Subtitles As Regions
//Roger Magnusson
//www.rmtools.se

import System.IO;
import Sony.Vegas;
import System.Windows.Forms;

try
{
    var sr : StreamReader = new StreamReader(ShowOpenFileDialog("DVD Architect Subtitle Script (*.sub)|*.sub", "Import Subtitles As Regions", null));
    var line : String;

    while ((line = sr.ReadLine()) != null)
    {
        if (line != String.Empty)
        {
            var regionNumber : int = parseInt(line.Substring(0, 4));
            if (isNaN(regionNumber)) continue;

            var tab1 : int;
            var tab2 : int;
            var regionStart : Timecode;
            var regionLength : Timecode;
            var regionLabel : String;

            tab1 = line.IndexOf("\t");
            tab2 = line.IndexOf("\t", tab1 + 1);

            regionStart = GetTimecode(tab1, tab2);

            tab1 = line.IndexOf("\t", tab2);
            tab2 = line.IndexOf("\t", tab1 + 1);

            regionLength = GetTimecode(tab1, tab2) - regionStart;

            tab1 = line.IndexOf("\t", tab2);

            regionLabel = line.Substring(tab1 + 1);

            TryAddRegion(regionStart, regionLength, regionLabel);
        }
    }

    sr.Close();
}
catch(e)
{
    MessageBox.Show(e);
}

function GetTimecode(startPos : int, endPos : int) : Timecode
{
    var tc : String = line.Substring(startPos + 1, endPos - startPos - 1);
    var lastSeparatorPos : int = tc.LastIndexOf(":");

    tc = tc.Substring(0, lastSeparatorPos) + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + tc.Substring(lastSeparatorPos + 1) + "0";

    return Timecode.FromString(tc, RulerFormat.Time);
}

function TryAddRegion(start : Timecode, length : Timecode, label : String)
{
    try
    {
        Vegas.Project.Regions.Add(new Region(start, length, label));
    }
    catch(e)
    {
        start += Timecode.FromNanos(1);
        TryAddRegion(start, length, label);
    }
}

//From Sonys "Import XML.js"
function ShowOpenFileDialog(filter, title, defaultFilename)
{
    var openFileDialog = new OpenFileDialog();

    if (null == filter) filter = "All Files (*.*)|*.*";
    openFileDialog.Filter = filter;

    if (null != title) openFileDialog.Title = title;
    openFileDialog.CheckPathExists = true;
    openFileDialog.AddExtension = true;

    if (null != defaultFilename)
    {
        var initialDir = Path.GetDirectoryName(defaultFilename);

        if (Directory.Exists(initialDir)) openFileDialog.InitialDirectory = initialDir;

        openFileDialog.DefaultExt = Path.GetExtension(defaultFilename);
        openFileDialog.FileName = Path.GetFileName(defaultFilename);
    }

    if (System.Windows.Forms.DialogResult.OK == openFileDialog.ShowDialog())
        return Path.GetFullPath(openFileDialog.FileName);
    else
        return null;
}

roger_74 wrote on 4/25/2004, 2:45 AM
Import Subtitles as Commands (i.e. as command markers - specifically 'TEXT')

Barleycorn, I've never used these. What decides the duration of the text?
barleycorn wrote on 4/25/2004, 3:47 AM
Firstly, thanks very much for your Import Subtitles as Commands script. I've only just grabbed it but will give it a thorough workout shortly (no problems with the couple of times I've run it so far).

> What decides the duration of the text?

Like normal markers, command markers only have a position not a length. The script I'm hoping for would add two markers for each line in the subtitles file:

0000 00:00:10:16 00:00:20:12 First Region

0001 00:00:23:64 00:00:40:92 Second Region

0002 00:00:43:76 00:00:58:36 Third Region

would become command markers as follows:

00:00:10:16 "First Region"
00:00:20:12 ""
00:00:23:64 "Second Region"
00:00:40:92 ""
00:00:43:76 "Third Region"
00:00:58:36 ""
johnmeyer wrote on 4/25/2004, 8:54 AM
Roger,

Thanks for the script!
akg wrote on 4/28/2004, 11:56 AM
This text format is only for dvd archect 2.0
Can outlet to this format for any dvd authoring software !!

Like this
----------------------------------------------------------------------------
0000
00:00:00:00 --> 00:00:00:00
HI

0001
00:00:05:00 --> 00:00:12:26
I`M OK
--------------------------------------------------------------------------
VMP wrote on 10/16/2005, 12:25 PM
Hi, I tried the script (above) to import subtitles from my DVDA 2 to Vegas 5.

So made a script.js pasted the script, opend vegas ran script opend a saved subtitle.sub.

But before opening it I get a message which says the following:

"ERROR: lenght can't be less than zero"
"parameter name: length"

Did I mis a step?

Thanks,
V
JohnnyRoy wrote on 10/16/2005, 4:46 PM
Just use SubText from the VASST Freeware collection. It will let you import a .SUB file as Regions.

~jr
VMP wrote on 10/17/2005, 5:30 AM
Thanks for the tip JohnnyRoy ,

But the program dosent seem to accept second line of .sub text.

for example

0001 00:05:19:83 00:05:22:66 person hello.
--> Person Yellow

The second line 'Person Yellow ' text line in this case.


The vasst dosent accept it it just stops putting the regions.
But after removing all the 'second lines of text' in the 'subtitle .sub' vasst seems to continue.
Is there a reason for this?

Because obviosly DVDA2 puts the second line of each Sub text event to the second line of the .sub file.

Thanks for any reply,
V
JohnnyRoy wrote on 10/17/2005, 6:56 AM
> Is there a reason for this?

Yea, just an oversight. ;-) I’ll get that fixed.

~jr
VMP wrote on 10/17/2005, 7:07 AM
No problem.

It says on the vasst website:

"SubText will then place/generate subtitles and regions to your project, saving you enormous amounts of time."

Does this mean that there will be 'text fields/events' generated between the regions aswell?

Or should that be done customly as I am doing now ;-)
so add text events between the generated regions _> past text per event.?

V
JohnnyRoy wrote on 10/17/2005, 1:16 PM
It only adds the text as regions. It does not create text events. :( Sorry if the wording sounds like it does. I will fix that when I upload the next version.

~jr
JohnnyRoy wrote on 10/18/2005, 6:00 AM
OK. An updated version of SubText 1.1.1 is on the VASST site. Please test it and let mw know if this solves your problem.

~jr
VMP wrote on 10/20/2005, 4:54 AM
Great!, no more errors, good job JohnnyRoy ;-)