diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca5585f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/windows64.zip diff --git a/Automator.cs b/Automator.cs index 1cbd10b..1bdc863 100644 --- a/Automator.cs +++ b/Automator.cs @@ -1,12 +1,4 @@ -// 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 +// Sets random automation values for video effects quickly and automatically. // using System; @@ -74,7 +66,7 @@ public void FromVegas(Vegas vegas) { var renderChecked = (string) Registry.GetValue( "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", "Automate_" + hashed, ""); - var defaultCheck = renderChecked == "True"; + var defaultCheck = renderChecked != "False"; var prompt = new Form { Width = 300, diff --git a/Automator.png b/Automator.png index 1a21d09..74f0d64 100644 Binary files a/Automator.png and b/Automator.png differ diff --git a/Automator14.cs b/Automator14.cs deleted file mode 100644 index 03766d0..0000000 --- a/Automator14.cs +++ /dev/null @@ -1,217 +0,0 @@ -// MAGIX Vegas (>=14) 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 deleted file mode 100644 index 2defaa6..0000000 --- a/Automator14.cs.config +++ /dev/null @@ -1,7 +0,0 @@ - - - System.dll - System.Core.dll - -debug -D:DEBUG - Automator.png - \ No newline at end of file diff --git a/Datamosh14.cs b/Datamix.cs similarity index 63% rename from Datamosh14.cs rename to Datamix.cs index 2f5fa0b..d5cbee6 100644 --- a/Datamosh14.cs +++ b/Datamix.cs @@ -1,12 +1,4 @@ -// MAGIX Vegas (>=14) script to datamosh a part of a video -// 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 +// Datamoshes a part of a video quickly and automatically (mosh a clip onto another). // using System; @@ -16,9 +8,9 @@ using System.Windows.Forms; using Microsoft.Win32; using Microsoft.WindowsAPICodePack.Dialogs; -using ScriptPortal.Vegas; +using Sony.Vegas; -namespace VegasDatamosh { +namespace VegasDatamix { public class EntryPoint { private static readonly byte[] Array1 = { 0x42, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -121,10 +113,51 @@ private static RenderTemplate GetTemplate(Vegas vegas, int frameRate) { } } + private void Encode(Vegas vegas, string scriptDirectory, RenderArgs renderArgs, string pathEncoded) { + var status = vegas.Render(renderArgs); + if (status != RenderStatus.Complete) { + MessageBox.Show("Unexpected render status: " + status); + return; + } + + var encode = new Process { + StartInfo = { + UseShellExecute = false, + FileName = Path.Combine(scriptDirectory, "_internal", "ffmpeg", "ffmpeg.exe"), + WorkingDirectory = Path.Combine(scriptDirectory, "_internal"), + Arguments = "-y -hide_banner -nostdin -i \"" + renderArgs.OutputFile + + "\" -c:v libxvid -q:v 1 -g 1M -flags +mv4+qpel -mpeg_quant 1 -c:a copy \"" + pathEncoded + + "\"", + RedirectStandardOutput = true, + RedirectStandardError = true, + CreateNoWindow = true + } + }; + encode.Start(); + var output = encode.StandardOutput.ReadToEnd(); + var error = encode.StandardError.ReadToEnd(); + Debug.WriteLine(output); + Debug.WriteLine("---------------------"); + Debug.WriteLine(error); + encode.WaitForExit(); + + File.Delete(renderArgs.OutputFile); + File.Delete(renderArgs.OutputFile + ".sfl"); + } + public void FromVegas(Vegas vegas) { var start = vegas.Transport.LoopRegionStart; var length = vegas.Transport.LoopRegionLength; + if (start.FrameCount == 0) { + MessageBox.Show("Selection must start at frame >= 1!"); + return; + } + if (length.FrameCount <= 1) { + MessageBox.Show("Selection length must be > 1 frame!"); + return; + } + try { var frameRate = vegas.Project.Video.FrameRate; var frameRateInt = (int) Math.Round(frameRate * 1000); @@ -178,76 +211,6 @@ public void FromVegas(Vegas vegas) { "Render template generated for the current frame rate. Please restart Sony Vegas and run the script again."); return; } - - var frameCount = (string) Registry.GetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "FrameCount", ""); - var defaultCount = 1; - if (frameCount != "") { - try { - var value = int.Parse(frameCount); - if (value > 0) { - defaultCount = value; - } - } - catch (Exception) { - // ignore - } - } - - var prompt = new Form { - Width = 500, - Height = 140, - Text = "Datamoshing Parameters" - }; - var textLabel = new Label {Left = 10, Top = 10, Text = "Frame count"}; - var inputBox = - new NumericUpDown {Left = 200, Top = 10, Width = 200, Minimum = 1, Maximum = 1000000000, Value = defaultCount}; - var textLabel2 = new Label {Left = 10, Top = 40, Text = "Frames repeats"}; - var inputBox2 = new NumericUpDown { - Left = 200, - Top = 40, - Width = 200, - Value = 1, - Minimum = 1, - Maximum = 1000000000, - Text = "" - }; - var confirmation = new Button {Text = "OK", Left = 200, Width = 100, Top = 70}; - confirmation.Click += (sender, e) => { prompt.DialogResult = DialogResult.OK; prompt.Close(); }; - prompt.Controls.Add(confirmation); - prompt.Controls.Add(textLabel); - prompt.Controls.Add(inputBox); - prompt.Controls.Add(textLabel2); - prompt.Controls.Add(inputBox2); - inputBox2.Select(); - prompt.AcceptButton = confirmation; - if (prompt.ShowDialog() != DialogResult.OK) { - return; - } - var size = (int) inputBox.Value; - var repeat = (int) inputBox2.Value; - - if (repeat <= 0) { - MessageBox.Show("Frames repeats must be > 0!"); - return; - } - - if (length.FrameCount < size) { - MessageBox.Show("The selection must be as long as the frame count!"); - return; - } - - if (start.FrameCount < 1) { - MessageBox.Show("The selection mustn't start on the first frame of the project!"); - return; - } - - if (defaultCount != size) { - Registry.SetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "FrameCount", size.ToString(), RegistryValueKind.String); - } VideoTrack videoTrack = null; for (var i = vegas.Project.Tracks.Count - 1; i >= 0; i--) { @@ -257,16 +220,8 @@ public void FromVegas(Vegas vegas) { } } - AudioTrack audioTrack = null; - for (var i = 0; i < vegas.Project.Tracks.Count; i++) { - audioTrack = vegas.Project.Tracks[i] as AudioTrack; - if (audioTrack != null) { - break; - } - } - - if (videoTrack == null && audioTrack == null) { - MessageBox.Show("No tracks found!"); + if (videoTrack == null) { + MessageBox.Show("No track found!"); return; } @@ -300,71 +255,48 @@ public void FromVegas(Vegas vegas) { "ClipFolder", finalFolder, RegistryValueKind.String); } - var path = Path.Combine(vegas.TemporaryFilesPath, Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + - "-" + - Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + - ".avi"); - var pathEncoded = Path.Combine(vegas.TemporaryFilesPath, - Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + + var pathSrc = Path.Combine(vegas.TemporaryFilesPath, Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + ".avi"); - var pathDatamoshedBase = Path.Combine(finalFolder, + var pathEncodedSrc = Path.Combine(vegas.TemporaryFilesPath, Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + - Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8)); - var pathDatamoshed = pathDatamoshedBase + ".avi"; - var pathEncodedEscape = pathEncoded.Replace("\\", "/"); - var pathDatamoshedEscape = pathDatamoshed.Replace("\\", "/"); - - var renderArgs = new RenderArgs { - OutputFile = path, + Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + ".avi"); + Encode(vegas, scriptDirectory, new RenderArgs { + OutputFile = pathSrc, Start = Timecode.FromFrames(start.FrameCount - 1), - Length = Timecode.FromFrames(length.FrameCount + 1), + Length = Timecode.FromFrames(1), RenderTemplate = template - }; - var status = vegas.Render(renderArgs); - if (status != RenderStatus.Complete) { - MessageBox.Show("Unexpected render status: " + status); - return; - } - - string[] datamoshConfig = { - "var input=\"" + pathEncodedEscape + "\";", - "var output=\"" + pathDatamoshedEscape + "\";", - "var size=" + size + ";", - "var repeat=" + repeat + ";" - }; + }, pathEncodedSrc); + + var pathClip = Path.Combine(vegas.TemporaryFilesPath, Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + + Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + ".avi"); + var pathEncodedClip = Path.Combine(vegas.TemporaryFilesPath, + Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + + Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + ".avi"); + Encode(vegas, scriptDirectory, new RenderArgs { + OutputFile = pathClip, + Start = start, + Length = length, + RenderTemplate = template + }, pathEncodedClip); - File.WriteAllLines(Path.Combine(scriptDirectory, "_internal", "config_datamosh.js"), datamoshConfig); + var pathDatamixed = Path.Combine(finalFolder, + Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + + Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8)) + ".avi"; - var encode = new Process { - StartInfo = { - UseShellExecute = false, - FileName = Path.Combine(scriptDirectory, "_internal", "ffmpeg", "ffmpeg.exe"), - WorkingDirectory = Path.Combine(scriptDirectory, "_internal"), - Arguments = "-hide_banner -nostdin -i \"" + path + - "\" -c:v mpeg4 -vtag xvid -qscale:v 1 -bf 0 -g 600 -vtag xvid -c:a copy \"" + pathEncoded + - "\"", - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true - } + string[] datamoshConfig = { + "var input0=\"" + pathEncodedSrc.Replace("\\", "/") + "\";", + "var input1=\"" + pathEncodedClip.Replace("\\", "/") + "\";", + "var output=\"" + pathDatamixed.Replace("\\", "/") + "\";" }; - encode.Start(); - var output = encode.StandardOutput.ReadToEnd(); - var error = encode.StandardError.ReadToEnd(); - Debug.WriteLine(output); - Debug.WriteLine("---------------------"); - Debug.WriteLine(error); - encode.WaitForExit(); - File.Delete(path); - File.Delete(path + ".sfl"); + File.WriteAllLines(Path.Combine(scriptDirectory, "_internal", "config_datamix.js"), datamoshConfig); var datamosh = new Process { StartInfo = { UseShellExecute = false, FileName = Path.Combine(scriptDirectory, "_internal", "avidemux", "avidemux2_cli.exe"), WorkingDirectory = Path.Combine(scriptDirectory, "_internal"), - Arguments = "--nogui --run avidemux_datamosh.js", + Arguments = "--nogui --run avidemux_datamix.js", RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, @@ -373,39 +305,23 @@ public void FromVegas(Vegas vegas) { }; datamosh.Start(); datamosh.StandardInput.WriteLine("n"); - output = datamosh.StandardOutput.ReadToEnd(); - error = datamosh.StandardError.ReadToEnd(); + var output = datamosh.StandardOutput.ReadToEnd(); + var error = datamosh.StandardError.ReadToEnd(); Debug.WriteLine(output); Debug.WriteLine("---------------------"); Debug.WriteLine(error); datamosh.WaitForExit(); - File.Delete(pathEncoded); - File.Delete(pathEncoded + ".sfl"); + File.Delete(pathEncodedSrc); + File.Delete(pathEncodedSrc + ".sfl"); + File.Delete(pathEncodedClip); + File.Delete(pathEncodedClip + ".sfl"); - var media = vegas.Project.MediaPool.AddMedia(pathDatamoshed); + var media = vegas.Project.MediaPool.AddMedia(pathDatamixed); media.TimecodeIn = Timecode.FromFrames(1); - VideoEvent videoEvent = null; - if (videoTrack != null) { - videoEvent = - videoTrack.AddVideoEvent(start, Timecode.FromFrames(1 + length.FrameCount + (repeat - 1) * size)); - videoEvent.AddTake(media.GetVideoStreamByIndex(0)); - } - - AudioEvent audioEvent = null; - if (audioTrack != null) { - audioEvent = - audioTrack.AddAudioEvent(start, Timecode.FromFrames(1 + length.FrameCount + (repeat - 1) * size)); - audioEvent.AddTake(media.GetAudioStreamByIndex(0)); - } - - if (videoTrack != null && audioTrack != null) { - var group = new TrackEventGroup(); - vegas.Project.Groups.Add(group); - group.Add(videoEvent); - group.Add(audioEvent); - } + var videoEvent = videoTrack.AddVideoEvent(start, Timecode.FromFrames(length.FrameCount - 1)); + videoEvent.AddTake(media.GetVideoStreamByIndex(0)); } catch (Exception e) { MessageBox.Show("Unexpected exception: " + e.Message); @@ -413,4 +329,4 @@ public void FromVegas(Vegas vegas) { } } } -} \ No newline at end of file +} diff --git a/Layer14.cs.config b/Datamix.cs.config similarity index 93% rename from Layer14.cs.config rename to Datamix.cs.config index 87d1874..82badee 100644 --- a/Layer14.cs.config +++ b/Datamix.cs.config @@ -7,5 +7,5 @@ Microsoft.WindowsAPICodePack.Shell.dll Microsoft.WindowsAPICodePack.dll -debug -D:DEBUG - Layer.png + Datamix.png \ No newline at end of file diff --git a/Datamix.png b/Datamix.png new file mode 100644 index 0000000..e88d371 Binary files /dev/null and b/Datamix.png differ diff --git a/Datamosh.cs b/Datamosh.cs index feed385..c41a502 100644 --- a/Datamosh.cs +++ b/Datamosh.cs @@ -1,12 +1,4 @@ -// Sony Vegas (<=13) script to datamosh a part of a video -// 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 +// Datamoshes a part of a video quickly and automatically. // using System; @@ -340,8 +332,8 @@ public void FromVegas(Vegas vegas) { UseShellExecute = false, FileName = Path.Combine(scriptDirectory, "_internal", "ffmpeg", "ffmpeg.exe"), WorkingDirectory = Path.Combine(scriptDirectory, "_internal"), - Arguments = "-hide_banner -nostdin -i \"" + path + - "\" -c:v mpeg4 -vtag xvid -qscale:v 1 -bf 0 -g 600 -vtag xvid -c:a copy \"" + pathEncoded + + Arguments = "-y -hide_banner -nostdin -i \"" + path + + "\" -c:v libxvid -q:v 1 -g 1M -flags +mv4+qpel -mpeg_quant 1 -c:a copy \"" + pathEncoded + "\"", RedirectStandardOutput = true, RedirectStandardError = true, diff --git a/Datamosh.png b/Datamosh.png index 537b2d2..9cbe23e 100644 Binary files a/Datamosh.png and b/Datamosh.png differ diff --git a/Datamosh14.cs.config b/Datamosh14.cs.config deleted file mode 100644 index fbd7c0f..0000000 --- a/Datamosh14.cs.config +++ /dev/null @@ -1,11 +0,0 @@ - - - System.dll - System.Core.dll - System.Data.dll - System.Xml.dll - Microsoft.WindowsAPICodePack.Shell.dll - Microsoft.WindowsAPICodePack.dll - -debug -D:DEBUG - Datamosh.png - \ No newline at end of file diff --git a/Layer.cs b/Layer.cs index 1932039..9535274 100644 --- a/Layer.cs +++ b/Layer.cs @@ -1,12 +1,4 @@ -// Sony Vegas (<=13) script to do multilayering on a part of a video -// 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 +// Does multilayering on a part of a video quickly and automatically. // using System; diff --git a/Layer.png b/Layer.png index 83d5025..6c35475 100644 Binary files a/Layer.png and b/Layer.png differ diff --git a/Layer14.cs b/Layer14.cs deleted file mode 100644 index 50ed359..0000000 --- a/Layer14.cs +++ /dev/null @@ -1,355 +0,0 @@ -// MAGIX Vegas (>=14) script to do multilayering on a part of a video -// 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.Diagnostics; -using System.IO; -using System.Windows.Forms; -using System.Windows.Forms.VisualStyles; -using Microsoft.Win32; -using Microsoft.WindowsAPICodePack.Dialogs; -using ScriptPortal.Vegas; - -namespace VegasLayering { - public class EntryPoint { - private static readonly byte[] Array1 = { - 0x42, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0x28, 0x9d, 0xea, 0x5a, 0xc8, 0xd3, 0x11, 0xbb, 0x3a, 0x00, 0x50, 0xda, 0x1a, - 0x5b, 0x06 - }; - - private static readonly byte[] Array2 = { - 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, - 0x00, 0x11, 0x00, 0x00, 0x00, 0x80, 0xbb, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xee, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x28, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - private static readonly byte[] Array3 = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x44, - 0x49, 0x42, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, - 0x00, 0x6e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x70, 0x00, 0x72, 0x00, 0x41, 0x00, 0x6c, 0x00, 0x70, 0x00, - 0x68, 0x00, 0x61, 0x00, 0x20, 0x00 - }; - - private static readonly byte[] Array4 = {0x00, 0x00, 0x00, 0x00}; - - private static void GetStandardTemplates(Vegas vegas) { - GetTemplate(vegas, 12000); - GetTemplate(vegas, 12500); - GetTemplate(vegas, 14000); - GetTemplate(vegas, 14985); - GetTemplate(vegas, 15000); - GetTemplate(vegas, 16000); - GetTemplate(vegas, 23976); - GetTemplate(vegas, 24000); - GetTemplate(vegas, 25000); - GetTemplate(vegas, 29970); - GetTemplate(vegas, 30000); - GetTemplate(vegas, 50000); - GetTemplate(vegas, 59940); - GetTemplate(vegas, 60000); - } - - private static RenderTemplate GetTemplate(Vegas vegas, int frameRate) { - if (frameRate >= 100 * 1000) { - throw new ArgumentException("Frame rate must be < 100!"); - } - - var frameString = (frameRate / 1000).ToString("00") + "." + (frameRate % 1000).ToString("000"); - var name = "UncomprAlpha " + frameString; - var template = vegas.Renderers.FindByRendererID(0).Templates - .FindByName(name); - if (template != null) { - return template; - } - - var appData = Environment.GetEnvironmentVariable("APPDATA"); - if (appData == null) { - throw new IOException("APPDATA not set!"); - } - - var folder = Path.Combine(appData, "Sony", "Render Templates", "avi"); - Directory.CreateDirectory(folder); - var file = Path.Combine(folder, name + ".sft2"); - if (File.Exists(file)) { - return null; - } - - using (var writer = new BinaryWriter(new FileStream(file, FileMode.Create, FileAccess.Write))) { - writer.Write(Array1, 0, Array1.Length); - var guid = Guid.NewGuid().ToByteArray(); - writer.Write(guid, 0, guid.Length); - writer.Write(Array2, 0, Array2.Length); - writer.Write((double) frameRate / 1000); - writer.Write(Array3, 0, Array3.Length); - var chars = frameString.ToCharArray(); - foreach (var ch in chars) { - writer.Write((byte) ch); - writer.Write((byte) 0x00); - } - - writer.Write(Array4, 0, Array4.Length); - return null; - } - } - - public void FromVegas(Vegas vegas) { - var videoTrackIndex = -1; - VideoTrack videoTrackStart = null; - VideoEvent videoEvent = null; - for (var i = 0; i < vegas.Project.Tracks.Count; i++) { - var track = vegas.Project.Tracks[i]; - if (!track.IsVideo()) - continue; - foreach (var trackEvent in track.Events) { - if (!trackEvent.Selected) continue; - if (videoEvent != null) { - MessageBox.Show("Only a single video event can be selected!"); - return; - } - - videoTrackIndex = i; - videoTrackStart = (VideoTrack) track; - videoEvent = (VideoEvent) trackEvent; - } - } - - if (videoEvent == null) { - MessageBox.Show("Select a video event to be layered!"); - return; - } - - try { - var frameRate = vegas.Project.Video.FrameRate; - var frameRateInt = (int) Math.Round(frameRate * 1000); - - var scriptDirectory = Path.GetDirectoryName(Script.File); - if (scriptDirectory == null) { - MessageBox.Show("Couldn't get script directory path!"); - return; - } - - var template = GetTemplate(vegas, frameRateInt); - if (template == null) { - GetStandardTemplates(vegas); - GetTemplate(vegas, frameRateInt); - MessageBox.Show( - "Render template generated for the current frame rate. Please restart Sony Vegas and run the script again."); - return; - } - - var layeringCount = (string) Registry.GetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "LayerCount", ""); - var defaultCount = 1; - if (layeringCount != "") { - try { - var value = int.Parse(layeringCount); - if (value > 0) { - defaultCount = value; - } - } - catch (Exception) { - // ignore - } - } - - var renderChecked = (string) Registry.GetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "RenderLayer", ""); - var defaultCheck = renderChecked == "True"; - var prompt = new Form { - Width = 500, - Height = 170, - Text = "Layering Parameters", - KeyPreview = true - }; - var textLabel = new Label {Left = 10, Top = 10, Text = "Layer count"}; - var inputBox = new NumericUpDown { - Left = 200, - Top = 10, - Width = 200, - Minimum = 1, - Maximum = 1000000000, - Value = defaultCount - }; - var textLabel2 = new Label {Left = 10, Top = 40, Text = "Layering offset"}; - var inputBox2 = - new NumericUpDown {Left = 200, Top = 40, Width = 200, Minimum = -1000000000, Maximum = 1000000000, Text = ""}; - var textLabel3 = new Label {Left = 10, Top = 70, Text = "Render"}; - var inputBox3 = new CheckBox { - Left = 200, - Top = 70, - Width = 200, - Checked = defaultCheck - }; - var confirmation = new Button {Text = "OK", Left = 200, Width = 100, Top = 100}; - confirmation.Click += (sender, e) => { prompt.DialogResult = DialogResult.OK; prompt.Close(); }; - prompt.KeyPress += (sender, args) => { - if (args.KeyChar != ' ') return; - inputBox3.Checked = !inputBox3.Checked; - args.Handled = true; - }; - prompt.Controls.Add(confirmation); - prompt.Controls.Add(textLabel); - prompt.Controls.Add(inputBox); - prompt.Controls.Add(textLabel2); - prompt.Controls.Add(inputBox2); - prompt.Controls.Add(textLabel3); - prompt.Controls.Add(inputBox3); - inputBox2.Select(); - prompt.AcceptButton = confirmation; - if (prompt.ShowDialog() != DialogResult.OK) { - return; - } - var count = (int) inputBox.Value; - var offset = (int) inputBox2.Value; - var render = inputBox3.Checked; - - if (offset == 0) { - MessageBox.Show("Layering offset must not be 0!"); - return; - } - - if (count <= 0) { - MessageBox.Show("Layer count must be > 0!"); - return; - } - - if (defaultCount != count) { - Registry.SetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "LayerCount", count.ToString(), RegistryValueKind.String); - } - if (defaultCheck != render) { - Registry.SetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "RenderLayer", render.ToString(), RegistryValueKind.String); - } - - var newTracks = new List(); - var newEvents = new List(); - var current = 0; - var baseOffset = offset > 0 ? 0 : -count * offset; - - for (var i = videoTrackIndex - 1; i >= 0 && current < count; i--) { - var videoTrack = vegas.Project.Tracks[i] as VideoTrack; - if (videoTrack == null) continue; - newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + baseOffset + (++current) * offset))); - } - - for (; current < count;) { - var videoTrack = vegas.Project.AddVideoTrack(); - newTracks.Add(videoTrack); - newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + baseOffset + (++current) * offset))); - } - - var start = videoEvent.Start; - if (offset < 0) { - videoEvent.Start = Timecode.FromFrames(videoEvent.Start.FrameCount + baseOffset); - } - - if (!render) return; - var changed = false; - var finalFolder = (string) Registry.GetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "LayerClipFolder", ""); - while (string.IsNullOrEmpty(finalFolder) || !Directory.Exists(finalFolder)) { - MessageBox.Show("Select the folder to put generated layered clips into.\n" + - "(As they are stored uncompressed with alpha, they can take a lot of space (think 1 GB/minute). " + - "Choose a location with a lot of available space and go remove some clips there if you need space.)"); - changed = true; - var dialog = new CommonOpenFileDialog { - IsFolderPicker = true, - EnsurePathExists = true, - EnsureFileExists = false, - AllowNonFileSystemItems = false, - DefaultFileName = "Select Folder", - Title = "Select the folder to put generated layered clips into" - }; - - if (dialog.ShowDialog() != CommonFileDialogResult.Ok) { - MessageBox.Show("No folder selected"); - return; - } - finalFolder = dialog.FileName; - } - - if (changed) { - Registry.SetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "LayerClipFolder", finalFolder, RegistryValueKind.String); - } - - var path = Path.Combine(vegas.TemporaryFilesPath, Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + - "-" + - Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + - ".avi"); - var pathEncoded = Path.Combine(vegas.TemporaryFilesPath, - Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + - Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + ".avi"); - - var renderArgs = new RenderArgs { - OutputFile = path, - Start = Timecode.FromFrames(start.FrameCount), - Length = Timecode.FromFrames(videoEvent.Length.FrameCount + count * Math.Abs(offset)), - RenderTemplate = template - }; - var status = vegas.Render(renderArgs); - if (status != RenderStatus.Complete) { - MessageBox.Show("Unexpected render status: " + status); - return; - } - - File.Delete(pathEncoded + ".sfl"); - - var media = vegas.Project.MediaPool.AddMedia(path); - var newVideoEvent = videoTrackStart.AddVideoEvent(start, - Timecode.FromFrames(videoEvent.Length.FrameCount + count * Math.Abs(offset))); - ((VideoStream) newVideoEvent.AddTake(media.GetVideoStreamByIndex(0)).MediaStream).AlphaChannel = - VideoAlphaType.Straight; - videoEvent.Track.Events.Remove(videoEvent); - - foreach (var newEvent in newEvents) { - newEvent.Track.Events.Remove(newEvent); - } - foreach (var newTrack in newTracks) { - vegas.Project.Tracks.Remove(newTrack); - } - } - catch (Exception e) { - MessageBox.Show("Unexpected exception: " + e.Message); - Debug.WriteLine(e); - } - } - } -} \ No newline at end of file diff --git a/README.md b/README.md index d4f4f3a..d6cc771 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ **A pack of Sony/MAGIX Vegas Pro scripts for YTP (datamoshing, multilayering, ...), using FFmpeg and Avidemux** ## News +- **1.4.0**: Added Datamix (datamosh: apply a clip P-frames on another clip I-frame) - **1.3.0**: Added Automator (randomizes video effects) ## Setup @@ -24,7 +25,18 @@ To use, make a selection in the timeline using I and O, then it will be rendered The start of the selection is the first P-frame that will be repeated. The P-frame will be relative to the previous frame, which will be rendered as an I-frame. So for best results, the start of the selection should be a frame with a lot of movement. -The end of the selection simply tells the script until which frame it should rendered the datamoshed file. The longer the selection, the longer the render time. +The end of the selection simply tells the script until which frame it should render the datamoshed file. The longer the selection, the longer the render time. + +### Datamix +This replaces the first I-frames of a clip by a frame of another clip. + +To use, make a selection in the timeline using I and O, then it will be rendered and datamixed and added to your project, all in one click. It can take quite some time for long selections so wait if Vegas seems to freeze. + +The start of the selection is the I-frame of the clip that will be replaced by another I-frame. *The image used for the new I-frame will be the frame just before the start of the selection.* So make sure to place the image you want to datamix from, just before the selection start. + +If you want to datamix on a scene change, you can typically split the clip at the exact frame where the scene changes, and select the right clip. This will datamix the right-hand side clip onto the last frame of the left-hand side clip. + +The end of the selection simply tells the script until which frame it should render the datamoshed file. The longer the selection, the longer the render time. ### Layer This does multilayering, by copying the select video clip/event N times, each time offsetting the clip by M frames. N is the ```Layer count```, M is the ```Layering offset```. You can also choose to automatically render the multilayered clip by checking the ```Render``` hitbox, otherwise the copies clips will simply be added to the timeline. diff --git a/Render.cs b/Render.cs index 7d7b8a0..94d192b 100644 --- a/Render.cs +++ b/Render.cs @@ -1,12 +1,4 @@ -// Sony Vegas (<=13) script to render a part of a video -// 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 +// Renders a part of a video quickly and automatically. // using System; diff --git a/Render.png b/Render.png index 9cff7da..6a8f28f 100644 Binary files a/Render.png and b/Render.png differ diff --git a/Render14.cs b/Render14.cs deleted file mode 100644 index 0830b14..0000000 --- a/Render14.cs +++ /dev/null @@ -1,252 +0,0 @@ -// MAGIX Vegas (>=14) script to render a part of a video -// 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.Diagnostics; -using System.IO; -using System.Windows.Forms; -using Microsoft.Win32; -using Microsoft.WindowsAPICodePack.Dialogs; -using ScriptPortal.Vegas; - -namespace VegasRender { - public class EntryPoint { - private static readonly byte[] Array1 = { - 0x42, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0x28, 0x9d, 0xea, 0x5a, 0xc8, 0xd3, 0x11, 0xbb, 0x3a, 0x00, 0x50, 0xda, 0x1a, - 0x5b, 0x06 - }; - - private static readonly byte[] Array2 = { - 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, - 0x00, 0x11, 0x00, 0x00, 0x00, 0x80, 0xbb, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xee, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x28, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - private static readonly byte[] Array3 = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x44, - 0x49, 0x42, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, - 0x00, 0x6e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x70, 0x00, 0x72, 0x00, 0x41, 0x00, 0x6c, 0x00, 0x70, 0x00, - 0x68, 0x00, 0x61, 0x00, 0x20, 0x00 - }; - - private static readonly byte[] Array4 = {0x00, 0x00, 0x00, 0x00}; - - private static void GetStandardTemplates(Vegas vegas) { - GetTemplate(vegas, 12000); - GetTemplate(vegas, 12500); - GetTemplate(vegas, 14000); - GetTemplate(vegas, 14985); - GetTemplate(vegas, 15000); - GetTemplate(vegas, 16000); - GetTemplate(vegas, 23976); - GetTemplate(vegas, 24000); - GetTemplate(vegas, 25000); - GetTemplate(vegas, 29970); - GetTemplate(vegas, 30000); - GetTemplate(vegas, 50000); - GetTemplate(vegas, 59940); - GetTemplate(vegas, 60000); - } - - private static RenderTemplate GetTemplate(Vegas vegas, int frameRate) { - if (frameRate >= 100 * 1000) { - throw new ArgumentException("Frame rate must be < 100!"); - } - - var frameString = (frameRate / 1000).ToString("00") + "." + (frameRate % 1000).ToString("000"); - var name = "UncomprAlpha " + frameString; - var template = vegas.Renderers.FindByRendererID(0).Templates - .FindByName(name); - if (template != null) { - return template; - } - - var appData = Environment.GetEnvironmentVariable("APPDATA"); - if (appData == null) { - throw new IOException("APPDATA not set!"); - } - - var folder = Path.Combine(appData, "Sony", "Render Templates", "avi"); - Directory.CreateDirectory(folder); - var file = Path.Combine(folder, name + ".sft2"); - if (File.Exists(file)) { - return null; - } - - using (var writer = new BinaryWriter(new FileStream(file, FileMode.Create, FileAccess.Write))) { - writer.Write(Array1, 0, Array1.Length); - var guid = Guid.NewGuid().ToByteArray(); - writer.Write(guid, 0, guid.Length); - writer.Write(Array2, 0, Array2.Length); - writer.Write((double) frameRate / 1000); - writer.Write(Array3, 0, Array3.Length); - var chars = frameString.ToCharArray(); - foreach (var ch in chars) { - writer.Write((byte) ch); - writer.Write((byte) 0x00); - } - - writer.Write(Array4, 0, Array4.Length); - return null; - } - } - - public void FromVegas(Vegas vegas) { - var start = vegas.Transport.LoopRegionStart; - var length = vegas.Transport.LoopRegionLength; - - try { - var frameRate = vegas.Project.Video.FrameRate; - var frameRateInt = (int) Math.Round(frameRate * 1000); - - var scriptDirectory = Path.GetDirectoryName(Script.File); - if (scriptDirectory == null) { - MessageBox.Show("Couldn't get script directory path!"); - return; - } - - var template = GetTemplate(vegas, frameRateInt); - if (template == null) { - GetStandardTemplates(vegas); - GetTemplate(vegas, frameRateInt); - MessageBox.Show( - "Render template generated for the current frame rate. Please restart Sony Vegas and run the script again."); - return; - } - - VideoTrack videoTrack = null; - for (var i = vegas.Project.Tracks.Count - 1; i >= 0; i--) { - videoTrack = vegas.Project.Tracks[i] as VideoTrack; - if (videoTrack != null) { - break; - } - } - - AudioTrack audioTrack = null; - for (var i = 0; i < vegas.Project.Tracks.Count; i++) { - audioTrack = vegas.Project.Tracks[i] as AudioTrack; - if (audioTrack != null) { - break; - } - } - - if (videoTrack == null && audioTrack == null) { - MessageBox.Show("No tracks found!"); - return; - } - - var changed = false; - var finalFolder = (string) Registry.GetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "RenderClipFolder", ""); - while (string.IsNullOrEmpty(finalFolder) || !Directory.Exists(finalFolder)) { - MessageBox.Show("Select the folder to put generated rendered clips into.\n" + - "(As they are stored uncompressed with alpha, they can take a lot of space (think 1 GB/minute). " + - "Choose a location with a lot of available space and go remove some clips there if you need space.)"); - changed = true; - var dialog = new CommonOpenFileDialog { - IsFolderPicker = true, - EnsurePathExists = true, - EnsureFileExists = false, - AllowNonFileSystemItems = false, - DefaultFileName = "Select Folder", - Title = "Select the folder to put generated rendered clips into" - }; - - if (dialog.ShowDialog() != CommonFileDialogResult.Ok) { - MessageBox.Show("No folder selected"); - return; - } - finalFolder = dialog.FileName; - } - - if (changed) { - Registry.SetValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", - "RenderClipFolder", finalFolder, RegistryValueKind.String); - } - - var path = Path.Combine(vegas.TemporaryFilesPath, Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + - "-" + - Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + - ".avi"); - var pathEncoded = Path.Combine(vegas.TemporaryFilesPath, - Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + - Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + ".avi"); - - var renderArgs = new RenderArgs { - OutputFile = path, - Start = Timecode.FromFrames(start.FrameCount), - Length = Timecode.FromFrames(length.FrameCount), - RenderTemplate = template - }; - var status = vegas.Render(renderArgs); - if (status != RenderStatus.Complete) { - MessageBox.Show("Unexpected render status: " + status); - return; - } - - File.Delete(pathEncoded + ".sfl"); - - var media = vegas.Project.MediaPool.AddMedia(path); - - VideoEvent videoEvent = null; - if (videoTrack != null) { - videoEvent = - videoTrack.AddVideoEvent(start, length); - ((VideoStream) videoEvent.AddTake(media.GetVideoStreamByIndex(0)).MediaStream).AlphaChannel = - VideoAlphaType.Straight; - } - - AudioEvent audioEvent = null; - if (audioTrack != null) { - audioEvent = - audioTrack.AddAudioEvent(start, length); - audioEvent.AddTake(media.GetAudioStreamByIndex(0)); - } - - if (videoTrack != null && audioTrack != null) { - var group = new TrackEventGroup(); - vegas.Project.Groups.Add(group); - group.Add(videoEvent); - group.Add(audioEvent); - } - - } - catch (Exception e) { - MessageBox.Show("Unexpected exception: " + e.Message); - Debug.WriteLine(e); - } - } - } -} \ No newline at end of file diff --git a/Render14.cs.config b/Render14.cs.config deleted file mode 100644 index cab7a5b..0000000 --- a/Render14.cs.config +++ /dev/null @@ -1,11 +0,0 @@ - - - System.dll - System.Core.dll - System.Data.dll - System.Xml.dll - Microsoft.WindowsAPICodePack.Shell.dll - Microsoft.WindowsAPICodePack.dll - -debug -D:DEBUG - Render.png - \ No newline at end of file diff --git a/Scramble.cs b/Scramble.cs index 18004c8..3a6a61d 100644 --- a/Scramble.cs +++ b/Scramble.cs @@ -1,12 +1,4 @@ -// Sony Vegas (<=13) script to scramble clips/events -// 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 +// Scrambles clips/events quickly and automatically. // using System; diff --git a/Scramble.png b/Scramble.png index fb83228..d993ce5 100644 Binary files a/Scramble.png and b/Scramble.png differ diff --git a/Scramble14.cs b/Scramble14.cs deleted file mode 100644 index f8867a9..0000000 --- a/Scramble14.cs +++ /dev/null @@ -1,111 +0,0 @@ -// MAGIX Vegas (>=14) script to scramble clips/events -// 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.Diagnostics; -using System.Linq; -using System.Windows.Forms; -using ScriptPortal.Vegas; - -namespace VegasScramble { - 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) - .GroupBy( - t => new { - StartFrameCount = t.Start.FrameCount, - LengthFrameCount = t.Length.FrameCount - }) - .Select(grp => grp.ToList()) - .ToList(); - - var prompt = new Form { - Width = 500, - Height = 110, - Text = "Scrambling Parameters" - }; - var textLabel = new Label {Left = 10, Top = 10, Text = "Scramble size"}; - var inputBox = new NumericUpDown { - Left = 200, - Top = 10, - Width = 200, - Minimum = 1, - Maximum = 1000000000, - Text = "" - }; - var confirmation = new Button {Text = "OK", Left = 200, Width = 100, Top = 40}; - confirmation.Click += (sender, e) => { - prompt.DialogResult = DialogResult.OK; - prompt.Close(); - }; - prompt.Controls.Add(confirmation); - prompt.Controls.Add(textLabel); - prompt.Controls.Add(inputBox); - inputBox.Select(); - prompt.AcceptButton = confirmation; - if (prompt.ShowDialog() != DialogResult.OK) { - return; - } - - var size = (int) inputBox.Value; - - if (size <= 0) { - MessageBox.Show("Scrambling size must be > 0!"); - return; - } - - try { - foreach (var e in events) { - var order = new List(); - var startFrameCount = e[0].Start.FrameCount; - var endFrameCount = e[0].End.FrameCount; - var n = (int) (endFrameCount - startFrameCount); - var l = n / size; - if(l == 0) continue; - if (n % size != 0) { - ++l; - } - for (var i = 0; i < l; i++) { - order.Add(i); - } - - - for (var i = 0; i < l - 1; i++) { - var k = i + 1 + Random.Next(l - i - 1); - var v = order[k]; - order[k] = order[i]; - order[i] = v; - } - - foreach (var evt in e) { - int offset; - for (var i = l - 1; i > 0; i--) { - var other = evt.Split(Timecode.FromFrames(i * size)); - offset = order[i] > order[l - 1] ? -(size - n % size) : 0; - other.Start = Timecode.FromFrames(startFrameCount + offset + order[i] * size); - } - offset = order[0] > order[l - 1] ? -(size - n % size) : 0; - evt.Start = Timecode.FromFrames(startFrameCount + offset + order[0] * size); - } - } - } - catch (Exception e) { - MessageBox.Show("Unexpected exception: " + e.Message); - Debug.WriteLine(e); - } - } - } -} \ No newline at end of file diff --git a/Scramble14.cs.config b/Scramble14.cs.config deleted file mode 100644 index e9fffa8..0000000 --- a/Scramble14.cs.config +++ /dev/null @@ -1,7 +0,0 @@ - - - System.dll - System.Core.dll - -debug -D:DEBUG - Scramble.png - \ No newline at end of file diff --git a/_internal/avidemux_datamix.js b/_internal/avidemux_datamix.js new file mode 100644 index 0000000..87f62e4 --- /dev/null +++ b/_internal/avidemux_datamix.js @@ -0,0 +1,26 @@ +//AD +// Datamosh a part of a video quickly and automatically (mosh a clip onto another). +// + +include("config_datamix.js"); +var app = new Avidemux(); +app.load(input1); +var len = app.markerB+1; +app.append(input0); +app.clearSegments(); +app.addSegment(1,0,1); +app.addSegment(0,1,len-1); + +app.markerA=0; +app.markerB=len-1; + +app.setContainer("AVI"); +app.video.codec("copy","CQ=4",""); + +app.audio.normalizeMode=0; +app.audio.normalizeValue=0; +app.audio.delay=0; +app.audio.mixer="NONE"; +app.setContainer("AVI"); +app.save(output); +app.exit(); diff --git a/_internal/avidemux_datamosh.js b/_internal/avidemux_datamosh.js index 763d2ba..23af7f4 100644 --- a/_internal/avidemux_datamosh.js +++ b/_internal/avidemux_datamosh.js @@ -1,14 +1,7 @@ //AD -// Avidemux script to datamosh a part of a video -// 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 +// Datamoshes a part of a video quickly and automatically. // + include("config_datamosh.js"); var app = new Avidemux(); app.load(input); diff --git a/scripts/make_release.sh b/scripts/make_release.sh new file mode 100644 index 0000000..9c2ef1e --- /dev/null +++ b/scripts/make_release.sh @@ -0,0 +1,43 @@ +#!/bin/sh -eu + +if [ $# -ne 2 ]; then + echo $# + echo "$0: syntax: " >&2 + exit 1 +fi + +rm -fr tmp/ +mkdir tmp/ + +header="// Author: delthas +// Date: $(date +%F) +// License: MIT +// Source: https://github.com/delthas/vegas-datamosh +// Documentation: https://github.com/delthas/vegas-datamosh +// Version: $1 +// +" + +for f in *.cs; do + echo -n "$header" | cat - "$f" > "tmp/$f" + sed -r 's/using Sony\.Vegas/using ScriptPortal\.Vegas/g' "tmp/$f" > "tmp/${f%.*}14.cs" + cp "$f.config" "tmp/$f.config" + cp "$f.config" "tmp/${f%.*}14.cs.config" +done + +cp LICENSE README.md *.png tmp/ +cp -R "$2" tmp/_internal/ + +for f in _internal/*.js; do + tail -n +2 "$f" > "tmp/$f.tmp" + echo -en "//AD\n$header" | cat - "tmp/$f.tmp" > "tmp/$f" + rm "tmp/$f.tmp" +done + +rm windows64.zip +cd tmp +zip -qr9 ../windows64.zip * +cd .. +rm -fr tmp/ + +echo "release $1 created successfully: windows64.zip"