Hello, I'm trying to create a script that deletes both video and audio parts equally. However, even though I've attempted to use the lines of code from another script that has the same function, it doesn't seem to work and doesn't delete the video parts along with the audio. Any ideas on how to correct this?
using System;
using System.Windows.Forms;
using System.IO;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Formulario : Form
{
private Label labelSignalBelow;
private TextBox textBoxSignalBelow;
private Label labelMinDuration;
private TextBox textBoxMinDuration;
private Label labelMinDistance;
private TextBox textBoxMinDistance;
private Button buttonOK;
private Button buttonCancel;
private bool formularioFechado = false;
private Vegas myVegas;
private string tempFilePath;
public Formulario(Vegas vegas)
{
myVegas = vegas;
Text = "Remoção de áreas silenciosas";
Size = new System.Drawing.Size(400, 175);
FormBorderStyle = FormBorderStyle.FixedDialog;
StartPosition = FormStartPosition.CenterScreen;
textBoxSignalBelow = CriarTextBox("-3381"); // Alteração aqui para -3381 dB
textBoxSignalBelow.Location = new System.Drawing.Point(10, 30);
labelSignalBelow = new Label();
labelSignalBelow.Text = "Sinal abaixo de (dB):";
labelSignalBelow.AutoSize = true;
labelSignalBelow.Location = new System.Drawing.Point(textBoxSignalBelow.Left, textBoxSignalBelow.Top - labelSignalBelow.Height);
textBoxMinDuration = CriarTextBox("00:00:00.500");
textBoxMinDuration.Location = new System.Drawing.Point(labelSignalBelow.Right + 20, 30);
labelMinDuration = new Label();
labelMinDuration.Text = "Min Duration:";
labelMinDuration.AutoSize = true;
labelMinDuration.Location = new System.Drawing.Point(textBoxMinDuration.Left, textBoxMinDuration.Top - labelMinDuration.Height);
textBoxMinDistance = CriarTextBox("00:00:00.100");
textBoxMinDistance.Location = new System.Drawing.Point(labelMinDuration.Right + 20, 30);
labelMinDistance = new Label();
labelMinDistance.Text = "Min Distance:";
labelMinDistance.AutoSize = true;
labelMinDistance.Location = new System.Drawing.Point(textBoxMinDistance.Left, textBoxMinDistance.Top - labelMinDistance.Height);
buttonOK = new Button();
buttonOK.Text = "OK";
buttonOK.Location = new System.Drawing.Point(10, ClientSize.Height - buttonOK.Height - 10);
buttonCancel = new Button();
buttonCancel.Text = "Cancelar";
buttonCancel.Location = new System.Drawing.Point(buttonOK.Right + 10, ClientSize.Height - buttonCancel.Height - 10);
buttonCancel.Click += (sender, e) =>
{
formularioFechado = true;
Close();
};
buttonOK.Click += (sender, e) =>
{
formularioFechado = false;
ExecuteSilentAreaRemovalScript();
Close();
};
ControlBox = false;
MinimizeBox = false;
MaximizeBox = false;
FormBorderStyle = FormBorderStyle.FixedDialog;
Controls.Add(labelSignalBelow);
Controls.Add(textBoxSignalBelow);
Controls.Add(labelMinDuration);
Controls.Add(textBoxMinDuration);
Controls.Add(labelMinDistance);
Controls.Add(textBoxMinDistance);
Controls.Add(buttonOK);
Controls.Add(buttonCancel);
}
private TextBox CriarTextBox(string defaultValue)
{
TextBox textBox = new TextBox();
textBox.Text = defaultValue;
textBox.Size = new System.Drawing.Size(100, 20);
return textBox;
}
private void ExecuteSilentAreaRemovalScript()
{
double signalBelowDB = Convert.ToDouble(textBoxSignalBelow.Text);
string minDurationStr = textBoxMinDuration.Text;
string minDistanceStr = textBoxMinDistance.Text;
if (string.IsNullOrWhiteSpace(minDurationStr) || string.IsNullOrWhiteSpace(minDistanceStr))
{
MessageBox.Show("Valores inválidos ou nenhum valor fornecido. O script será encerrado.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
Timecode minDuration = Timecode.FromString(minDurationStr);
Timecode minDistance = Timecode.FromString(minDistanceStr);
Class1 script = new Class1();
script.Main(myVegas, signalBelowDB, minDuration, minDistance, tempFilePath);
}
public Tuple<string, string, string> GetSignalMinDurationDistance()
{
ShowDialog();
return Tuple.Create(textBoxSignalBelow.Text, textBoxMinDuration.Text, textBoxMinDistance.Text);
}
public void SetTempFilePath(string path)
{
tempFilePath = path;
}
}
public class Class1
{
public Vegas myVegas;
Renderer myRenderer = null;
RenderTemplate rndrTemplate = null;
double QuietLimit = -3381; // Alteração aqui para -3381 dB
Timecode logOffset = Timecode.FromFrames(15);
Timecode minDuration = Timecode.FromMilliseconds(500);
Timecode minDistance = Timecode.FromMilliseconds(100);
public void Main(Vegas vegas, double signalBelowDB, Timecode minDuration, Timecode minDistance, string tempFilePath)
{
myVegas = vegas;
FindRenderers();
string tempLog = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + "temp_loud.txt";
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsAudio())
{
myTrack.Mute = false;
ProcessLog(tempLog, myTrack, signalBelowDB);
myTrack.Mute = true;
}
}
}
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 ProcessLog(string path, Track myTrack, double signalBelowDB)
{
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, signalBelowDB);
}
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 < signalBelowDB)
{
if (!FoundQuiet)
{
FoundQuiet = true;
QuietStart = trackTime;
}
else
{
QuietEnd = trackTime;
}
}
else
{
if (FoundQuiet)
{
FoundQuiet = false;
ProcessSegment(QuietStart, QuietEnd, myTrack, signalBelowDB);
}
}
PreviousTC = trackTime;
}
}
}
}
}
private void ProcessSegment(Timecode QuietStart, Timecode QuietEnd, Track audioTrack, double signalBelowDB)
{
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);
}
}
}
else if (regionLen < minDistance)
{
// Implement logic for merging here if needed
}
}
}
public class EntryPoint
{
private Vegas myVegas;
public void FromVegas(Vegas vegas)
{
myVegas = vegas;
string tempFilePath = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + Guid.NewGuid().ToString("N") + ".mp3";
Formulario formulario = new Formulario(myVegas);
formulario.SetTempFilePath(tempFilePath);
var values = formulario.GetSignalMinDurationDistance();
string signalBelowDB = values.Item1;
string minDuration = values.Item2;
string minDistance = values.Item3;
if (string.IsNullOrWhiteSpace(signalBelowDB) || string.IsNullOrWhiteSpace(minDuration) || string.IsNullOrWhiteSpace(minDistance))
{
MessageBox.Show("Valores inválidos ou nenhum valor fornecido. O script será encerrado.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
double signalDB = Convert.ToDouble(signalBelowDB);
Timecode minDur = Timecode.FromString(minDuration);
Timecode minDist = Timecode.FromString(minDistance);
Class1 script = new Class1();
script.Main(myVegas, signalDB, minDur, minDist, tempFilePath);
}
}
}
Hello, I'm trying to create a script that deletes both video and audio parts equally. However, even though I've attempted to use the lines of code from another script that has the same function, it doesn't seem to work and doesn't delete the video parts along with the audio. Any ideas on how to correct this?