script to cut video clips based on timecode

marcinzm wrote on 9/10/2021, 4:24 PM

Hello,

 

I would like to create some sophisticated script, which do the following job for me...

I have 4 video tracks that's contain videos from different camera angles.

The whole project is 2 hours total time.

I have a text file which contains times:
0:1:56:00

0:2:20:00

0:2:26:00

0:2:49:00

0:3:5:00

0:3:16:00

0:3:40:00

0:4:19:00

0:5:41:00

0:6:12:00

...

2:01:00:00

etc.

I would like to read the times from the import text file and minus 5 seconds and plus 5 seconds from above times (10 seconds total duration time as a result) and cut this video clips (from the video camera angle which is not muted - 1 of these 4 video tracks will be always not muted - because it was edited from multicamera view in Vegas Pro so always 3 videos on timeline will be muted and 1 video will be not muted on the specified duration position).

Such video cut should be moved upper on the seperate video track previously prepared for it. Let's name this video track: "video cuts".

I don't need audio track.

 

Is it possible to do via script?
Regards
Marcin

If you are bored, drink water, you will want to pee. -> Albert Einstein - my idol!

I am 42. I have been creating videos since 2009 (the date when my first daughter was born in). My first video software was Pinnacle, next one was Sony Vegas 8 (I am not sure if remember it correctly). I am also a developer and wedding movie operator and editor. For example: I have created an Android app which let me control Vegas Pro rendering progress level on Android smartphone. I created it for fun, because I also love programming. I also created my own plugin for Audio To Text feature specified usage from Vegas Pro 19. I created proxy creation plugin which uses multiple GPU threads (maximum 3) to create proxy files for Vegas Pro. I also written many others plugin/softwares which enhance my video editing, also wedding editing.

Camera/video camera: Sony FX3, Sony A7 III, Sony FDR AX 100, Canon 5D Mark III, GoPro Hero Black 7,8,9,10

Lenses for Sony: Tamron 28-75mm F/2.8 Di III , Sony 24mm gm 1.4 FE, Sony 20 mm G FE 1.8

Lenses for Canon: Canon EF 24-70 mm F/2.8 L USM, Canon 70-200 f/2.8 L

Drone: DJI Mavic 3 & DJI Phantom 4 Pro v2.0

 

Editing: Vegas Pro 20 (365) with a lot of third party plugins, also my own plugins written in C#

 

PC:

CPU: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz   3.31 GHz

RAM: 128 GB

GPU: Nvidia RTX 2080 TI

storage: 4 SSD drives (including two M.2 flash drives) and two HDD drives

Windows system: 10 Home edition

Comments

jetdv wrote on 9/11/2021, 8:25 AM

@marcinzm, the short answer is - yes it is possible. If you go through the tutorials on my website, you can learn how to do a lot of this. But it sounds like you need something that specialized to your needs.

marcinzm wrote on 9/12/2021, 12:44 PM

@jetdv - I will try go through your website and learn how to do it. I have some basics, because I used to create some scripts in the past. I need this script to enhance editing my wedding videoclips.

Thank you all for your replies.

If you are bored, drink water, you will want to pee. -> Albert Einstein - my idol!

I am 42. I have been creating videos since 2009 (the date when my first daughter was born in). My first video software was Pinnacle, next one was Sony Vegas 8 (I am not sure if remember it correctly). I am also a developer and wedding movie operator and editor. For example: I have created an Android app which let me control Vegas Pro rendering progress level on Android smartphone. I created it for fun, because I also love programming. I also created my own plugin for Audio To Text feature specified usage from Vegas Pro 19. I created proxy creation plugin which uses multiple GPU threads (maximum 3) to create proxy files for Vegas Pro. I also written many others plugin/softwares which enhance my video editing, also wedding editing.

Camera/video camera: Sony FX3, Sony A7 III, Sony FDR AX 100, Canon 5D Mark III, GoPro Hero Black 7,8,9,10

Lenses for Sony: Tamron 28-75mm F/2.8 Di III , Sony 24mm gm 1.4 FE, Sony 20 mm G FE 1.8

Lenses for Canon: Canon EF 24-70 mm F/2.8 L USM, Canon 70-200 f/2.8 L

Drone: DJI Mavic 3 & DJI Phantom 4 Pro v2.0

 

Editing: Vegas Pro 20 (365) with a lot of third party plugins, also my own plugins written in C#

 

PC:

CPU: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz   3.31 GHz

RAM: 128 GB

GPU: Nvidia RTX 2080 TI

