Audio muting script ?

R. Heffels wrote on 1/25/2006, 8:14 AM
Anyone interested in typing, or helping me with a script ?

I'm trying to list all audio and video files used on all tracks.
Then match the audio and video names,
if a duplicate name exists (like Reuters.mpg) then the audio events must be removed from it and the audio normalized.
If there is no match, the audio piece must be muted.

After that the entire selection must be rendered to MP3 with the left and right balance intact.

The idea of this all is, that I'll always have the original audio of the video that I used, in the exact length as the edited project.

If anyone can help me with this, I'll be very gratefull.
It also helps me to learn to script for Vegas if I see this code ! :-)

Comments

JohnnyRoy wrote on 1/25/2006, 10:50 AM
> Anyone interested in typing, or helping me with a script ?

Sure. I’m not clear on exactly what you want to do but let’s see how far we can get. All the examples are in C#. If you are using Vegas 6 this should not be a problem as it can use a .cs file directly. If you are using Vegas 5, this code must be compiled or you must use JScript (which I hate) ;-)

> I'm trying to list all audio and video files used on all tracks. Then match the audio and video names,

Since you are only looking for duplicates of video event source, you can store them in a Hashtable. This will ensure there are no duplicate video entries and allows quick access by name.

The following code will do this (note: it only uses the Active Take!):
Hashtable videoFiles = new Hashtable();
// iterate over all the tracks
foreach (Track track in vegas.Project.Tracks)
{
// only process video tracks
if (track.IsVideo())
{
// iterate over all the events on the track
foreach (VideoEvent videoEvent in track.Events)
{
// add any new files that don't already exist
if (!videoFiles.ContainsKey(videoEvent.ActiveTake.MediaPath))
{
videoFiles.Add(videoEvent.ActiveTake.MediaPath, videoEvent);
}
}
}
}
> if a duplicate name exists (like Reuters.mpg) then the audio events must be removed from it and the audio normalized. If there is no match, the audio piece must be muted.

For this I would just iterate over the audio events checking the video filename hashtable to see if any video event uses the same media and then normalize or mute it accordingly like this:
// iterate over all the tracks
foreach (Track track in vegas.Project.Tracks)
{
// only process audio tracks
if (track.IsAudio())
{
// iterate over all the events on the track
foreach (AudioEvent audioEvent in track.Events)
{
if (videoFiles.ContainsKey(audioEvent.ActiveTake.MediaPath))
{
// a video event DOES exists for this audio event so normalize it
audioEvent.Mute = false;
audioEvent.Normalize = true;
}
else
{
// a video event DOES NOT exists for this audio event so mute it
audioEvent.Mute = true;
}
}
}
}
> After that the entire selection must be rendered to MP3 with the left and right balance intact.

You can just do a manual render at that point but if you want to render in the script, you need to get a renderer with the correct template. The following code will do this for MP3:
Renderer renderer = vegas.Renderers.FindByName("MP3 Audio");
if (renderer != null)
{
RenderTemplate template = renderer.Templates.FindByName("128 Kbps, CD Quality Audio");
if (template != null)
{
vegas.Render("myproject.mp3", template);
}
}
That should get you started.

~jr
R. Heffels wrote on 1/27/2006, 2:52 AM
Thank you so very much !
Reading and modifying existing code gives me very much insight into creating my own scripts for Vegas.

Coming from PHP this C# code makes very much sence to me.
Much more than JavaScript and .NET do :-)

My scripts usually seem not very logical, I'm fully aware of that.
But let me try to explain:
We have a lot of not so skilled editors, who take existing video's with general noise and a voice-over.

They cut the video's a bit and place their own voice-over in a different language in the project.

So for archiving purposes we need to mute all the audio that isn't linked to the video (which is our translated voice-over).
And normalize and de-mute the audio that IS linked to the video (which is the original audio).

So any professional editor can do this very easily by using only track 1 or 2 for the original audio, and then solo it and render it as MP3.
But for our dummy staff we just need a button with a script attached to it :-)

Anyways, thanks again for you time !
JohnnyRoy wrote on 1/27/2006, 6:14 AM
Gotcha! The code above doesn’t de-mute so you might want to add a Mute = false along with the Normalize = true if you think they might have muted the original audio. Good Luck!

(Edit) I just modified the code above to do this. ;-)

~jr
R. Heffels wrote on 2/1/2006, 4:18 AM
Thanks :-)
I'm also trying to get rid of all the envelopes on the tracks that need to be rendered.
Somehow I can't find how this works.
JohnnyRoy wrote on 2/2/2006, 10:16 AM
> I'm also trying to get rid of all the envelopes on the tracks that need to be rendered.

If you just want to remove all the envelopes on a track, it’s only one line of code:
    track.Envelopes.Clear();
There is no way to get them back so this is a destructive approach but I don’t think there is a way to simply disable them.

~jr