📝⚙️(Script) Add Medias Between Marker

m3lquixd wrote on 4/27/2023, 9:26 AM

It would be very useful a script that we could add media between the markers that we add between the events.

 

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 7 5700G 3.80 GHz
RAM:
    32,0GB Dual-Channel DDR4 3200MHz
Motherboard:
    ASRock B450M Steel Legend (AM4)
Graphics:
    MSI RTX 4060 Ventus 2X Black OC 8GB
Storage:
    476GB ADATA SU650 (SATA (SSD))
    931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

Comments

jetdv wrote on 4/27/2023, 10:50 AM

Check this out... Will use the selected video track if a video track is selected - otherwise it will create a new video track. Once all the markers have been processed, the rest of the selected media (if there are more) will be placed at the END of that track at their default lengths.
 

using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;
        private string[] filenames;
        VideoTrack vTrack;

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            string basePath = "D:\\VMedia\\";

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = basePath;
            ofd.Filter = "Media File (*.jpg; *.png; *.gif; *.AVI; *.wmv; *.m2t; *.m2ts; *.mov; *.mpg; *.mp4)|*.jpg; *.png; *.gif; *.AVI; *.wmv; *.m2t; *.m2ts; *.mov; *.mpg; *.mp4|All Files(*.*)|*.*";
            ofd.Multiselect = true;
            ofd.Title = "Select the media to use";
            DialogResult dr = ofd.ShowDialog();
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                filenames = ofd.FileNames;
                vTrack = null;
                foreach(Track myTrack in myVegas.Project.Tracks)
                {
                    if (myTrack.IsVideo() && myTrack.Selected)
                    {
                        vTrack = (VideoTrack)myTrack;
                        break;
                    }
                }
                if (vTrack == null)
                {
                    vTrack = new VideoTrack(0, "Added Media");
                    myVegas.Project.Tracks.Add(vTrack);
                }

                int currentFile = 0;
                for(int i=0; i<myVegas.Project.Markers.Count - 1; i++)
                {
                    if (currentFile >= filenames.Length)
                        break;
                    AddFile(filenames[currentFile], i);
                    currentFile++;
                }
                for(int i=currentFile; i<filenames.Length; i++)
                {
                    AddFile(filenames[i], -1);
                }
            }
        }

        public void AddFile(string filename, int MarkerNum)
        {
            Timecode startPos;
            Timecode length;
            Media myMedia = new Media(filename);
            if (MarkerNum >= 0)
            {
                startPos = myVegas.Project.Markers[MarkerNum].Position;
                length = myVegas.Project.Markers[MarkerNum + 1].Position - startPos;
            }
            else
            {
                startPos = vTrack.Length;
                length = myMedia.Length;
            }

            if (myMedia.HasVideo())
            {
                MediaStream stream = myMedia.Streams.GetItemByMediaType(MediaType.Video, 0);
                if (null != stream)
                {
                    VideoEvent myNewVideoEvent = new VideoEvent(startPos, length);
                    vTrack.Events.Add(myNewVideoEvent);
                    Take myNewTake = new Take(stream);
                    myNewVideoEvent.Takes.Add(myNewTake);
                }
            }

        }

    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

 

m3lquixd wrote on 4/27/2023, 11:42 AM

@jetdv It worked, it's inserting correctly. But, despite the mp4 and mov options appearing, it is only inserting image files, I would like it to be able to insert any type of media, such as: videos and audios. Mostly video.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 7 5700G 3.80 GHz
RAM:
    32,0GB Dual-Channel DDR4 3200MHz
Motherboard:
    ASRock B450M Steel Legend (AM4)
Graphics:
    MSI RTX 4060 Ventus 2X Black OC 8GB
Storage:
    476GB ADATA SU650 (SATA (SSD))
    931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

m3lquixd wrote on 4/27/2023, 11:44 AM


The options appear here, but it does not show the videos in the explorer.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 7 5700G 3.80 GHz
RAM:
    32,0GB Dual-Channel DDR4 3200MHz
