Making scripts for automatically adding (specific) Color Correction?

Mathematics wrote on 12/19/2018, 1:55 PM

Hi, I need some help with writing a script where I would be able to add a specific preset of color correction to either every clip in my video track or to the overall video track itself (2 separate scripts).

I'm fairly new to scripting/coding in general, so when I took a look at the API documentation, I was fairly confused as to what steps I should be taking.

There were a couple of things I was looking at in the API like [OFXColor Class] and [VideoColor Class] but I'm not exactly sure how to implement them...

What classes and such should I be using for writing this script and how should I go about implementing them?

I use Sony (Edit: Magix) Vegas Pro 15 on Windows 10 and I am also writing in C-Sharp using the Atom IDE (I used another premade script as a template for this script).

Thank you in advance!

Comments

klt wrote on 12/19/2018, 3:10 PM

For that you don't need a script. Just apply the color coorecting effects to an event, then copy it (edit/copy). Then select all the targeted events, and paste attributes.

BTW since version 13 Magix took over the Vegas product line from Sony.

Mathematics wrote on 12/19/2018, 3:45 PM

@klt That works as well.

However, if I were to have a bunch of clips (e.g. 40-50) from different videos along different video tracks, rather than pasting the attributes to every single clip, is there a way that I can create a script that would add a specific color correction to every single clip on the timeline? It's just to improve the workflow in general for large projects.

Also, thanks for the Magix reminder, I guess my mind still lives back in old days of Sony Vegas.

Thanks for the response!

fr0sty wrote on 12/19/2018, 3:53 PM

Just save a preset... set the colors as you like them, then in the preset panel above, type a name for that preset, and click the disk icon. You can call that preset back up on any other clip. If you want to add it to every clip at once, add it at the project level (the fx button by the preview window). Otherwise you can add it at the track, media, or event level.

Last changed by fr0sty on 12/19/2018, 3:54 PM, changed a total of 1 times.

Systems:

Desktop

AMD Ryzen 7 1800x 8 core 16 thread at stock speed

64GB 3000mhz DDR4

Geforce RTX 3090

Windows 10

Laptop:

ASUS Zenbook Pro Duo 32GB (9980HK CPU, RTX 2060 GPU, dual 4K touch screens, main one OLED HDR)

Marco. wrote on 12/19/2018, 3:55 PM

Scripts like this exists. For the one copied here you'd need to replace the desired FX name and the desired preset name.

import ScriptPortal.Vegas; 
import System.Windows.Forms;
import Microsoft.Win32;

// FX Name
var plugInName = "VEGAS Color Corrector";
// Preset Name
var presetName = "cool";
try
                {
for (var track in Vegas.Project.Tracks)     {
for (var evnt in track.Events)         {
if (!evnt.Selected || evnt.MediaType != MediaType.Video) continue;
var fx = Vegas.VideoFX;
var plugIn = fx.GetChildByName(plugInName);
if (null == plugIn)         {
throw "could not find a plug-in named: '" + plugInName + "'";
            }
var effect = new Effect(plugIn);
evnt.Effects.Add(effect);
if (null != presetName)     {
effect.Preset = presetName;
            }
                }
                }
                }
