Hi,
So i resumed my work on my "Audio Volume to Video Scale" script, and it's almost working perfectly.
In short, the script analyses the audio master of the project, generate a log file (temp_loud.txt) and the data inside it are used to create keyframe on a picture-in-picture effect on a selected event on the timeline.
(on the screenshot there are the double amount of keyframe) ((a bug))
The only issue is the maximum amount of keyframe i can generate with the script.
Even with the better audio quality, the log file has roughly 20 samples per seconds in it, which is not enough.
@jetdv I would like to know if there is a way to generate an audio log file with an amount of sample that match the video framerate of the project (60fps), so i can generate one keyframe for each frame of the video.
Here's the code of the script
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; private double x1 = 0.00; private double x2 = 0.00; private double x3 = 0.00; private double y1 = 0.00; private double y2 = 0.00; private double y3 = 0.00; private static OFXInterpolationType ParseOFXCurveType(String val) { switch (val) { case "Sharp": return OFXInterpolationType.Sharp; case "Slow": return OFXInterpolationType.Slow; case "Linear": return OFXInterpolationType.Linear; case "Fast": return OFXInterpolationType.Fast; case "Smooth": return OFXInterpolationType.Smooth; case "Hold": return OFXInterpolationType.Hold; case "Manual": return OFXInterpolationType.Manual; case "Split": return OFXInterpolationType.Split; default: throw new ApplicationException("Unknown CurveType: " + val); } } public void Main(Vegas vegas) { myVegas = vegas; FindRenderers(); string tempFile = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + "temp.wav"; string tempLog = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + "temp_loud.txt"; //Apply Effects on Selected Events foreach (Track track in myVegas.Project.Tracks) { foreach (TrackEvent evnt in track.Events) { if (evnt.Selected && evnt.IsVideo()) { RenderTempFile(tempFile); PlugInNode trans = myVegas.Transitions; } } foreach (TrackEvent trackEvent in track.Events) { // Picture-In-Picture if (trackEvent.Selected && trackEvent.IsVideo()) { ProcessLog(tempLog); } } } } public void FindRenderers() { try { foreach (Renderer renderer in myVegas.Renderers) { if ("3cbba9c1-75ad-11d3-a483-00105a24aa37" == renderer.ClassID.ToString()) { myRenderer = renderer; try { foreach (RenderTemplate renderTemplate in renderer.Templates) { if (renderTemplate.IsValid()) { if ("ad7a39c3-2773-3acf-9607-ca751c73e938" == 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(1); args.Length = myVegas.Project.Length; args.IncludeMarkers = false; args.StretchToFill = false; args.GenerateLoudnessLog = true; RenderStatus status = myVegas.Render(args); } public void ProcessLog(string path) { var lines = File.ReadLines(path); bool foundfirst = false; string fxPictureUID = "{Svfx:com.vegascreativesoftware:pictureinpicture}"; string fxDeformationUID = "{Svfx:com.genarts.sapphire.Distort.S_WarpTransform}"; //Apply Picture-In-Picture on Selected Events between Cookie Cutter & Layer Dimensionality foreach (Track track in myVegas.Project.Tracks) { foreach (TrackEvent trackEvent in track.Events) { //Determine The First and Last Keyframe of each Events Timecode startFrame = trackEvent.Start; Timecode endFrame = trackEvent.End; // Picture-In-Picture if (trackEvent.Selected && trackEvent.IsVideo()) { VideoEvent videoEventDeformation = (VideoEvent)trackEvent; VideoEvent videoEventPicture = (VideoEvent)trackEvent; PlugInNode fxList = myVegas.VideoFX; PlugInNode fxChildPicture = fxList.GetChildByUniqueID(fxPictureUID); PlugInNode fxChildDeformation = fxList.GetChildByUniqueID(fxDeformationUID); Effect effectPicture = new Effect(fxChildPicture); Effect effectDeformation = new Effect(fxChildDeformation); videoEventPicture.Effects.Add(effectPicture); videoEventDeformation.Effects.Add(effectDeformation); if (effectPicture.PlugIn.IsOFX && effectDeformation.PlugIn.IsOFX) { OFXEffect ofxpicture = effectPicture.OFXEffect; OFXEffect ofxdeformation = effectDeformation.OFXEffect; //DEFORM : Setup Y_Scale //PICTURE : Setup Scale of Picture foreach (string line in lines) { if (line.StartsWith("-------------")) { break; } if (line.StartsWith(" Pos.")) { foundfirst = true; } else { if (foundfirst) { if (line.Length > 5) { string a = line.Replace("\t" , "A"); string b = a.Replace("AA" , "A"); string c = b.Replace("-",""); string[] pieces = b.Split('A'); double trackVolume = 0; Timecode trackTime = Timecode.FromString(pieces[1]); if (pieces[2].Contains("Inf")) { trackVolume = -10.00; } else { trackVolume = Convert.ToDouble(pieces[2]); } if (trackVolume < -10.00) { x1 = 1.0 + (trackVolume / 140); //x2 = 1.0 + (trackVolume / 150); //x3 = 1.0 + (trackVolume / 130); y1 = 1.0 + (trackVolume / 1000); //y2 = 1.0 + (trackVolume / 1000); //y3 = 1.0 + (trackVolume / 1000); } else { x1 = 1.0 + (trackVolume / 140); //x2 = 1.0 + (trackVolume / 150); //x3 = 1.0 + (trackVolume / 130); y1 = 1.0 + (trackVolume / 1000); //y2 = 1.0 + (trackVolume / 1000); //y3 = 1.0 + (trackVolume / 1000); } if (trackTime > startFrame) { Timecode effectTime = (trackTime - startFrame); Timecode effectTime1 = (effectTime - Timecode.FromFrames(7)); Timecode effectTime2 = (effectTime - Timecode.FromFrames(8)); Timecode effectTime3 = (effectTime - Timecode.FromFrames(9)); OFXDoubleParameter ofxScaleX = (OFXDoubleParameter)ofxdeformation["Scale X"]; ofxScaleX.IsAnimated = true; setOFXDoubleParameter (ofxdeformation, "Scale X", effectTime1, y1); //setOFXDoubleParameter (ofxdeformation, "Scale X", effectTime2, y2); //setOFXDoubleParameter (ofxdeformation, "Scale X", effectTime3, y3); //setOFXDoubleParameter (ofxdeformation, "Scale X", Timecode.FromFrames(0), 0.800); foreach(OFXDoubleKeyframe elemnt in ofxScaleX.Keyframes) { elemnt.Interpolation = OFXInterpolationType.Smooth; } OFXDoubleParameter ofxScale = (OFXDoubleParameter)ofxpicture["Scale"]; ofxScale.IsAnimated = true; setOFXDoubleParameter (ofxpicture, "Scale", effectTime1, x1); //setOFXDoubleParameter (ofxpicture, "Scale", effectTime2, x2); //setOFXDoubleParameter (ofxpicture, "Scale", effectTime3, x3); //setOFXDoubleParameter (ofxpicture, "Scale", Timecode.FromFrames(0), 0.800); foreach(OFXDoubleKeyframe elemnt in ofxScale.Keyframes) { elemnt.Interpolation = OFXInterpolationType.Smooth; } } } } } } } } } } } public void setOFXDoubleParameter(OFXEffect ofx, string Parameter, Timecode keyTime, double keyValue) { OFXDoubleParameter ofxParm = (OFXDoubleParameter)ofx[Parameter]; ofxParm.IsAnimated = true; ofxParm.SetValueAtTime(keyTime, keyValue); } } public class EntryPoint { public Vegas myVegas; public void FromVegas(Vegas vegas) { Test_Script.Class1 test = new Test_Script.Class1(); myVegas = vegas; test.Main(vegas); } } }
Have a nice day and thx in advance,
Clement F.