diff --git a/Automator.cs b/Automator.cs new file mode 100644 index 0000000..1cbd10b --- /dev/null +++ b/Automator.cs @@ -0,0 +1,217 @@ +// Sony Vegas (<=13) script to set random automation +// values for video effects quickly and automatically. +// +// Author: delthas +// Date: 2018-11-29 +// License: MIT +// Source: https://github.com/delthas/vegas-datamosh +// Documentation: https://github.com/delthas/vegas-datamosh +// Version: 1.3.0 +// + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Security.Cryptography; +using System.Text; +using System.Windows.Forms; +using Microsoft.Win32; +using Sony.Vegas; + +namespace VegasAutomator { + public class EntryPoint { + private static readonly Random Random = new Random(); + + public void FromVegas(Vegas vegas) { + var events = vegas.Project.Tracks + .SelectMany(track => track.Events) + .Where(t => t.Selected) + .Where(t => t.IsVideo()) + .Cast() + .ToList(); + + var effects = events + .SelectMany(ev => ev.Effects) + .Where(ev => !ev.Bypass) + .Where(ev => { + try { + return ev.IsOFX; + } catch (COMException) { + // vegas api throwing an exception if not ofx + return false; + } + }) + .Select(ev => ev.OFXEffect) + .GroupBy(ev => ev.Label) + .Select(ev => ev.First()) + .ToList(); + + var parameterEnabled = new HashSet>(); + + foreach (var effect in effects) { + foreach (var parameter in effect.Parameters) { + if (parameter.Label == null) { + continue; + } + if(!(parameter is OFXChoiceParameter + || parameter is OFXDouble2DParameter + || parameter is OFXDouble3DParameter + || parameter is OFXDoubleParameter + || parameter is OFXInteger2DParameter + || parameter is OFXInteger3DParameter + || parameter is OFXIntegerParameter + || parameter is OFXRGBAParameter + || parameter is OFXRGBParameter)) { + continue; + } + + var key = effect.Label.Trim() + " - " + parameter.Label.Trim(); + string hashed; + using (MD5 md5 = MD5.Create()) { + hashed = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(key))).Replace("-", ""); + } + var renderChecked = (string) Registry.GetValue( + "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", + "Automate_" + hashed, ""); + var defaultCheck = renderChecked == "True"; + + var prompt = new Form { + Width = 300, + Height = 150, + Text = "Automator Parameters", + KeyPreview = true + }; + var textLabel = new Label {Left = 10, Top = 10, Width = 280, Text = key}; + var textLabel2 = new Label {Left = 80, Top = 45, Text = "Scramble"}; + var inputBox = new CheckBox { + Left = 200, + Top = 40, + Width = 240, + Checked = defaultCheck + }; + var confirmation = new Button {Text = "OK", Left = 110, Width = 100, Top = 75}; + confirmation.Click += (sender, e) => { + prompt.DialogResult = DialogResult.OK; + prompt.Close(); + }; + prompt.KeyPress += (sender, args) => { + if (args.KeyChar != ' ') return; + inputBox.Checked = !inputBox.Checked; + args.Handled = true; + }; + prompt.KeyUp += (sender, args) => { + if (args.KeyCode != Keys.Space) return; + args.Handled = true; + }; + prompt.Controls.Add(confirmation); + prompt.Controls.Add(textLabel); + prompt.Controls.Add(inputBox); + prompt.Controls.Add(textLabel2); + prompt.AcceptButton = confirmation; + inputBox.Select(); + if (prompt.ShowDialog() != DialogResult.OK) { + return; + } + + if (defaultCheck != inputBox.Checked) { + Registry.SetValue( + "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", + "Automate_" + hashed, inputBox.Checked.ToString(), RegistryValueKind.String); + } + + if (inputBox.Checked) { + parameterEnabled.Add(new Tuple(effect.Label, parameter.Name)); + } + } + } + + if (parameterEnabled.Count == 0) { + return; + } + + foreach (var ev in events) { + foreach (var effect in ev.Effects) { + if (effect.Bypass) { + continue; + } + try { + if (!effect.IsOFX) { + continue; + } + } catch (COMException) { + // vegas api throwing an exception if not ofx + continue; + } + var ofx = effect.OFXEffect; + foreach (var parameter in ofx.Parameters) { + if (!parameterEnabled.Contains(new Tuple(ofx.Label, parameter.Name))) { + continue; + } + + if(parameter is OFXChoiceParameter) { + var p = parameter as OFXChoiceParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), p.Choices[Random.Next(0, p.Choices.Length)]); + } + } else if (parameter is OFXDouble2DParameter) { + var p = parameter as OFXDouble2DParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXDouble2D { + X = p.DisplayMin.X + (p.DisplayMax.X - p.DisplayMin.X) * Random.NextDouble(), + Y = p.DisplayMin.Y + (p.DisplayMax.Y - p.DisplayMin.Y) * Random.NextDouble() + }); + } + } else if (parameter is OFXDouble3DParameter) { + var p = parameter as OFXDouble3DParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXDouble3D { + X = p.DisplayMin.X + (p.DisplayMax.X - p.DisplayMin.X) * Random.NextDouble(), + Y = p.DisplayMin.Y + (p.DisplayMax.Y - p.DisplayMin.Y) * Random.NextDouble(), + Z = p.DisplayMin.Z + (p.DisplayMax.Z - p.DisplayMin.Z) * Random.NextDouble() + }); + } + } else if (parameter is OFXDoubleParameter) { + var p = parameter as OFXDoubleParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), p.DisplayMin + (p.DisplayMax - p.DisplayMin) * Random.NextDouble()); + } + } else if (parameter is OFXInteger2DParameter) { + var p = parameter as OFXInteger2DParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXInteger2D { + X = Random.Next(p.DisplayMin.X, p.DisplayMax.X), + Y = Random.Next(p.DisplayMin.Y, p.DisplayMax.Y) + }); + } + } else if (parameter is OFXInteger3DParameter) { + var p = parameter as OFXInteger3DParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXInteger3D { + X = Random.Next(p.DisplayMin.X, p.DisplayMax.X), + Y = Random.Next(p.DisplayMin.Y, p.DisplayMax.Y), + Z = Random.Next(p.DisplayMin.Z, p.DisplayMax.Z) + }); + } + } else if (parameter is OFXIntegerParameter) { + var p = parameter as OFXIntegerParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), Random.Next(p.DisplayMin, p.DisplayMax)); + } + } else if (parameter is OFXRGBAParameter) { + var p = parameter as OFXRGBAParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXColor(Random.NextDouble(), Random.NextDouble(), Random.NextDouble(), Random.NextDouble())); + } + } else if (parameter is OFXRGBParameter) { + var p = parameter as OFXRGBParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXColor(Random.NextDouble(), Random.NextDouble(), Random.NextDouble())); + } + } + } + } + } + } + } +} diff --git a/Automator.cs.config b/Automator.cs.config new file mode 100644 index 0000000..2defaa6 --- /dev/null +++ b/Automator.cs.config @@ -0,0 +1,7 @@ + + + System.dll + System.Core.dll + -debug -D:DEBUG + Automator.png + \ No newline at end of file diff --git a/Automator.png b/Automator.png new file mode 100644 index 0000000..1a21d09 Binary files /dev/null and b/Automator.png differ diff --git a/Automator14.cs b/Automator14.cs new file mode 100644 index 0000000..7ec437f --- /dev/null +++ b/Automator14.cs @@ -0,0 +1,217 @@ +// Sony Vegas (<=13) script to set random automation +// values for video effects quickly and automatically. +// +// Author: delthas +// Date: 2018-11-29 +// License: MIT +// Source: https://github.com/delthas/vegas-datamosh +// Documentation: https://github.com/delthas/vegas-datamosh +// Version: 1.3.0 +// + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Security.Cryptography; +using System.Text; +using System.Windows.Forms; +using Microsoft.Win32; +using ScriptPortal.Vegas; + +namespace VegasAutomator { + public class EntryPoint { + private static readonly Random Random = new Random(); + + public void FromVegas(Vegas vegas) { + var events = vegas.Project.Tracks + .SelectMany(track => track.Events) + .Where(t => t.Selected) + .Where(t => t.IsVideo()) + .Cast() + .ToList(); + + var effects = events + .SelectMany(ev => ev.Effects) + .Where(ev => !ev.Bypass) + .Where(ev => { + try { + return ev.IsOFX; + } catch (COMException) { + // vegas api throwing an exception if not ofx + return false; + } + }) + .Select(ev => ev.OFXEffect) + .GroupBy(ev => ev.Label) + .Select(ev => ev.First()) + .ToList(); + + var parameterEnabled = new HashSet>(); + + foreach (var effect in effects) { + foreach (var parameter in effect.Parameters) { + if (parameter.Label == null) { + continue; + } + if(!(parameter is OFXChoiceParameter + || parameter is OFXDouble2DParameter + || parameter is OFXDouble3DParameter + || parameter is OFXDoubleParameter + || parameter is OFXInteger2DParameter + || parameter is OFXInteger3DParameter + || parameter is OFXIntegerParameter + || parameter is OFXRGBAParameter + || parameter is OFXRGBParameter)) { + continue; + } + + var key = effect.Label.Trim() + " - " + parameter.Label.Trim(); + string hashed; + using (MD5 md5 = MD5.Create()) { + hashed = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(key))).Replace("-", ""); + } + var renderChecked = (string) Registry.GetValue( + "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", + "Automate_" + hashed, ""); + var defaultCheck = renderChecked == "True"; + + var prompt = new Form { + Width = 300, + Height = 150, + Text = "Automator Parameters", + KeyPreview = true + }; + var textLabel = new Label {Left = 10, Top = 10, Width = 280, Text = key}; + var textLabel2 = new Label {Left = 80, Top = 45, Text = "Scramble"}; + var inputBox = new CheckBox { + Left = 200, + Top = 40, + Width = 240, + Checked = defaultCheck + }; + var confirmation = new Button {Text = "OK", Left = 110, Width = 100, Top = 75}; + confirmation.Click += (sender, e) => { + prompt.DialogResult = DialogResult.OK; + prompt.Close(); + }; + prompt.KeyPress += (sender, args) => { + if (args.KeyChar != ' ') return; + inputBox.Checked = !inputBox.Checked; + args.Handled = true; + }; + prompt.KeyUp += (sender, args) => { + if (args.KeyCode != Keys.Space) return; + args.Handled = true; + }; + prompt.Controls.Add(confirmation); + prompt.Controls.Add(textLabel); + prompt.Controls.Add(inputBox); + prompt.Controls.Add(textLabel2); + prompt.AcceptButton = confirmation; + inputBox.Select(); + if (prompt.ShowDialog() != DialogResult.OK) { + return; + } + + if (defaultCheck != inputBox.Checked) { + Registry.SetValue( + "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", + "Automate_" + hashed, inputBox.Checked.ToString(), RegistryValueKind.String); + } + + if (inputBox.Checked) { + parameterEnabled.Add(new Tuple(effect.Label, parameter.Name)); + } + } + } + + if (parameterEnabled.Count == 0) { + return; + } + + foreach (var ev in events) { + foreach (var effect in ev.Effects) { + if (effect.Bypass) { + continue; + } + try { + if (!effect.IsOFX) { + continue; + } + } catch (COMException) { + // vegas api throwing an exception if not ofx + continue; + } + var ofx = effect.OFXEffect; + foreach (var parameter in ofx.Parameters) { + if (!parameterEnabled.Contains(new Tuple(ofx.Label, parameter.Name))) { + continue; + } + + if(parameter is OFXChoiceParameter) { + var p = parameter as OFXChoiceParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), p.Choices[Random.Next(0, p.Choices.Length)]); + } + } else if (parameter is OFXDouble2DParameter) { + var p = parameter as OFXDouble2DParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXDouble2D { + X = p.DisplayMin.X + (p.DisplayMax.X - p.DisplayMin.X) * Random.NextDouble(), + Y = p.DisplayMin.Y + (p.DisplayMax.Y - p.DisplayMin.Y) * Random.NextDouble() + }); + } + } else if (parameter is OFXDouble3DParameter) { + var p = parameter as OFXDouble3DParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXDouble3D { + X = p.DisplayMin.X + (p.DisplayMax.X - p.DisplayMin.X) * Random.NextDouble(), + Y = p.DisplayMin.Y + (p.DisplayMax.Y - p.DisplayMin.Y) * Random.NextDouble(), + Z = p.DisplayMin.Z + (p.DisplayMax.Z - p.DisplayMin.Z) * Random.NextDouble() + }); + } + } else if (parameter is OFXDoubleParameter) { + var p = parameter as OFXDoubleParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), p.DisplayMin + (p.DisplayMax - p.DisplayMin) * Random.NextDouble()); + } + } else if (parameter is OFXInteger2DParameter) { + var p = parameter as OFXInteger2DParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXInteger2D { + X = Random.Next(p.DisplayMin.X, p.DisplayMax.X), + Y = Random.Next(p.DisplayMin.Y, p.DisplayMax.Y) + }); + } + } else if (parameter is OFXInteger3DParameter) { + var p = parameter as OFXInteger3DParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXInteger3D { + X = Random.Next(p.DisplayMin.X, p.DisplayMax.X), + Y = Random.Next(p.DisplayMin.Y, p.DisplayMax.Y), + Z = Random.Next(p.DisplayMin.Z, p.DisplayMax.Z) + }); + } + } else if (parameter is OFXIntegerParameter) { + var p = parameter as OFXIntegerParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), Random.Next(p.DisplayMin, p.DisplayMax)); + } + } else if (parameter is OFXRGBAParameter) { + var p = parameter as OFXRGBAParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXColor(Random.NextDouble(), Random.NextDouble(), Random.NextDouble(), Random.NextDouble())); + } + } else if (parameter is OFXRGBParameter) { + var p = parameter as OFXRGBParameter; + for (int i = 0; i < ev.Length.FrameCount; i++) { + p.SetValueAtTime(Timecode.FromFrames(i), new OFXColor(Random.NextDouble(), Random.NextDouble(), Random.NextDouble())); + } + } + } + } + } + } + } +} diff --git a/Automator14.cs.config b/Automator14.cs.config new file mode 100644 index 0000000..2defaa6 --- /dev/null +++ b/Automator14.cs.config @@ -0,0 +1,7 @@ + + + System.dll + System.Core.dll + -debug -D:DEBUG + Automator.png + \ No newline at end of file diff --git a/Datamosh.cs b/Datamosh.cs index 4851a91..feed385 100644 --- a/Datamosh.cs +++ b/Datamosh.cs @@ -2,11 +2,11 @@ // quickly and automatically. // // Author: delthas -// Date: 2018-04-15 +// Date: 2018-11-29 // License: MIT // Source: https://github.com/delthas/vegas-datamosh // Documentation: https://github.com/delthas/vegas-datamosh -// Version: 1.2.1 +// Version: 1.3.0 // using System; diff --git a/Datamosh.png b/Datamosh.png index 9cbe23e..537b2d2 100644 Binary files a/Datamosh.png and b/Datamosh.png differ diff --git a/Datamosh14.cs b/Datamosh14.cs index 916aeb8..2f5fa0b 100644 --- a/Datamosh14.cs +++ b/Datamosh14.cs @@ -2,11 +2,11 @@ // quickly and automatically. // // Author: delthas -// Date: 2018-04-15 +// Date: 2018-11-29 // License: MIT // Source: https://github.com/delthas/vegas-datamosh // Documentation: https://github.com/delthas/vegas-datamosh -// Version: 1.2.1 +// Version: 1.3.0 // using System; diff --git a/Layer.cs b/Layer.cs index 0f0b388..1932039 100644 --- a/Layer.cs +++ b/Layer.cs @@ -2,11 +2,11 @@ // quickly and automatically. // // Author: delthas -// Date: 2018-04-15 +// Date: 2018-11-29 // License: MIT // Source: https://github.com/delthas/vegas-datamosh // Documentation: https://github.com/delthas/vegas-datamosh -// Version: 1.2.1 +// Version: 1.3.0 // using System; diff --git a/Layer.png b/Layer.png index 6c35475..83d5025 100644 Binary files a/Layer.png and b/Layer.png differ diff --git a/Layer14.cs b/Layer14.cs index e1f7d91..50ed359 100644 --- a/Layer14.cs +++ b/Layer14.cs @@ -2,11 +2,11 @@ // quickly and automatically. // // Author: delthas -// Date: 2018-04-15 +// Date: 2018-11-29 // License: MIT // Source: https://github.com/delthas/vegas-datamosh // Documentation: https://github.com/delthas/vegas-datamosh -// Version: 1.2.1 +// Version: 1.3.0 // using System; diff --git a/README.md b/README.md index f0a9269..d4f4f3a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # vegas-datamosh ![Github All Releases](https://img.shields.io/github/downloads/delthas/vegas-datamosh/total.svg?style=flat-square) **A pack of Sony/MAGIX Vegas Pro scripts for YTP (datamoshing, multilayering, ...), using FFmpeg and Avidemux** +## News +- **1.3.0**: Added Automator (randomizes video effects) + ## Setup Download the latest [release](../../releases/) **(the windows64.zip file)** and unpack it into your ```C:\Users\\Documents\Vegas Script Menu``` folder. (If the folder does not exist, create it.) @@ -46,6 +49,13 @@ To use, select several clips/events (they must be actually selected, not only in *Clips starting and ending at the same time will be scrambled together, ie their subclips will be shuffled the same way.* +### Automator +This randomizes the video effects of selected clips/events, by adding random keyframes every frame for each parameter type you select. + +To use, select several clips/events which have video effects on them (they must be actually selected, not only in group-selected), then start the script. For each type of video effect parameter on any of the clips, you will be prompted for whether you want the script to *scramble* the parameter (replace all the current keyframes of the parameter with random keyframes), or not (leave the keyframes as is). + +**Only *OFX* video effects are supported (newsprint, mirror, ...); they all have the same look, it's easy to identify which effects are OFX. Other effects are ignored.** + ## Tips *On most script window prompts, pressing ```enter``` confirms and pressing ```space``` toggles the checkbox (if present) so you don't even need to use your mouse most of the time.* diff --git a/Render.cs b/Render.cs index f06925f..7d7b8a0 100644 --- a/Render.cs +++ b/Render.cs @@ -2,11 +2,11 @@ // quickly and automatically. // // Author: delthas -// Date: 2018-04-15 +// Date: 2018-11-29 // License: MIT // Source: https://github.com/delthas/vegas-datamosh // Documentation: https://github.com/delthas/vegas-datamosh -// Version: 1.2.1 +// Version: 1.3.0 // using System; diff --git a/Render.png b/Render.png index 6a8f28f..9cff7da 100644 Binary files a/Render.png and b/Render.png differ diff --git a/Render14.cs b/Render14.cs index 47d408c..0830b14 100644 --- a/Render14.cs +++ b/Render14.cs @@ -2,11 +2,11 @@ // quickly and automatically. // // Author: delthas -// Date: 2018-04-15 +// Date: 2018-11-29 // License: MIT // Source: https://github.com/delthas/vegas-datamosh // Documentation: https://github.com/delthas/vegas-datamosh -// Version: 1.2.1 +// Version: 1.3.0 // using System; diff --git a/Scramble.cs b/Scramble.cs index 70b8df9..18004c8 100644 --- a/Scramble.cs +++ b/Scramble.cs @@ -2,11 +2,11 @@ // quickly and automatically. // // Author: delthas -// Date: 2018-04-15 +// Date: 2018-11-29 // License: MIT // Source: https://github.com/delthas/vegas-datamosh // Documentation: https://github.com/delthas/vegas-datamosh -// Version: 1.2.1 +// Version: 1.3.0 // using System; diff --git a/Scramble.png b/Scramble.png index d993ce5..fb83228 100644 Binary files a/Scramble.png and b/Scramble.png differ diff --git a/Scramble14.cs b/Scramble14.cs index f22a7dc..f8867a9 100644 --- a/Scramble14.cs +++ b/Scramble14.cs @@ -2,11 +2,11 @@ // quickly and automatically. // // Author: delthas -// Date: 2018-04-15 +// Date: 2018-11-29 // License: MIT // Source: https://github.com/delthas/vegas-datamosh // Documentation: https://github.com/delthas/vegas-datamosh -// Version: 1.2.1 +// Version: 1.3.0 // using System; diff --git a/_internal/avidemux_datamosh.js b/_internal/avidemux_datamosh.js index 155ccff..763d2ba 100644 --- a/_internal/avidemux_datamosh.js +++ b/_internal/avidemux_datamosh.js @@ -3,11 +3,11 @@ // quickly and automatically. // // Author: delthas -// Date: 2018-04-01 +// Date: 2018-11-29 // License: MIT // Source: https://github.com/delthas/vegas-datamosh // Documentation: https://github.com/delthas/vegas-datamosh -// Version: 1.0.0 +// Version: 1.3.0 // include("config_datamosh.js"); var app = new Avidemux();