catch (errorMsg)
            {
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

 

Eagle Six wrote on 12/19/2018, 3:57 PM

You can apply a color correction preset at the track level, which of course applies the preset to any clip in that track. Or, you can apply a preset on the project level which will effect all clips (events) on all video tracks. If you have various Fx's you use for color corrections, such as brightness, color correction, color corrector secondary, levels, etc., you would most likely save additional time by creating a LUT including all the corrections you are using and then apply that for selective events on a track, or the track level, or the project level.

System Specs......
Corsair Obsidian Series 450D ATX Mid Tower
Asus X99-A II LGA 2011-v3, Intel X99 SATA 6 Gb/s USB 3.1/3.0 ATX Intel Motherboard
Intel Core i7-6800K 15M Broadwell-E, 6 core 3.4 GHz LGA 2011-v3 (overclocked 20%)
64GB Corsair Vengeance LPX DDR4 3200
Corsair Hydro Series H110i GTX 280mm Extreme Performance Liquid CPU Cooler
MSI Radeon R9 390 DirectX 12 8GB Video Card
Corsair RMx Series RM750X 740W 80 Plus Gold power pack
Samsung 970 EVO NVMe M.2 boot drive
Corsair Neutron XT 2.5 480GB SATA III SSD - video work drive
Western Digitial 1TB 7200 RPM SATA - video work drive
Western Digital Black 6TB 7200 RPM SATA 6Bb/s 128MB Cache 3.5 data drive

Bluray Disc burner drive
2x 1080p monitors
Microsoft Window 10 Pro
DaVinci Resolve Studio 16 pb2
SVP13, MVP15, MVP16, SMSP13, MVMS15, MVMSP15, MVMSP16

Former user wrote on 12/19/2018, 3:58 PM

Just add the color correction effect to the Track. The effect is automatically applied across the entire video track and all the clips that are in it.

Former user wrote on 12/19/2018, 4:31 PM

Or copy effect, select all clips and paste.

Mathematics wrote on 12/19/2018, 6:32 PM

Scripts like this exists. For the one copied here you'd need to replace the desired FX name and the desired preset name.

import ScriptPortal.Vegas; 
import System.Windows.Forms;
import Microsoft.Win32;

// FX Name
var plugInName = "VEGAS Color Corrector";
// Preset Name
var presetName = "cool";
try
                {
for (var track in Vegas.Project.Tracks)     {
for (var evnt in track.Events)         {
if (!evnt.Selected || evnt.MediaType != MediaType.Video) continue;
var fx = Vegas.VideoFX;
var plugIn = fx.GetChildByName(plugInName);
if (null == plugIn)         {
throw "could not find a plug-in named: '" + plugInName + "'";
            }
var effect = new Effect(plugIn);
evnt.Effects.Add(effect);
if (null != presetName)     {
effect.Preset = presetName;
            }
                }
                }
                }
catch (errorMsg)
            {
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

 

@Marco. Thanks for the response! This was what I was looking for.

I am not super familiar with C# (or scripting in general) but I gave this a shot. I came out with a few errors earlier and now I am just down to one error:

"A namespace cannot directly contain members such as fields or methods"

From what I've found on the internet, it relates to classes within C#, however, I'm not finding the trouble within the code:

Import System;
Import System.IO;
Import System.Text;
Import System.Drawing;
Import System.Reflection;
Import System.Diagnostics;
Import System.Collections;
Import System.Windows.Forms;
Import System.ComponentModel;
Import System.Runtime.InteropServices;
Import Microsoft.Win32;
Import ScriptPortal.Vegas;

public class EntryPoint
{
Vegas myVegas;
public void FromVegas(Vegas vegas)
{
myVegas = vegas;

// Introduce Plugin

var plugInName = "VEGAS Color Corrector";

// Introduce Preset

var presetName = "normal";
try

{
for (var track in Vegas.Project.Tracks)
{
for (var evnt in track.Events)
{
if (!evnt.Selected || evnt.MediaType != MediaType.Video) continue;

var fx = Vegas.VideoFX;

var PlugIn = fx.GetChildByName(VEGAS Color Corrector);

if (null == plugIn)
{
throw "could not find a plug-in named: '" + plugInName + "'";

}
var effect = new Effect(plugIn);
evnt.Effects.Add(effect);
if (null != presetName);
{
effect.Preset = presetName;
}
}
}
}
catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}

I appreciate any criticism and/or ideas as to how I can correct this error.

Former user wrote on 12/19/2018, 7:18 PM

Are you saving the script with the extension (.js) or (.cs)? I believe the correct one for this script is the extension (.js). That's why this error is occurring.

Marco. wrote on 12/20/2018, 1:45 AM

Yes, the code I copied is meant to be saved as .js. But I think Mathematics wants to convert this one into C#.

I can't help there as I have almost zero coding knowledge (I'm only successful – in some cases – in cutting and pasting code fragments). The code shown above is from an unknown author. I didn't write it.

jetdv wrote on 12/20/2018, 9:05 AM

To convert to a .cs would require a lot of changes. For example, "Import" becomes "Using". There is no "var", you must use a variable type instead such as "string".

Mathematics wrote on 12/20/2018, 5:03 PM

Are you saving the script with the extension (.js) or (.cs)? I believe the correct one for this script is the extension (.js). That's why this error is occurring.


@Former user I am in fact using (.cs), I have recently changed it to (.js) as it was intended to be. Good catch!

Yes, the code I copied is meant to be saved as .js. But I think Mathematics wants to convert this one into C#.

I can't help there as I have almost zero coding knowledge (I'm only successful – in some cases – in cutting and pasting code fragments). The code shown above is from an unknown author. I didn't write it.

@Marco. That's alright. The code helped me build a decent foundation for what I am trying to make. Thank You.

To convert to a .cs would require a lot of changes. For example, "Import" becomes "Using". There is no "var", you must use a variable type instead such as "string".

@jetdv Hello! I think I actually use some of your scripts in Vegas.

I changed the file extension to (.js) and slightly altered the code for Javascript:

import System;
import System.IO;
import System.Text;
import System.Drawing;
import System.Reflection;
import System.Diagnostics;
import System.Collections;
import System.Windows.Forms;
import System.ComponentModel;
import System.Runtime.InteropServices;
import Microsoft.Win32;
import ScriptPortal.Vegas;

try{
  // introduce PlugIn

  var plugInName = "Vegas Color Corrector";

  // introduce Preset

  var presetName = "Normal";{

    for (var track in Vegas.Project.Tracks) {
      for (var evnt in track.Events) {
        if (!evnt.Selected || evnt.MediaType != MediaType.Video) {
          continue;

          var fx = Vegas.VideoFX;
          var plugIn = fx.GetChildByName(plugInName)

          // ^ Introduces the selected FX

          if (null == plugIn){
            throw "could not find a plug-in named: '" + plugInName + "'";

          }
          var effect = new Effect(plugIn);
          evnt.Effects.Add(effect);
          if (null != presetName){
            effect.Preset = presetName;
          }
        }
      }
    }
  }
}
catch (errorMsg){
  MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

On the bright side, there are absolutely no errors (from Vegas), however, it didn't do what I intended it to do.

When I run the script, it does absolutely nothing. I checked the FX on the video track level and on the individual clips... nothing was altered.

Marco. wrote on 12/20/2018, 5:18 PM

Not sure how important are the upper cases in "VEGAS Color Corrector" instead of "Vegas Color Corrector".