Hi,
I'm trying to replicate one of the @jetdv script : "Remove Silent Areas from an Audio Track in VEGAS - Part 2" ( in order to modify it later in a video bass shake effect.
However i have an issue i located but i'm unable to fix it :
- The script works until it reach the first audio value and send the following error :
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at Test_Script.Class1.ProcessLog(String path)
at Test_Script.Class1.Main(Vegas vegas)
The faulty code line is this one : trackVolume = Convert.ToDouble(pieces[2]);
Look like the value is not converted correctly to double.
Is there a solution possible to this issue ?
My Vegas : Vegas version 21 (English)
Here is the entire code :
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Threading.Tasks; using System.Threading; using System.Windows.Forms; using System.Drawing; using System.Reflection; using System.Diagnostics; using System.Collections; using System.ComponentModel; using System.Runtime.InteropServices; using Microsoft.Win32; using ScriptPortal.Vegas; namespace Test_Script { public class Class1 { public Vegas myVegas; Renderer myRenderer = null; RenderTemplate rndrTemplate = null; public void Main(Vegas vegas) { myVegas = vegas; FindRenderers(); string tempFile = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + "temp.mp3"; string tempLog = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + "temp_loud.txt"; foreach (Track myTrack in myVegas.Project.Tracks) { if (myTrack.IsAudio()) { RenderTempFile(tempFile); ProcessLog(tempLog); } } } public void FindRenderers() { try { foreach (Renderer renderer in myVegas.Renderers) { if ("adfa6a4b-a99b-42e3-ae1f-081123ada04b" == renderer.ClassID.ToString()) { myRenderer = renderer; try { foreach (RenderTemplate renderTemplate in renderer.Templates) { if (renderTemplate.IsValid()) { if ("8ab64a16-81f5-46e6-8155-1611d592088c" == renderTemplate.TemplateGuid.ToString()) { rndrTemplate = renderTemplate; } } } } catch { } } } } catch { } } public void RenderTempFile(string tempFile) { RenderArgs args = new RenderArgs(); args.OutputFile = tempFile; args.RenderTemplate = rndrTemplate; args.Start = Timecode.FromFrames(0); args.Length = myVegas.Project.Length; args.IncludeMarkers = false; args.StretchToFill = false; args.GenerateLoudnessLog = true; RenderStatus status = myVegas.Render(args); } public void ProcessLog(string path) { Envelope compEnv = new Envelope(EnvelopeType.Composite); myVegas.Project.Tracks[0].Envelopes.Add(compEnv); compEnv.Points[0].Y = 0.0; var lines = File.ReadLines(path); bool foundfirst = false; foreach (string line in lines) { if (line.StartsWith("-------------")) { break; } if (line.StartsWith(" Pos.")) { foundfirst = true; } else { if (foundfirst) { if (line.Length > 5) { string[] pieces = line.Split('\t'); Timecode trackTime = Timecode.FromString(pieces[1]); double trackVolume = 0; if (pieces[2].Contains("Inf")) { trackVolume = -100; } else { trackVolume = Convert.ToDouble(pieces[2]); } EnvelopePoint volPoint = new EnvelopePoint(trackTime, 1.0 + (trackVolume / 100)); compEnv.Points.Add(volPoint); } } } } } } public class EntryPoint { public Vegas myVegas; public void FromVegas(Vegas vegas) { Test_Script.Class1 test = new Test_Script.Class1(); myVegas = vegas; test.Main(vegas); } } }