I'm trying to make this script delete the video parts in the same way it deletes the audio parts. Instead of deleting only one part of the audio and leaving the video parts as they are, I want it to delete both at the same time. In summary, I'm trying to make it perform the same cuts and remove both the audio and video parts
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
Renderer myRenderer = null;
RenderTemplate rndrTemplate = null;
double QuietLimit = -3381.86;
Timecode logOffset = Timecode.FromFrames(15);
Timecode minDuration = Timecode.FromMilliseconds(500); // Duração mínima de silêncio em milissegundos
Timecode minDistance = Timecode.FromMilliseconds(100); // Distância mínima para mesclar em milissegundos
bool[,] trackStatus = new bool[1000, 2];
public void Main(Vegas vegas, Track videoTrack)
{
myVegas = vegas;
FindRenderers();
string tempFile = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + "temp.mp3";
string tempLog = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + "temp_loud.txt";
SaveTrackStatus();
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsAudio() && myTrack.Selected)
{
myTrack.Mute = false;
RenderTempFile(tempFile);
ProcessLog(tempLog, myTrack, videoTrack);
File.Delete(tempFile);
File.Delete(tempLog);
myTrack.Mute = true;
}
}
RecallTrackStatus();
}
public void FindRenderers()
{
try
{
foreach (Renderer renderer in myVegas.Renderers)
{
// MP3
if ("adfa6a4b-a99b-42e3-ae1f-081123ada04b" == renderer.ClassID.ToString())
{
myRenderer = renderer;
try
{
foreach (RenderTemplate renderTemplate in renderer.Templates)
{
if (renderTemplate.IsValid())
{
// 192 Kbps, CD Transparent Audio
if ("8ab64a16-81f5-46e6-8155-1611d592088c" == renderTemplate.TemplateGuid.ToString())
{
rndrTemplate = renderTemplate;
}
}
}
}
catch
{
}
}
}
}
catch
{
}
}
public void SaveTrackStatus()
{
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsAudio())
{
int myIndex = myTrack.Index;
trackStatus[myIndex, 0] = myTrack.Mute;
trackStatus[myIndex, 1] = myTrack.Solo;
myTrack.Mute = true;
myTrack.Solo = false;
}
}
}
public void RecallTrackStatus()
{
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsAudio())
{
int myIndex = myTrack.Index;
myTrack.Mute = trackStatus[myIndex, 0];
myTrack.Solo = trackStatus[myIndex, 1];
}
}
}
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, Track myTrack, Track videoTrack)
{
var lines = File.ReadLines(path);
bool foundfirst = false;
bool FoundQuiet = false;
Timecode QuietStart = Timecode.FromFrames(0);
Timecode QuietEnd = Timecode.FromFrames(0);
Timecode PreviousTC = Timecode.FromFrames(0);
foreach (string line in lines)
{
if (line.StartsWith("------------"))
{
if (FoundQuiet)
{
QuietEnd = PreviousTC;
ProcessSegment(QuietStart, QuietEnd, myTrack, videoTrack);
}
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]);
}
if (trackVolume < QuietLimit)
{
if (!FoundQuiet)
{
FoundQuiet = true;
QuietStart = trackTime;
}
else
{
QuietEnd = trackTime;
}
}
else
{
if (FoundQuiet)
{
FoundQuiet = false;
ProcessSegment(QuietStart, QuietEnd, myTrack, videoTrack);
}
}
PreviousTC = trackTime;
}
}
}
}
}
private void ProcessSegment(Timecode QuietStart, Timecode QuietEnd, Track audioTrack, Track videoTrack)
{
Timecode startTC = QuietStart - logOffset;
if (startTC < Timecode.FromFrames(0))
{
startTC = Timecode.FromFrames(0);
}
Timecode endTC = QuietEnd - logOffset;
Timecode regionLen = endTC - startTC;
if (regionLen > minDuration)
{
foreach (TrackEvent evnt in audioTrack.Events)
{
if (evnt.Start < startTC && evnt.End > startTC)
{
evnt.Split(startTC - evnt.Start);
}
if (evnt.Start < endTC && evnt.End > endTC)
{
evnt.Split(endTC - evnt.Start);
}
}
for (int i = audioTrack.Events.Count - 1; i >= 0; i--)
{
TrackEvent evnt = audioTrack.Events[i];
if (evnt.Start >= startTC && evnt.End <= endTC)
{
audioTrack.Events.Remove(evnt);
}
}
// Cut the video track in sync with the audio
foreach (TrackEvent videoEvent in videoTrack.Events)
{
if (videoEvent.Start < startTC && videoEvent.End > startTC)
{
videoEvent.Split(startTC - videoEvent.Start);
}
if (videoEvent.Start < endTC && videoEvent.End > endTC)
{
videoEvent.Split(endTC - videoEvent.Start);
}
}
for (int i = videoTrack.Events.Count - 1; i >= 0; i--)
{
TrackEvent videoEvent = videoTrack.Events[i];
if (videoEvent.Start >= startTC && videoEvent.End <= endTC)
{
videoTrack.Events.Remove(videoEvent);
}
}
}
else if (regionLen < minDistance)
{
// Implement logic for merging here if needed
}
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Test_Script.Class1 test = new Test_Script.Class1();
// Assuming videoTrackIndex is the index of the video track you want to cut
int videoTrackIndex = 0; // Change this to the appropriate index
Track videoTrack = vegas.Project.Tracks[videoTrackIndex];
test.Main(vegas, videoTrack);
}
}
I'm trying to make this script delete the video parts in the same way it deletes the audio parts. Instead of deleting only one part of the audio and leaving the video parts as they are, I want it to delete both at the same time. In summary, I'm trying to make it perform the same cuts and remove both the audio and video parts