[Resolved] Script to add media files to timeline?

jimmyeatsquaids wrote on 8/8/2020, 7:04 PM

Hi! I'm trying to figure out if there's a way in Sony Vegas Pro 13.0 to use a script to add music files to the timeline (to a specific audio track)

I'm trying to automate the tedious process that I go through daily of adding background music to my videos from a set of songs. For each video a random sequence of songs are used (already automated) but I can't figure out how to use the generated list of songs to automatically put them on the timeline in the correct order.

Alternatively I was first trying to use the "Automatically overlap multiple selected media when added" to at least get rid of some of the editing involved but here I run into the issue of Vegas not being able to import the files in the exact order I selected them (Windows 10 limitation?). I feel like I'm trying to do something very specific and I can't find a lot of help so I'd appreciate any suggestions.

Comments

wwaag wrote on 8/10/2020, 10:07 AM

Could you upload a sample playlist to something like DropBox so I can download and take a look? Or is it in a standard playlist format? Adding files to a specific audio track, even with an overlap, should require a relatively simple script.

AKA the HappyOtter at https://tools4vegas.com/. System 1: Intel i7-8700k with HD 630 graphics plus an Nvidia RTX4070 graphics card. System 2: Intel i7-3770k with HD 4000 graphics plus an AMD RX550 graphics card. System 3: Laptop. Dell Inspiron Plus 16. Intel i7-11800H, Intel Graphics. Current cameras include Panasonic FZ2500, GoPro Hero11 and Hero8 Black plus a myriad of smartPhone, pocket cameras, video cameras and film cameras going back to the original Nikon S.

Robert Johnston wrote on 8/10/2020, 4:25 PM

To maintain the order you selected the media, you will need to be in Detail view, not List or Thumbnail view. If you have already selected the media in List or Thumbnail view, you will need to reselect them in Detail view.

Last changed by Robert Johnston on 8/10/2020, 4:26 PM, changed a total of 1 times.

Intel Core i7 10700K CPU @ 3.80GHz (to 4.65GHz), NVIDIA GeForce RTX 2060 SUPER 8GBytes. Memory 32 GBytes DDR4. Also Intel UHD Graphics 630. Mainboard: Dell Inc. PCI-Express 3.0 (8.0 GT/s) Comet Lake. Bench CPU Multi Thread: 5500.5 per CPU-Z.

Vegas Pro 21.0 (Build 108) with Mocha Vegas

Windows 11 not pro

jimmyeatsquaids wrote on 8/10/2020, 6:33 PM

Could you upload a sample playlist to something like DropBox so I can download and take a look? Or is it in a standard playlist format? Adding files to a specific audio track, even with an overlap, should require a relatively simple script.

It's not a playlist, it's just multiple different audio files. I would love to know more about how I can get started with a script that achieves this.

To maintain the order you selected the media, you will need to be in Detail view, not List or Thumbnail view. If you have already selected the media in List or Thumbnail view, you will need to reselect them in Detail view.

Thank you so much for this suggestion, this helps a lot! It's not perfect but a nice step in the right direction!

wwaag wrote on 8/10/2020, 6:57 PM

"For each video a random sequence of songs are used (already automated) but I can't figure out how to use the generated list of songs to automatically put them on the timeline in the correct order."

You must have a list somewhere? The list defines the random sequence of files that are to be played.

AKA the HappyOtter at https://tools4vegas.com/. System 1: Intel i7-8700k with HD 630 graphics plus an Nvidia RTX4070 graphics card. System 2: Intel i7-3770k with HD 4000 graphics plus an AMD RX550 graphics card. System 3: Laptop. Dell Inspiron Plus 16. Intel i7-11800H, Intel Graphics. Current cameras include Panasonic FZ2500, GoPro Hero11 and Hero8 Black plus a myriad of smartPhone, pocket cameras, video cameras and film cameras going back to the original Nikon S.

jimmyeatsquaids wrote on 8/10/2020, 7:05 PM

"For each video a random sequence of songs are used (already automated) but I can't figure out how to use the generated list of songs to automatically put them on the timeline in the correct order."

You must have a list somewhere? The list defines the random sequence of files that are to be played.

The list is just a text file generated by a python script that I wrote. I did this so I wouldn't have to manually decide the music for each video and the python script makes sure no song gets repeated in 2 consecutive videos.

wwaag wrote on 8/10/2020, 7:10 PM

So what is in the text file? Could you upload or at least show an example of exactly its contents?

AKA the HappyOtter at https://tools4vegas.com/. System 1: Intel i7-8700k with HD 630 graphics plus an Nvidia RTX4070 graphics card. System 2: Intel i7-3770k with HD 4000 graphics plus an AMD RX550 graphics card. System 3: Laptop. Dell Inspiron Plus 16. Intel i7-11800H, Intel Graphics. Current cameras include Panasonic FZ2500, GoPro Hero11 and Hero8 Black plus a myriad of smartPhone, pocket cameras, video cameras and film cameras going back to the original Nikon S.

jimmyeatsquaids wrote on 8/11/2020, 4:39 AM

So what is in the text file? Could you upload or at least show an example of exactly its contents?