Motherboard:
    ASRock B450M Steel Legend (AM4)
Graphics:
    MSI RTX 4060 Ventus 2X Black OC 8GB
Storage:
    476GB ADATA SU650 (SATA (SSD))
    931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

jetdv wrote on 4/27/2023, 11:58 AM

I tried it with video files and it worked just fine...

It does NOT work with audio. This is a video only tool as it stands right now.

m3lquixd wrote on 4/27/2023, 12:05 PM


What is going on? 😥

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 7 5700G 3.80 GHz
RAM:
    32,0GB Dual-Channel DDR4 3200MHz
Motherboard:
    ASRock B450M Steel Legend (AM4)
Graphics:
    MSI RTX 4060 Ventus 2X Black OC 8GB
Storage:
    476GB ADATA SU650 (SATA (SSD))
    931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

jetdv wrote on 4/27/2023, 12:39 PM

Change the filter line to read:

ofd.Filter = "Media File (*.jpg; *.png; *.gif; *.AVI; *.wmv; *.m2t; *.m2ts; *.mov; *.mpg; *.mp4)|*.jpg; *.png; *.gif; *.AVI; *.wmv; *.m2t; *.m2ts; *.mov; *.mpg; *.mp4|All Files(*.*)|*.*";

 

m3lquixd wrote on 4/27/2023, 1:00 PM

@jetdv Okay, now it's working fine!

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 7 5700G 3.80 GHz
RAM:
    32,0GB Dual-Channel DDR4 3200MHz
Motherboard:
    ASRock B450M Steel Legend (AM4)
Graphics:
    MSI RTX 4060 Ventus 2X Black OC 8GB
Storage:
    476GB ADATA SU650 (SATA (SSD))
    931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

m3lquixd wrote on 4/27/2023, 1:02 PM

@jetdv Could you change your answer, with the change? So I can mark it as a solution, please.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 7 5700G 3.80 GHz
RAM:
    32,0GB Dual-Channel DDR4 3200MHz
Motherboard:
    ASRock B450M Steel Legend (AM4)
Graphics:
    MSI RTX 4060 Ventus 2X Black OC 8GB
Storage:
    476GB ADATA SU650 (SATA (SSD))
    931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

jetdv wrote on 4/27/2023, 1:04 PM

Done...

m3lquixd wrote on 4/27/2023, 1:22 PM

Perfect! Thank you very much!

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 7 5700G 3.80 GHz
RAM:
    32,0GB Dual-Channel DDR4 3200MHz
Motherboard:
    ASRock B450M Steel Legend (AM4)
Graphics:
    MSI RTX 4060 Ventus 2X Black OC 8GB
Storage:
    476GB ADATA SU650 (SATA (SSD))
    931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

minhhienvz wrote on 5/26/2023, 10:51 PM

How to add media files from the cursor position? I want to add more media files but it only starts from the first marker. @jetdv

Done...

 

jetdv wrote on 5/27/2023, 7:40 AM

@minhhienvz, the script above specifically states the marker position as the starting position:

startPos = myVegas.Project.Markers[MarkerNum].Position;

You can easily change that to the cursor position:

startPos = myVegas.Transport.CursorPosition;

That would be correct for the first one. But in subsequent files, you would want to add them after the event just added so you'll need to set the start position to the end of that last event or move the cursor to after that event.

If you look through the tutorials, there are others that use the cursor position as the target location.

minhhienvz wrote on 5/27/2023, 9:03 AM

@minhhienvz, the script above specifically states the marker position as the starting position:

startPos = myVegas.Project.Markers[MarkerNum].Position;

You can easily change that to the cursor position:

startPos = myVegas.Transport.CursorPosition;

That would be correct for the first one. But in subsequent files, you would want to add them after the event just added so you'll need to set the start position to the end of that last event or move the cursor to after that event.

If you look through the tutorials, there are others that use the cursor position as the target location.

Thank you, that's what I was looking for !