storage: 4 SSD drives (including two M.2 flash drives) and two HDD drives

Windows system: 10 Home edition

marcinzm wrote on 9/13/2021, 4:31 AM

I am nearly finish my script.
One thing I must do, but I don`t know how.

 

I have event cut. How can I move it to the seperate track which I have added in the beginning of the script.

            Track vTrack= new VideoTrack(0,"teledysk_video");
            myVegas.Project.Tracks.Add(vTrack);
 

and I have:

foreach (Track MyVTrack in myVegas.Project.Tracks)
            {
                foreach (TrackEvent myEventV in MyVTrack.Events)
                {
                    if (!myEventV.Mute)
                    {

...my code, here I want to move myEventV to the vTrack??????

}

}

If you are bored, drink water, you will want to pee. -> Albert Einstein - my idol!

I am 42. I have been creating videos since 2009 (the date when my first daughter was born in). My first video software was Pinnacle, next one was Sony Vegas 8 (I am not sure if remember it correctly). I am also a developer and wedding movie operator and editor. For example: I have created an Android app which let me control Vegas Pro rendering progress level on Android smartphone. I created it for fun, because I also love programming. I also created my own plugin for Audio To Text feature specified usage from Vegas Pro 19. I created proxy creation plugin which uses multiple GPU threads (maximum 3) to create proxy files for Vegas Pro. I also written many others plugin/softwares which enhance my video editing, also wedding editing.

Camera/video camera: Sony FX3, Sony A7 III, Sony FDR AX 100, Canon 5D Mark III, GoPro Hero Black 7,8,9,10

Lenses for Sony: Tamron 28-75mm F/2.8 Di III , Sony 24mm gm 1.4 FE, Sony 20 mm G FE 1.8

Lenses for Canon: Canon EF 24-70 mm F/2.8 L USM, Canon 70-200 f/2.8 L

Drone: DJI Mavic 3 & DJI Phantom 4 Pro v2.0

 

Editing: Vegas Pro 20 (365) with a lot of third party plugins, also my own plugins written in C#

 

PC:

CPU: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz   3.31 GHz

RAM: 128 GB

GPU: Nvidia RTX 2080 TI

storage: 4 SSD drives (including two M.2 flash drives) and two HDD drives

Windows system: 10 Home edition

jetdv wrote on 9/13/2021, 9:17 AM

I just "copy" it to the new track. Then, if desired, you can remove it from the original track.

                        //Copy the event
                        double g = SEvnt.Start.ToMilliseconds(); //Timecode on the new track
    
                        Timecode MyTC = new Timecode(g); //Set the timecode to start on the new track
                        TrackEvent mynewEvent = SEvnt.Copy(DestTrack, MyTC); //Copy to the new track
                        track.Events.Remove(SEvnt); //Remove from the original track

In this case "SEvnt" is on "track". It is then copied to "mynewEvent" on track "DestTrack". Finally, "SEvnt" can be removed from "track" if desired as shown in the last line.

Alternately, I suppose you could just "remove" it from the original track and then "add" it to the new track.

marcinzm wrote on 9/13/2021, 2:08 PM

Thank you. I have written a code:

 

using System;
//using System.Windows.Forms;
using ScriptPortal.Vegas;
using System.IO;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;

public class EntryPoint
{
    
    Vegas myVegas;
    
    public void FromVegas(Vegas vegas)
    {
        myVegas=vegas;
        string p_krok="krok1";
        bool pokaz_logi=false;
        //pokaz_logi=true;
        bool pokaz_logi2=false;
        
        Track vTrack= new VideoTrack(0,"teledysk_video");
        myVegas.Project.Tracks.Add(vTrack);
        
        Track aTrack = new AudioTrack(1,"teledysk_audio");
        myVegas.Project.Tracks.Add(aTrack);
        
        myVegas.UpdateUI();
        
        double tracktime=0;
        int licznik=0;
        
        string[] tablica_splitow_start = new string[20000];
        string[] tablica_splitow_koniec= new string[20000];
        
        p_krok="krok2";
        try
        {
        
        foreach (Track MyVTrack in myVegas.Project.Tracks)
        {
            tracktime=0;
            p_krok="krok3";
            
            foreach (TrackEvent myEventV in MyVTrack.Events)
            {
                //Timecode tracktime = new Timecode("00:00:00:00");
                
                TimeSpan ts1 = TimeSpan.Parse( myEventV.Start.ToString().Substring(0,8));
                double p_myEventV_Start_int = ts1.TotalSeconds;//00:00:02:03
                
                tracktime = p_myEventV_Start_int;
                p_krok="krok4";
                
                if (!myEventV.Mute)
                {
                    p_krok="krok5";
                    String[] timecode_array=File.ReadAllLines("f:\\!!!_YouTube_upload\\_media_file_extractor_ffmpeg_input\\MZ_teledysk.txt");
                    
                    p_krok="krok6";
                    for (int i=0; i<timecode_array.Length;i++)
                    {
                        
                        if (String.IsNullOrEmpty(timecode_array[i]))
                        {
                            continue;
                        }
                        
                    p_krok="krok7";
                    Timecode p_start  = new Timecode(timecode_array[i]);
                    Timecode p_koniec = new Timecode(timecode_array[i]);

                    double p_cut_int  = TimeSpan.Parse(timecode_array[i].Substring(0,8)).TotalSeconds;//00:00:03:00
                    //double p_koniec_int = TimeSpan.Parse(timecode_array[i]).TotalSeconds;
                    
                    if (pokaz_logi)
                    {
                        MessageBox.Show("START="+myEventV.Start.ToString());
                        MessageBox.Show("END="+myEventV.End.ToString());
                    }
                    p_krok="krok8";
                    
                    
                    
                    TimeSpan ts2 = TimeSpan.Parse( myEventV.End.ToString().Substring(0,8));
                    double p_myEventV_End_int = ts2.TotalSeconds;//00:00:11:03
                    
                    p_krok="krok9";
                    if (pokaz_logi)
                    {
                        MessageBox.Show("START_INT="+p_myEventV_Start_int.ToString());//123
                        MessageBox.Show("END_INT="+p_myEventV_End_int.ToString());//663
                        
                        MessageBox.Show("myEventV.Start="+myEventV.Start);
                        MessageBox.Show("myEventV.End="+myEventV.End);
                        MessageBox.Show("p_start="+p_start);
                    }
                    p_krok="krok10";
                    
                    //if (myEventV.Start<=p_start /*&& myEventV.End<p_koniec*/)
                    if (TimeSpan.Parse(myEventV.Length.ToString().Substring(0,8)).TotalSeconds<1 && p_myEventV_Start_int<=p_cut_int && p_myEventV_End_int>=p_cut_int)
                    {
                        licznik++;
                        p_krok="krok11";
                        tablica_splitow_start[licznik]=Timecode.FromSeconds(p_myEventV_Start_int).ToString().Substring(0,8);                        
                        
                        if (pokaz_logi2)
                        {
                            MessageBox.Show("XXtracktimeSTARTWSTAW=("+(p_myEventV_Start_int).ToString()+") tracktime="+tracktime.ToString()+Environment.NewLine+Environment.NewLine+
                                            "XXtracktimeKONIECWSTAW=("+(p_myEventV_End_int).ToString()+") tracktime="+tracktime.ToString()+Environment.NewLine+Environment.NewLine+
                                            "XXp_myEventV_Start_int="+p_myEventV_Start_int.ToString()+" p_myEventV_End_int="+p_myEventV_End_int.ToString());
                        }
                        p_krok="krok12";
                        tablica_splitow_koniec[licznik]=Timecode.FromSeconds(p_myEventV_End_int).ToString().Substring(0,8);
                        p_krok="krok13";
                        myVegas.UpdateUI();
                        
                    }
                    else if (p_myEventV_Start_int<=p_cut_int && p_myEventV_End_int>=p_cut_int)
                    {
                        licznik++;
                        p_krok="krok14";
                        if (pokaz_logi)
                        {
                            MessageBox.Show("WLAZL ZEM");
                        }
                        
                        double p_start_cut=0;
                        
                        p_start_cut=p_cut_int-p_myEventV_Start_int; //wynik 1 sekunda
                        p_krok="krok15";
                        if (pokaz_logi)
                        {
                            MessageBox.Show("X "+p_start_cut.ToString());
                        }
                        
                        double p_start_cut_poczatek=0;
                        double p_start_cut_koniec=0;
                        
                        
                        
                        if (p_start_cut>=5)
                        {
                            p_krok="krok16";
                            p_start_cut=5;
                            p_start_cut_poczatek=p_cut_int-p_myEventV_Start_int-5;
                            if (pokaz_logi)
                            {
                                MessageBox.Show("Y "+p_start_cut_poczatek.ToString());
                            }
                            p_krok="krok17";
                            myEventV.Split(Timecode.FromSeconds(p_start_cut_poczatek));
                            
                            tablica_splitow_start[licznik]=Timecode.FromSeconds(tracktime+p_start_cut_poczatek).ToString().Substring(0,8);
                            
                            p_krok="krok18";
                        }
                        else
                        {
                            
                            /*if (p_myEventV_Start_int>tracktime+p_start_cut_poczatek)
                            {
                                p_start_cut_poczatek=p_myEventV_Start_int;
                                p_start_cut=
                            }*/
                            //nie musisz robic cuta
                            p_krok="krok19";
                            tablica_splitow_start[licznik]=Timecode.FromSeconds(p_myEventV_Start_int).ToString().Substring(0,8);
                            
                        }
                        
                        p_krok="krok20";
                        
                        if (pokaz_logi2)
                        {
                            //MessageBox.Show("tracktimeSTARTWSTAW=("+(tracktime+p_start_cut_poczatek).ToString()+") "+tracktime.ToString()+" p_start_cut_poczatek="+p_start_cut_poczatek.ToString()+Environment.NewLine+Environment.NewLine+ );
                        }
                        //tablica_splitow_start[licznik]=Timecode.FromSeconds(tracktime+p_start_cut_poczatek).ToString().Substring(0,8);
                        
                        
                        double p_start_cut2=p_myEventV_End_int-p_cut_int;//8 sekund
                        
                        //MessageBox.Show("XX "+p_start_cut2.ToString());
                        
                        if (p_start_cut2>=5)
                        {
                            p_krok="krok21";
                            p_start_cut_koniec=p_start_cut_poczatek+5;//wynik 5 sekund
                            if (pokaz_logi)
                            {
                                MessageBox.Show("YY "+p_start_cut_koniec.ToString());
                            }
                            p_krok="krok22";
                            myEventV.Split(Timecode.FromSeconds(p_start_cut+p_start_cut_koniec));
                            p_krok="krok23";
                            tablica_splitow_koniec[licznik]=Timecode.FromSeconds(tracktime+p_start_cut+p_start_cut_koniec).ToString().Substring(0,8);    
                            p_krok="krok24";
                        }
                        else
                        {
                            //p_start_cut=p_cut_int-p_myEventV_Start_int-5;
                            //myEventV.Split(p_start_cut);
                            //nie musisz robic cuta
                            p_krok="krok25";
                            p_start_cut_koniec=p_myEventV_End_int-p_cut_int;
                            p_krok="krok26";
                            tablica_splitow_koniec[licznik]=Timecode.FromSeconds(p_myEventV_End_int).ToString().Substring(0,8);
                        }
                        
                        
                        p_krok="krok27";
                        
                        if (pokaz_logi2)
                        {
                            MessageBox.Show("tracktimeSTARTWSTAW=("+tablica_splitow_start[licznik]+") ("+(tracktime+p_start_cut_poczatek).ToString()+") tracktime="+tracktime.ToString()+" p_start_cut_poczatek="+p_start_cut_poczatek.ToString()+Environment.NewLine+Environment.NewLine+
                                            "tracktimeKONIECWSTAW=("+tablica_splitow_koniec[licznik]+") "+(tracktime+p_start_cut+p_start_cut_koniec).ToString()+") tracktime="+tracktime.ToString()+" p_start_cut="+p_start_cut.ToString()+" p_start_cut_koniec="+p_start_cut_koniec.ToString()+Environment.NewLine+Environment.NewLine+
                                            "p_myEventV_Start_int="+p_myEventV_Start_int.ToString()+" p_myEventV_End_int="+p_myEventV_End_int.ToString()+ " p_cut_int="+p_cut_int.ToString());
                        }
                        
                        
                        
                        //MessageBox.Show("MOVE MOVE MOVE");

                         //myEventV.Copy(vTrack,myEventV.Start);//jest ok
                        
                        p_krok="krok28";
                        myVegas.UpdateUI();
                    }
                    
                }
                
                }
                p_krok="krok29";
                double p_myEventV_Length_int = TimeSpan.Parse(myEventV.Length.ToString().Substring(0,8)).TotalSeconds;
                
                //tracktime = tracktime + p_myEventV_Length_int;
                //tracktime = p_myEventV_Start_int;
                
                if (pokaz_logi)
                {
                    MessageBox.Show("tracktime="+tracktime+" "+myEventV.Length.ToString());
                }
        
            }
        
        }
        
        myVegas.UpdateUI();
        
        if (tablica_splitow_start.Length>0 && licznik>=0)
        {
            p_krok="krok100";
            foreach (Track MyVTrack2 in myVegas.Project.Tracks)
            {
                tracktime=0;
                
                //poczatek_event:
                
                foreach (TrackEvent myEventV in MyVTrack2.Events)
                {
                    //Timecode tracktime = new Timecode("00:00:00:00");
                    p_krok="krok101";
                    if (!myEventV.Mute)
                    {
                        //MessageBox.Show("tablica_splitow_start.lenght="+tablica_splitow_start.Length.ToString());
                        //MessageBox.Show("licznik="+licznik.ToString());
                        p_krok="krok102";
                        
                        for (int i=1; i<=licznik;i++)
                        {
                            p_krok="krok103";
                            if (pokaz_logi)
                            {
                                MessageBox.Show("MOVE MOVE MOVE");
                            }
                            p_krok="krok104";
                            if (myEventV.Start.ToString().Substring(0,8).Equals(tablica_splitow_start[i].ToString().Substring(0,8)) && myEventV.End.ToString().Substring(0,8).Equals(tablica_splitow_koniec[i].ToString().Substring(0,8)))
                            {
                                p_krok="krok105";
                                if (pokaz_logi2)
                                {
                                MessageBox.Show("START_INT="+tablica_splitow_start[i].ToString().Substring(0,8)+Environment.NewLine+Environment.NewLine+
                                                "myEventV.Start="+myEventV.Start.ToString().Substring(0,8)+Environment.NewLine+Environment.NewLine+
                                                "END_INT="+tablica_splitow_koniec[i].ToString().Substring(0,8)+Environment.NewLine+Environment.NewLine+
                                                "myEventV.End="+myEventV.End.ToString().Substring(0,8)+Environment.NewLine+Environment.NewLine+"PRZENIOSLEM");
                            
                                }
                                p_krok="krok107";
                                myEventV.Copy(vTrack,myEventV.Start);//jest ok
                                p_krok="krok108";
                                //goto poczatek_event;
                                myVegas.UpdateUI();        
                            }
                            else
                            {
                                p_krok="krok109";
                                if (pokaz_logi2)
                                {
                                MessageBox.Show("START_INT="+tablica_splitow_start[i].ToString().Substring(0,8)+Environment.NewLine+Environment.NewLine+
                                                "myEventV.Start="+myEventV.Start.ToString().Substring(0,8)+Environment.NewLine+Environment.NewLine+
                                                "END_INT="+tablica_splitow_koniec[i].ToString().Substring(0,8)+Environment.NewLine+Environment.NewLine+
                                                "myEventV.End="+myEventV.End.ToString().Substring(0,8));
                            
                                }    
                                p_krok="krok110";
                            }
                        }
                    }
                }
            }
        } //if (tablica_splitow_start.Length>0)
        
        
        myVegas.UpdateUI();        
        }
        catch (Exception eeee)
        {
            MessageBox.Show("Blad krok="+p_krok+Environment.NewLine+Environment.NewLine+eeee.ToString());
        }
            
            
    }
}

 

If you are bored, drink water, you will want to pee. -> Albert Einstein - my idol!

I am 42. I have been creating videos since 2009 (the date when my first daughter was born in). My first video software was Pinnacle, next one was Sony Vegas 8 (I am not sure if remember it correctly). I am also a developer and wedding movie operator and editor. For example: I have created an Android app which let me control Vegas Pro rendering progress level on Android smartphone. I created it for fun, because I also love programming. I also created my own plugin for Audio To Text feature specified usage from Vegas Pro 19. I created proxy creation plugin which uses multiple GPU threads (maximum 3) to create proxy files for Vegas Pro. I also written many others plugin/softwares which enhance my video editing, also wedding editing.

Camera/video camera: Sony FX3, Sony A7 III, Sony FDR AX 100, Canon 5D Mark III, GoPro Hero Black 7,8,9,10

Lenses for Sony: Tamron 28-75mm F/2.8 Di III , Sony 24mm gm 1.4 FE, Sony 20 mm G FE 1.8

Lenses for Canon: Canon EF 24-70 mm F/2.8 L USM, Canon 70-200 f/2.8 L

Drone: DJI Mavic 3 & DJI Phantom 4 Pro v2.0

 

Editing: Vegas Pro 20 (365) with a lot of third party plugins, also my own plugins written in C#

 

PC:

CPU: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz   3.31 GHz

RAM: 128 GB

GPU: Nvidia RTX 2080 TI

storage: 4 SSD drives (including two M.2 flash drives) and two HDD drives

Windows system: 10 Home edition