Here's an example:

"1. Hillside Plaza - Brazil Stage
2. Theme of Guile
3. Theme of Urien
4. Theme of Falke
5. Forgotten Waterfall - New Zealand Stage
6. Lifeformed - 9-bit Expedition [Dustforce OST]"

This format is used so I can just copy/paste it into the description of my Youtube videos. I can change it anytime to something better suited to work with a Sony Vegas script if that's what you had in mind.

wwaag wrote on 8/11/2020, 10:28 AM

To be able to import your audio files into Vegas in a specific order, all you need is a textfile that contains the filepaths in the order you want. For example,

D:\Music\MP3 Music_Disc 1\Wilson Pickett - Land Of 1000 Dances.mp3
D:\Music\MP3 Music_Disc 1\Wilson Pickett - In The Midnight Hour.mp3
D:\Music\MP3 Music_Disc 1\Wham - Everything She Wants.mp3
D:\Music\MP3 Music_Disc 1\Wham - Careless Whispers.mp3
D:\Music\MP3 Music_Disc 1\Wayne Fontana - Game Of Love.mp3
D:\Music\MP3 Music_Disc 1\Troggs - Wild Thing.mp3
D:\Music\MP3 Music_Disc 1\Trini Lopez - If I Had a Hammer.mp3
D:\Music\MP3 Music_Disc 1\Tornadoes 74 - Telstar.mp3

You should easily be able to do this in your python script.

A script could then be written that reads in your list of filepaths and for each item, adds it to the project media pool, creates an audio event on your selected track and then adds the item as the Active Take for the newly created event.

 

AKA the HappyOtter at https://tools4vegas.com/. System 1: Intel i7-8700k with HD 630 graphics plus an Nvidia RTX4070 graphics card. System 2: Intel i7-3770k with HD 4000 graphics plus an AMD RX550 graphics card. System 3: Laptop. Dell Inspiron Plus 16. Intel i7-11800H, Intel Graphics. Current cameras include Panasonic FZ2500, GoPro Hero11 and Hero8 Black plus a myriad of smartPhone, pocket cameras, video cameras and film cameras going back to the original Nikon S.

jimmyeatsquaids wrote on 8/11/2020, 2:23 PM

To be able to import your audio files into Vegas in a specific order, all you need is a textfile that contains the filepaths in the order you want. For example,

D:\Music\MP3 Music_Disc 1\Wilson Pickett - Land Of 1000 Dances.mp3
D:\Music\MP3 Music_Disc 1\Wilson Pickett - In The Midnight Hour.mp3
D:\Music\MP3 Music_Disc 1\Wham - Everything She Wants.mp3
D:\Music\MP3 Music_Disc 1\Wham - Careless Whispers.mp3
D:\Music\MP3 Music_Disc 1\Wayne Fontana - Game Of Love.mp3
D:\Music\MP3 Music_Disc 1\Troggs - Wild Thing.mp3
D:\Music\MP3 Music_Disc 1\Trini Lopez - If I Had a Hammer.mp3
D:\Music\MP3 Music_Disc 1\Tornadoes 74 - Telstar.mp3

You should easily be able to do this in your python script.

A script could then be written that reads in your list of filepaths and for each item, adds it to the project media pool, creates an audio event on your selected track and then adds the item as the Active Take for the newly created event.

 

Yeah it would very easy to change it in my python script. The part that gives me a headache though is the Sony Vegas script... I briefly looked over the "VEGAS Pro Scripting API Summary" and I can't figure out how to add a file to an audio track. Most scripts that I saw work with existing media in the timeline and simply check whether it's a video or audio track to perform a specific task on. That's another part I'm not sure about: How do I perform a task ONLY on a specific audio track?

I feel like I would to spend a lot more time with the API to get this done lol

jetdv wrote on 8/11/2020, 7:03 PM

Well... adding audio to a track is really fairly simple. This is an example (I'm using another routine to find the track but you wouldn't need to do that. You could easily specify which track but this gives you an idea of how it's done).

                if (mymedia.HasAudio())
                {
                    Atrack = (AudioTrack)FindTrack(titleName, false);                    //Do we need a audio track? And did we find one?
                    MediaStream astream = mymedia.Streams.GetItemByMediaType(MediaType.Audio, 0);
                    if (null != astream)
                    {
                        myNewAudioEvent = new AudioEvent(starttime, astream.Length);
                        if (Atrack == null)
                        {
                            Atrack = new AudioTrack(999, titleName);  // Using number 999 so it will add it "last"
                            myvegas.Project.Tracks.Add(Atrack);
                        }
                        Atrack.Events.Add(myNewAudioEvent);
                        Take myNewAtake = new Take(astream);
                        myNewAudioEvent.Takes.Add(myNewAtake);
                    }
                }

You'll also need to reset the "starttime" to the correct value at the beginning and add the "length" to the "starttime" after each one is added. If you want them to crossfade, you could add a little less than the full "length" to the "starttime".

jimmyeatsquaids wrote on 8/12/2020, 1:11 PM

@wwaag was so kind to DM me a solution to my problem! I really appreciate all the help I received here!