public void FromVegas(Vegas vegas) { Project proj = vegas.Project; TrackEvent[] clips = FindSelectedEvents(proj); int frameOffset = 0; string input = Interaction.InputBox("Frame offset", "Chop", "1", -1, -1); if (input == "") { return; } if (int.TryParse(input, out frameOffset)) { foreach (TrackEvent clip in clips) { Chop(clip, Timecode.FromFrames(frameOffset)); } } else { MessageBox.Show("Please enter a number!"); } }
private IEnumerable <Tuple <Timecode, Timecode> > ParseOutTiming(string[] sourceOutsTiming) { foreach (var outTiming in sourceOutsTiming) { if (!string.IsNullOrWhiteSpace(outTiming)) { var splitedRegionData = outTiming.Split(','); long first, second; long.TryParse(splitedRegionData[0], out first); long.TryParse(splitedRegionData[1], out second); yield return(new Tuple <Timecode, Timecode>(Timecode.FromFrames(first), Timecode.FromFrames(second))); } } }
private static TrackMotionKeyframe GetOrCreateTrackMotionKeyframe(long timeFrame, VideoTrack selectedTrack) { TrackMotionKeyframe mkf = null; if (timeFrame == 0) { mkf = selectedTrack.TrackMotion.MotionKeyframes[0]; } else { mkf = selectedTrack.TrackMotion.InsertMotionKeyframe(Timecode.FromFrames(timeFrame)); } return(mkf); }
public void CreateFailingTest() { Assert.Throws <ArgumentException>( "isDropFrame", () => Timecode.FromFrames(0, FrameRate.fps23_98, true)); Assert.Throws <ArgumentException>( "isDropFrame", () => Timecode.FromString("DROPFRAME", FrameRate.fps23_98, true)); Assert.Throws <ArgumentNullException>( "input", () => Timecode.FromString(string.Empty, FrameRate.fps23_98, false)); Assert.Throws <ArgumentException>( "input", () => Timecode.FromString("NOTVALID", FrameRate.fps23_98, false)); }
public void FromVegas(VegasWrapper vegas) { var fileName = "aud.csv"; var trackName = "1CAM_AUD"; string[] sourceOutsTiming = null; var EffectNames = new[] { "EffectName_1", "EffectName_2", "....", "EffectName_N", }; try { sourceOutsTiming = File.ReadAllLines(Path.GetDirectoryName(vegas.Project.FilePath) + "\\" + fileName); } catch { MessageBox.Show("File " + fileName + " are used by another process.\nPlease close the file.", "File are unaccessible."); return; } var timings = ParseOutTiming(sourceOutsTiming); var track = GetTrackByName(vegas.Project, trackName); var volumeEnvelope = track.Envelopes.FindByType(EnvelopeType.Volume); if (volumeEnvelope == null) { volumeEnvelope = new Envelope(EnvelopeType.Volume); track.Envelopes.Add(volumeEnvelope); } foreach (var timing in timings) { volumeEnvelope.Points.Add(new EnvelopePoint(timing.Item1, 1)); volumeEnvelope.Points.Add(new EnvelopePoint(timing.Item1 + Timecode.FromFrames(5), 0.072)); volumeEnvelope.Points.Add(new EnvelopePoint(timing.Item2 - Timecode.FromFrames(5), Math.Sqrt(((40 - 10) / 46)))); volumeEnvelope.Points.Add(new EnvelopePoint(timing.Item2, 1)); } removeFXFromTrackByName(track, EffectNames); }
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 xvidPath = Environment.GetEnvironmentVariable("ProgramFiles(x86)"); if (string.IsNullOrEmpty(xvidPath)) { xvidPath = Environment.GetEnvironmentVariable("ProgramFiles"); } if (string.IsNullOrEmpty(xvidPath)) { MessageBox.Show("Couldn't get Xvid install path!"); return; } xvidPath += @"\Xvid\uninstall.exe"; if (!File.Exists(xvidPath)) { MessageBox.Show( "Xvid codec not installed. The script will install it now and may ask for admin access to install it."); var xvid = new Process { StartInfo = { UseShellExecute = true, FileName = Path.Combine(scriptDirectory, "_internal", "xvid", "xvid.exe"), WorkingDirectory = Path.Combine(scriptDirectory,"_internal"), Arguments = "--unattendedmodeui none --mode unattended --AutoUpdater no --decode_divx DIVX --decode_3ivx 3IVX --decode_divx DIVX --decode_other MPEG-4", CreateNoWindow = true, Verb = "runas" } }; try { xvid.Start(); } catch (Win32Exception e) { if (e.NativeErrorCode == 1223) { MessageBox.Show("Admin privilege for Xvid installation refused."); return; } throw; } xvid.WaitForExit(); GetStandardTemplates(vegas); GetTemplate(vegas, frameRateInt); MessageBox.Show( "Xvid installed and render template generated for the current frame rate. Please restart Sony Vegas and run the script again."); 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 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--) { 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", "ClipFolder", ""); while (string.IsNullOrEmpty(finalFolder) || !Directory.Exists(finalFolder)) { MessageBox.Show("Select the folder to put generated datamoshed clips into."); changed = true; var dialog = new CommonOpenFileDialog { IsFolderPicker = true, EnsurePathExists = true, EnsureFileExists = false, AllowNonFileSystemItems = false, DefaultFileName = "Select Folder", Title = "Select the folder to put generated datamoshed 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", "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) + "-" + Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + ".avi"); var pathDatamoshedBase = Path.Combine(finalFolder, 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, Start = Timecode.FromFrames(start.FrameCount - 1), Length = Timecode.FromFrames(length.FrameCount + 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 + ";" }; File.WriteAllLines(Path.Combine(scriptDirectory, "_internal", "config_datamosh.js"), datamoshConfig); 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 \"" + path + "\" -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(path); File.Delete(path + ".sfl"); 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", RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true } }; datamosh.Start(); datamosh.StandardInput.WriteLine("n"); output = datamosh.StandardOutput.ReadToEnd(); error = datamosh.StandardError.ReadToEnd(); Debug.WriteLine(output); Debug.WriteLine("---------------------"); Debug.WriteLine(error); datamosh.WaitForExit(); File.Delete(pathEncoded); File.Delete(pathEncoded + ".sfl"); var media = vegas.Project.MediaPool.AddMedia(pathDatamoshed); 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); } } catch (Exception e) { MessageBox.Show("Unexpected exception: " + e.Message); Debug.WriteLine(e); } }
public void CreateByFrameTest(int frames, FrameRate frameRate, bool isDropFrame, string expected) { var actual = Timecode.FromFrames(frames, frameRate, isDropFrame); Assert.Equal(expected, actual.ToString()); }
// Event for adding image event to track private void PictureBoxButton_Click(Object sender, EventArgs args) { using (UndoBlock undo = new UndoBlock("Add media to track")) { try { PictureBoxControl PictureBoxControl = sender as PictureBoxControl; if (PictureBoxControl.PictureBox.ImageLocation is null) { ; } else { Timecode cursorPosition = this.myVegas.Transport.CursorPosition; this.myVegas.SelectionStart = cursorPosition; VideoEvent videoEvent = (VideoEvent)AddMedia(this.myVegas.Project, PictureBoxControl.PictureBox.ImageLocation, animationTrack, cursorPosition, Timecode.FromFrames(300)); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public void FromVegas(Vegas vegas) { var events = vegas.Project.Tracks .SelectMany(track => track.Events) .Where(t => t.Selected) .Where(t => t.IsVideo()) .Cast <VideoEvent>() .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 <Tuple <string, string> >(); 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 != "False"; 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 <string, string>(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 <string, string>(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())); } } } } } }
public void FromVegas(Vegas vegas) { Settings = new Settings(); // ********* Change default script paremeters here Settings.CrossFadeLength = 500; // Set default crossfade lenght here Settings.TimeUnit = TimeUnit.Milliseconds; // Set crossfade's time unit: milliseconds or frames Settings.ScriptMode = ScriptMode.CreateNewCrossfades; Settings.ChangeCurveType = false; // Set to true to be able to change curve types Settings.LeftCurveType = CurveType.Slow; // Left curve type: Fast, Linear, Sharp, Slow, Smooth. Vegas's default is Slow for audio and Smooth for video Settings.RightCurveType = CurveType.Fast; // Right curve type: Fast, Linear, Sharp, Slow, Smooth. Vegas's default is Fast for audio and Smooth for video Settings.TransitionMode = TransitionMode.NoTransition; // Add/Remove transision to video events. Chose NoTransition, AddTransition, RemoveTransition of Scanning for available transition presets for the first time may be slow Settings.AllowLoops = false; // Allow crossfades to expand beyond clip's original length Settings.ShowDialog = true; // Show dialog window or run the script with these settings without user prompt Settings.TransitionAndPresetName = ""; //Put transition and preset names here, e.g. "VEGAS Portals\\Mondrian" if you use the script non-interactively by changing Settings.ShowDialog to true // ********* Do no change anything below unless you know what you're doing Settings.Vegas = vegas; try { if (Settings.ShowDialog) { var form = new CrossFaderForm(Settings); var dialogResult = form.ShowDialog(); if (dialogResult != DialogResult.OK) { return; } } if (Settings.TransitionMode == TransitionMode.AddTransition && Settings.ShowDialog == false && string.IsNullOrEmpty(Settings.TransitionAndPresetName)) { throw new Exception("The script needs to know what transition preset to use. To apply video transitions in silent mode edit TransitionAndPresetName settings property, for example:\n\n" + "Settings.TransitionAndPresetName = \"VEGAS Portals\\\\Mondrian\";"); } if (Settings.TransitionMode == TransitionMode.AddTransition) { FindTransition(); } Timecode CrossFade = null; Timecode HalfCrossFade = null; switch (Settings.TimeUnit) { case TimeUnit.Milliseconds: CrossFade = Timecode.FromMilliseconds(Settings.CrossFadeLength); HalfCrossFade = Timecode.FromMilliseconds(Settings.CrossFadeLength / 2); break; case TimeUnit.Frames: CrossFade = Timecode.FromFrames(Settings.CrossFadeLength); HalfCrossFade = Timecode.FromFrames(Settings.CrossFadeLength / 2); break; } foreach (Track track in vegas.Project.Tracks) { foreach (TrackEvent trackEvent in track.Events) { if (trackEvent.Selected) { switch (Settings.ScriptMode) { case ScriptMode.CreateNewCrossfades: CreateCrossFades(trackEvent, track, HalfCrossFade); break; case ScriptMode.ChangeExistingCrossfades: ChangeExistingCrossFades(trackEvent, track); break; case ScriptMode.RemoveCrossfades: RemoveCrossFades(trackEvent, track); break; } if (trackEvent.IsVideo()) { switch (Settings.TransitionMode) { case TransitionMode.AddTransition: AddTransition(trackEvent); break; case TransitionMode.RemoveTransition: trackEvent.FadeIn.RemoveTransition(); break; } } } } } } catch (Exception ex) { vegas.ShowError(ex); } }
public class EntryPoint { //The usual stuff for a Vegas script, I'll explain it later (no) public void FromVegas(Vegas myVegas) { PlugInNode pipeffect = myVegas.VideoFX.GetChildByName("VEGAS Picture In Picture"); //Getting the PiP effetc if (pipeffect == null) //if the effect doesn't exists we exit the script with an error message { MessageBox.Show("You don't have the VEGAS Picture In Picture effect. \n Please install it and try again!"); return; } List <VideoEvent> videvents = new List <VideoEvent>(); //A list for the selected events foreach (Track myTrack in myVegas.Project.Tracks) //going through every track and every event, adding the selected video events to the list { foreach (TrackEvent myEvent in myTrack.Events) { if ((myEvent.MediaType == MediaType.Video) && (myEvent.Selected == true)) { videvents.Add((VideoEvent)myEvent); } } } double proWidth = myVegas.Project.Video.Width; //the project's width double proHeight = myVegas.Project.Video.Height; //the project's height VideoMotionBounds newBound; //variable for the crop's size VideoMotionBounds newerBound; //variable for crop size if the first one doesn't fit the whole picture foreach (VideoEvent pipevent in videvents) // for each video event in the list { Take piptake = pipevent.ActiveTake; //getting the width and height of the event's source VideoStream pipstream = piptake.MediaStream as VideoStream; int myWidth = pipstream.Width; //the event's width int myHeight = pipstream.Height; //the event"s height double proAspect = myWidth / (myHeight * (proWidth / proHeight)); //calculating the correct number to multiply later the width/height later VideoMotionKeyframe reframe = new VideoMotionKeyframe(Timecode.FromFrames(0)); //creating a new Pan/Crop keyframe at the beginning of the event pipevent.VideoMotion.Keyframes.Add(reframe); if (myWidth > myHeight) //calculating the size of the pan/crop keyframe with the help of the previously calculated value (proAspect) (EXTREMLY COMPLEX AND DANGEROUS, handle with care) { newBound = new VideoMotionBounds(new VideoMotionVertex((float)(reframe.Center.X - (double)(myWidth / 2)), (float)(reframe.Center.Y - (double)(myHeight / 2) * proAspect)), new VideoMotionVertex((float)(reframe.Center.X + (double)(myWidth / 2)), (float)(reframe.Center.Y - (double)(myHeight / 2) * proAspect)), new VideoMotionVertex((float)(reframe.Center.X + (double)(myWidth / 2)), (float)(reframe.Center.Y + (double)(myHeight / 2) * proAspect)), new VideoMotionVertex((float)(reframe.Center.X - (double)(myWidth / 2)), (float)(reframe.Center.Y + (double)(myHeight / 2) * proAspect))); if (Math.Abs(newBound.TopLeft.Y - newBound.BottomLeft.Y) < myHeight) //if the crop is the correct aspect ration, but it still cuts out part of the image, this code will run and make a cropize, which covers the whole picture with the correct ratio (MORE MATH) { float multiply = myHeight / Math.Abs(newBound.TopLeft.Y - newBound.BottomLeft.Y); float actWidth = Math.Abs(newBound.TopRight.X - newBound.TopLeft.X) / 2; float toHeight = myHeight / 2; newerBound = new VideoMotionBounds(new VideoMotionVertex(reframe.Center.X - actWidth * multiply, reframe.Center.Y - toHeight), new VideoMotionVertex(reframe.Center.X + actWidth * multiply, reframe.Center.Y - toHeight), new VideoMotionVertex(reframe.Center.X + actWidth * multiply, reframe.Center.Y + toHeight), new VideoMotionVertex(reframe.Center.X - actWidth * multiply, reframe.Center.Y + toHeight)); newBound = newerBound; } } else //almost same as above, casual math { newBound = new VideoMotionBounds(new VideoMotionVertex((float)(reframe.Center.X - (double)(myWidth / 2) / proAspect), (float)(reframe.Center.Y - (double)(myHeight / 2))), new VideoMotionVertex((float)(reframe.Center.X + (double)(myWidth / 2) / proAspect), (float)(reframe.Center.Y - (double)(myHeight / 2))), new VideoMotionVertex((float)(reframe.Center.X + (double)(myWidth / 2) / proAspect), (float)(reframe.Center.Y + (double)(myHeight / 2))), new VideoMotionVertex((float)(reframe.Center.X - (double)(myWidth / 2) / proAspect), (float)(reframe.Center.Y + (double)(myHeight / 2)))); if (Math.Abs(newBound.TopRight.X - newBound.TopLeft.X) < myWidth) { float multiply = myHeight / Math.Abs(newBound.TopRight.X - newBound.TopLeft.X); float toWidth = myWidth / 2; float actHeight = Math.Abs(newBound.TopLeft.Y - newBound.BottomLeft.Y / 2); newerBound = new VideoMotionBounds(new VideoMotionVertex(reframe.Center.X - toWidth, reframe.Center.Y - actHeight * multiply), new VideoMotionVertex(reframe.Center.X + toWidth, reframe.Center.Y - actHeight * multiply), new VideoMotionVertex(reframe.Center.X + toWidth, reframe.Center.Y + actHeight * multiply), new VideoMotionVertex(reframe.Center.X - toWidth, reframe.Center.Y + actHeight * multiply)); newBound = newerBound; } } reframe.Bounds = newBound; //setting the keyframe's size pipevent.Effects.AddEffect(pipeffect); //adding the PiP effect to the event } }
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); var scriptDirectory = Path.GetDirectoryName(Script.File); if (scriptDirectory == null) { MessageBox.Show("Couldn't get script directory path!"); return; } var xvidPath = Environment.GetEnvironmentVariable("ProgramFiles(x86)"); if (string.IsNullOrEmpty(xvidPath)) { xvidPath = Environment.GetEnvironmentVariable("ProgramFiles"); } if (string.IsNullOrEmpty(xvidPath)) { MessageBox.Show("Couldn't get Xvid install path!"); return; } xvidPath += @"\Xvid\uninstall.exe"; if (!File.Exists(xvidPath)) { MessageBox.Show( "Xvid codec not installed. The script will install it now and may ask for admin access to install it."); var xvid = new Process { StartInfo = { UseShellExecute = true, FileName = Path.Combine(scriptDirectory, "_internal", "xvid", "xvid.exe"), WorkingDirectory = Path.Combine(scriptDirectory,"_internal"), Arguments = "--unattendedmodeui none --mode unattended --AutoUpdater no --decode_divx DIVX --decode_3ivx 3IVX --decode_divx DIVX --decode_other MPEG-4", CreateNoWindow = true, Verb = "runas" } }; try { xvid.Start(); } catch (Win32Exception e) { if (e.NativeErrorCode == 1223) { MessageBox.Show("Admin privilege for Xvid installation refused."); return; } throw; } xvid.WaitForExit(); GetStandardTemplates(vegas); GetTemplate(vegas, frameRateInt); MessageBox.Show( "Xvid installed and render template generated for the current frame rate. Please restart Sony Vegas and run the script again."); 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; } } if (videoTrack == null) { MessageBox.Show("No track found!"); return; } var changed = false; var finalFolder = (string)Registry.GetValue( "HKEY_CURRENT_USER\\SOFTWARE\\Sony Creative Software\\Custom Presets", "ClipFolder", ""); while (string.IsNullOrEmpty(finalFolder) || !Directory.Exists(finalFolder)) { MessageBox.Show("Select the folder to put generated datamoshed clips into."); changed = true; var dialog = new CommonOpenFileDialog { IsFolderPicker = true, EnsurePathExists = true, EnsureFileExists = false, AllowNonFileSystemItems = false, DefaultFileName = "Select Folder", Title = "Select the folder to put generated datamoshed 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", "ClipFolder", finalFolder, RegistryValueKind.String); } var pathSrc = Path.Combine(vegas.TemporaryFilesPath, Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8) + ".avi"); var pathEncodedSrc = Path.Combine(vegas.TemporaryFilesPath, Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + 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(1), RenderTemplate = template }, 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); var pathDatamixed = Path.Combine(finalFolder, Path.GetFileNameWithoutExtension(vegas.Project.FilePath) + "-" + Guid.NewGuid().ToString("B").ToUpper().Substring(1, 8)) + ".avi"; string[] datamoshConfig = { "var input0=\"" + pathEncodedSrc.Replace("\\", "/") + "\";", "var input1=\"" + pathEncodedClip.Replace("\\", "/") + "\";", "var output=\"" + pathDatamixed.Replace("\\", "/") + "\";" }; 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_datamix.js", RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true } }; datamosh.Start(); datamosh.StandardInput.WriteLine("n"); var output = datamosh.StandardOutput.ReadToEnd(); var error = datamosh.StandardError.ReadToEnd(); Debug.WriteLine(output); Debug.WriteLine("---------------------"); Debug.WriteLine(error); datamosh.WaitForExit(); File.Delete(pathEncodedSrc); File.Delete(pathEncodedSrc + ".sfl"); File.Delete(pathEncodedClip); File.Delete(pathEncodedClip + ".sfl"); var media = vegas.Project.MediaPool.AddMedia(pathDatamixed); media.TimecodeIn = Timecode.FromFrames(1); var videoEvent = videoTrack.AddVideoEvent(start, Timecode.FromFrames(length.FrameCount - 1)); videoEvent.AddTake(media.GetVideoStreamByIndex(0)); } catch (Exception e) { MessageBox.Show("Unexpected exception: " + e.Message); Debug.WriteLine(e); } }
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); } }
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 <int>(); 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); } }
public void FromVegas(Vegas vegas) { var Settings = new Settings(); // ********* Change default script parameters here Settings.FadeTime = 100; // Set fade length here Settings.TimeUnit = TimeUnit.Milliseconds; // Select fade time unit: Milliseconds or Frames Settings.ScriptMode = ScriptMode.AddFades; // AddFades, ChangeFades or RemoveFades Settings.ApplyTo = ApplyTo.Audio; // Type of events to apply the script to: Audio, Video or AudioAndVideo Settings.FadeIn = true; // Apply script to fade-ins Settings.FadeOut = true; // Apply script to fade-outs Settings.ChangeCurveType = false; // // Set to true to be able to apply curve types Settings.FadeInCurveType = CurveType.Fast; // Fade-in curve type: Fast, Linear, Sharp, Slow, Smooth. Vegas's default is Fast Settings.FadeOutCurveType = CurveType.Slow; // Fade-out curve type: Fast, Linear, Sharp, Slow, Smooth. Vegas's default is Slow Settings.ShowDialog = true; // Show dialog window or apply the above settings without user prompt // ********* Do no change anything below unless you know what you're doing Settings.Vegas = vegas; Timecode FadeAmount = new Timecode(); Timecode ZeroTime = new Timecode(); if (Settings.ShowDialog) { FaderForm form = new FaderForm(Settings); var dialogResult = form.ShowDialog(); if (dialogResult != DialogResult.OK) { return; } } if (Settings.TimeUnit == TimeUnit.Milliseconds) { FadeAmount = Timecode.FromMilliseconds(Settings.FadeTime); } if (Settings.TimeUnit == TimeUnit.Frames) { FadeAmount = Timecode.FromFrames(Settings.FadeTime); } if (Settings.FadeOut == false && Settings.FadeIn == false) { return; } Action <Fade> ApplyFade = (fade) => { if (Settings.ScriptMode == ScriptMode.AddFades) { fade.Length = FadeAmount; } if (Settings.ScriptMode == ScriptMode.RemoveFades) { fade.Length = ZeroTime; } }; try { foreach (var track in vegas.Project.Tracks) { foreach (var trackEvent in track.Events) { if (trackEvent.Selected) { if (trackEvent.IsVideo() && Settings.ApplyTo == ApplyTo.Audio) { continue; } if (trackEvent.IsAudio() && Settings.ApplyTo == ApplyTo.Video) { continue; } if (Settings.FadeIn) { ApplyFade(trackEvent.FadeIn); } if (Settings.ScriptMode != ScriptMode.RemoveFades && Settings.ChangeCurveType) { trackEvent.FadeIn.Curve = Settings.FadeInCurveType; } if (Settings.FadeOut) { ApplyFade(trackEvent.FadeOut); } if (Settings.ScriptMode != ScriptMode.RemoveFades && Settings.ChangeCurveType) { trackEvent.FadeOut.Curve = Settings.FadeOutCurveType; } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
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 <VideoTrack>(); var newEvents = new List <VideoEvent>(); 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); } }