Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums VEGAS Pro Script to have sony vegas automatically add media to a layer?

  • Matt Carlson

    February 4, 2014 at 2:04 am

    It is done. Here is the script…

    7092_parseboxchanges.cs.zip

    There are a few things to mention.

    1) The overlay tracks need to be set up with one frame of the appropriate png like this:

    2) If you have no event(s) selected or anything other than the main video track event(s) selected it will not work correctly.

    3) Since this is a workaround and relatively not even possible with Vegas scripting the quality and speed of the parsing is solely dependent on the video preview quality setting. Without getting too deep in to an explanation set the video preview to Preview(Half) for the best speed results. Any other setting will cause severe speed problems or a lack of color targeting which will have the end result be useless.

    4) Speed… the video you sent to me was x264. Vegas takes a LOOOOOONG time to decode x264 frames. I re-rendered the test.avi to a standard AVC 10k bitrate and the script took half as long to complete.

    So if your original file is x264 and 45 minutes long it will take about 5 hours to parse.
    If your original is something other than x264 it will take about 2 hours and 15 minutes to finish.

    5) Since this is a script and not open to input once it starts it can’t be canceled. I would suggest breaking up video in to manageable pieces just to be safe.

    So as long as everything is set up and selected correctly the script will solo the base video track just to make sure it is only parsing pixels of the right video. Once it starts go read a book, eat a pizza, experience the love of a good woman, or write an email to Sony telling them to give the scripting environment better access to video frame information. In two hours or five everything will be golden.

  • Cain Nuke

    February 4, 2014 at 11:16 am

    Hi,

    i really appreciate the time you dedicated to do this for me. I have a few questions though. Its my first time with a script so im not really sure about how it works upon execution. Does it just adds the events to the tracks? Or it also starts rendering?

    Also, about point 1), I have to add at least one frame of each png images onto the tracks, right? Does it matter where in the time line i add them to? If so, wont they appear there for a split of a second on the rendered video?

    Tank you so much!

  • Matt Carlson

    February 4, 2014 at 7:25 pm

    The script only adds events to the tracks. It will not begin rendering. It creates the events by copying the first event of each track so technically the event can be anywhere on the track as long as it is the only event when the script starts. Since rendering does not begin it is easiest to put it at the beginning. You can delete the initial reference frames after the script is done. In fact you can make any changes you need to after the script is done.

  • Cain Nuke

    February 5, 2014 at 5:11 am

    Oh, great. I wanted to ask you also, the files i sent were just a sample, the actual file is much more complex. It has many more tracks and its always quite different in structure so i would like to discuss the script you sent me in order to be able to modify it myself accordingly. These lines below:

    boxes = new List();
    boxes.Add((VideoEvent)vegas.Project.Tracks[0].Events[0]);
    boxes.Add((VideoEvent)vegas.Project.Tracks[1].Events[0]);
    boxes.Add((VideoEvent)vegas.Project.Tracks[2].Events[0]);
    boxes.Add((VideoEvent)vegas.Project.Tracks[3].Events[0]);

    represent the tracks that are supposed to contain the png events? If thats the case Tracks[1] represents track number 1? So it means i have to place the events on that track or it wont work? Because in my actual veg file the tracks that contain those events are 8 through 11 so i thought should modify the script like below:

    boxes = new List();
    boxes.Add((VideoEvent)vegas.Project.Tracks[8].Events[0]);
    boxes.Add((VideoEvent)vegas.Project.Tracks[9].Events[0]);
    boxes.Add((VideoEvent)vegas.Project.Tracks[10].Events[0]);
    boxes.Add((VideoEvent)vegas.Project.Tracks[11].Events[0]);

    but i tried it and didnt work. How should i proceed?

    Editing: i just tested the script exactly as you sent it to me on the files i sent you but i get this error after processing a few frames:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.NullReferenceException: Object reference not set to an instance of an object.
    at ParseBoxChanges.ParseVideo(List`1 selected)
    at ParseBoxChanges..ctor(Vegas vegas)
    at EntryPoint.FromVegas(Vegas vegas)
    — End of inner exception stack trace —
    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Sony.Vegas.ScriptHost.ScriptManager.Run(Assembly asm, String className, String methodName)
    at Sony.Vegas.ScriptHost.CodeDomScriptManager.Run()
    at Sony.Vegas.ScriptHost.RunScript(Boolean fCompileOnly)

    Maybe i have the wrong version of Vegas? I have Vegas Pro 11.

    Thank you.

  • Matt Carlson

    February 5, 2014 at 7:57 am

    That is odd that the script failed on the files you sent me. I ran it multiple times successfully.
    The error is probably because you have to have video event on the main video track selected… and only that selected.

    As far identifying the tracks….

    Programming deals with zero index arrays… in short…

    Tracks[0] = Track 1
    Tracks[1] = Track 2, etc. So if you need to change the tracks use the Display Number of the track minus 1.

    So to recap. Change the vegas.Project.Tracks[ ] to Display Index minus 1 for overlay tracks you need. Make sure the first event on the overlay tracks is the proper png event. Make sure the video event on the “main video” is selected. You can split up that video if you like and only select a portion of it. It will run through only selected events.

    If the “main video” in your actual project is actually a composite of several video tracks that have not been rendered out yet then there will be the problem of the Solo line in the script since it will only be accessing a portion of the complete video. Take out the two maintrack.Solo lines and manually Solo the tracks that need to be processed before you start the script.

  • Cain Nuke

    February 5, 2014 at 8:35 am

    Ah, okay, now it started to add the events but it stopped halfway for some reason. I got the error below:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.NullReferenceException: Object reference not set to an instance of an object.
    at ParseBoxChanges.ParseVideo(List`1 selected)
    at ParseBoxChanges..ctor(Vegas vegas)
    at EntryPoint.FromVegas(Vegas vegas)
    — End of inner exception stack trace —
    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Sony.Vegas.ScriptHost.ScriptManager.Run(Assembly asm, String className, String methodName)
    at Sony.Vegas.ScriptHost.CodeDomScriptManager.Run()
    at Sony.Vegas.ScriptHost.RunScript(Boolean fCompileOnly)

  • Matt Carlson

    February 5, 2014 at 9:30 am

    Is this in the test project you sent me that it stopped halfway or your full project?

  • Matt Carlson

    February 5, 2014 at 10:14 am

    Here is an example of running your test project. I just threw the pngs at the end. The script looks for the first event on each of the overlay tracks so it is not completely necessary to have them at the beginning as you can see (although it causes a slight hiccup at the end that was easily taken care of.)

    Parse Boxes example

    Tell me if you have done anything differently. The script should not behave any differently in Vegas 11. Well… I am 99% sure that it would not.

  • Cain Nuke

    February 5, 2014 at 2:28 pm

    Im doing it on the video i sent you. This time i did everything exactly the same as you do in your video but still, it stops at about 10 seconds.What OS are you using? Im on Windows 7.

  • Matt Carlson

    February 5, 2014 at 6:59 pm

    I am also using Windows 7. We may have come across an example of why Vegas 11 crashed so much (and was reviled by many.) In the same project, doing the same things, something that should exist during play back does not. Internally variables are just disappearing.

    Find the line in the script

    Bitmap bitmap = (Bitmap)Clipboard.GetImage();

    Add this line after

    if (bitmap == null) { MessageBox.Show(“No image to analyze at ” + now); break; }

    Tell me if you get a pop-up message. Does the error occur at a different place each time you run the script?

Page 2 of 4

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy