Regions to subclips

Nat wrote on 10/16/2005, 5:13 PM
I've been looking at the new "Promote media markers" script that came with Vegas 6.0c and from what I understand it is now possible to access markers and regions embeded in media.

This means it would be possible to have a script that would convert media embeded regions to subclips.

Anyone can confirm this ?

Thanks,
Nat

Comments

JohnnyRoy wrote on 10/17/2005, 1:45 PM
Actually this would work if Vegas reported MediaRegions correctly but it doesn’t in Vegas 6.0c. Not sure if this worked before. Does that script work for regions for you? I can only get markers to work. Yes, you can create subclips (when/if regions actually works)

~jr
Nat wrote on 10/17/2005, 4:02 PM
Regions seem to work here...
JohnnyRoy wrote on 10/17/2005, 6:34 PM
Ok, I just tested it again with an AVI file and it worked fine. I was testing with a WMV file before and it would get the imbedded markers but not the regions. Just something to watch out for. So yes, MediaRegions to Subclips works fine.

~jr
Marco. wrote on 10/18/2005, 4:32 AM
How do you do this?

Marco
JohnnyRoy wrote on 10/18/2005, 6:24 AM
> How do you do this?

You have to modify the script. Here is the version that I modified for my test.

WARNING!!! You MUST save this file with a .CS extention. This is NOT a JScript file! (it’s C#) This script will only work in Vegas 6.0c and above.
/*

Script: MediaRegions To Subclips.cs
Original Author: Sony Media Software
Last Modified By: John Rofrano

This script will create Subclips from regions embedded in the
selected events' media and place them in the root mediabin.

This script is only supported by Vegas version 6.0c and above.

Last Modified: October 18, 2005.

*/

using System;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using Sony.Vegas;

public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
int processedClipCount = 0;
Project proj = vegas.Project;

foreach (Track track in proj.Tracks)
{
if (!track.IsVideo()) continue; // Only process video tracks

foreach (TrackEvent trackEvent in track.Events)
{
if (!trackEvent.Selected)
continue;

Take activeTake = trackEvent.ActiveTake;
if (null == activeTake)
continue;
Media media = activeTake.Media;
if (null == media)
continue;
Timecode eventStart = trackEvent.Start;
Timecode eventEnd = eventStart + trackEvent.Length;
Timecode takeOffset = activeTake.Offset;
Timecode position;

// Interate over all the imbedded regions and make subclips
foreach (MediaRegion mr in media.Regions)
{
position = mr.Position + eventStart - takeOffset;
if (position < eventStart || position > eventEnd)
continue;
Subclip clip = new Subclip(media.FilePath, position, mr.Length, false, mr.Label);
proj.MediaPool.RootMediaBin.Add(clip);
processedClipCount++;
}
}
}
MessageBox.Show(String.Format("{0} regions/subclips processed.", processedClipCount));
}
}

/* END OF SCRIPT */
~jr
Marco. wrote on 10/18/2005, 12:40 PM
Ah, o.k., so I see this is "only" for regions created in the trimmer, not for timeline created regions, right?

Thanks a lot anyway!!!
I think this could be a very valuable workflow helper in many cases.

Marco
Nat wrote on 10/18/2005, 8:38 PM
Thanks for that script Johnny,

I'd like to modify it to do the following :

Instead of naming the subclip with the name of the region, I'd like to name it this way :
FileName - RegionName

Example : movie.avi - Chapter 2

Is there an easy way to extract this title from the media.FileType property without the full path ?

When the region has no name Vegas names it like this : "FileName.avi - subclip 1" Which is great.

I'll also try to modify it so subclips are put in bins that are named after the media name which would be great for organization. If you had 3 media files with regions : shot1.avi, shot2.avi and shot3.avi, they would each have a bin named by their name with their respective subclips inside.

Excited Nat
JohnnyRoy wrote on 10/18/2005, 9:53 PM
> Ah, o.k., so I see this is "only" for regions created in the trimmer, not for timeline created regions, right?

Yes, but you could modify it to use timeline regions by iterating over the vegas.Project.Regions list instead of media.Regions. It would need more error checking because there is no guarantee that an event falls within the timeline regions but it can be done.

~jr
JohnnyRoy wrote on 10/18/2005, 9:54 PM
> Is there an easy way to extract this title from the media.FileType property without the full path ?

Yea, you can use System.IO.Path.GetFileName() like this:
string clipName = String.Format("{0} – {1}", System.IO.Path.GetFileName(media.FilePath), mr.Label);
This should do what you want.

~jr
Nat wrote on 10/18/2005, 10:22 PM
Thanks Johnny, I was able to get the formatting I wanted like this :

Subclip clip = new Subclip(media.FilePath, position, mr.Length, false, Path.GetFileName(media.FilePath) + " - " + " subclip " + (processedClipCount + 1) + " - " + mr.Label );

This gives me an output similar to this :

shot1.avi - subclip 1 - RegionName1
shot1.avi - subclip 2 - RegionName2
etc.

Pretty neat !
Now I'll try to make that folder thing work :)
Nat wrote on 10/18/2005, 10:25 PM
Another question, how can I detect if a region has no name ?

I tried this but it gives an error :

if (mr.Label == null)
//dostuff
Nat wrote on 10/18/2005, 10:54 PM
Found a solution, this seems to work :

if (mr.Label == "")
clipName = Path.GetFileName(media.FilePath) + " - " + " subclip " + (processedClipCount + 1);
else
clipName = Path.GetFileName(media.FilePath) + " - " + " subclip " + (processedClipCount + 1) + " - " + mr.Label;
Subclip clip = new Subclip(media.FilePath, position, mr.Length, false, clipName );

JohnnyRoy wrote on 10/19/2005, 5:18 AM
Nat, Great! You figured it out. Attributes like Labels are rarely null. They are usually assigned an empty string as you have seen. Now you’ve got the hang of it. Another technique is to build the default string first and then just add to it if there is more like this:
clipName = Path.GetFileName(media.FilePath) + " - "  + " subclip " + (processedClipCount + 1);
if (mr.Label != "")
{
clipName += " - " + mr.Label; // append the label if it exists
}
The advantage to writing it this way is that weeks later when you look at the code and you’ve forgotten what it does, you have to study the two if/else statements to see what’s different. In this example, it is more obvious that you built the string, and if the region label wasn’t empty, you appended it to the string. Also if there is a bug in building the string you only have to fix it on one line.

This is just variations on programming style (and a little religion) because it works both ways. ;-)

~jr