NEED HELP Scripting : Transcoding Media Withing VEGAS

iEmby wrote on 8/8/2024, 5:43 AM

Just check out my following script

and see why it is muting audio event before rendering.

i want

  • i select a full or partial event even i select its only audio stream or video stream or both.
  • it should find the media related to that
  • then it should added the detecting media to timeline, from starting of project in new video/audio tracks.
  • then it remember all mute/unmute states of existing tracks
  • then it mute all track except new ones
  • then it select the timeline as per the added media length
  • then it should render it as per render template with a suffix (this is just part of that)
  • after render it should find output transcoded file.
  • then it should replace this transcoded media with the original media in media pool.
  • and then remove new tracks and get back to original mute/unmute state of existing tracks

 

ok all going good

but it is muting audio event before rendering

please take a look and tell me what is wrong in it..

        private void TranscodeMedia(RenderTemplate renderTemplate, string fileExtension)
        {
            List<TrackEvent> selectedEvents = GetSelectedEvents(vegas);
            if (selectedEvents == null || selectedEvents.Count == 0)
            {
                MessageBox.Show("No Event Selected.", "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            List<Media> selectedMediaList = new List<Media>();

            foreach (TrackEvent ev in selectedEvents)
            {
                foreach (Take take in ev.Takes)
                {
                    Media media = take.Media;
                    if (media != null && !selectedMediaList.Contains(media))
                    {
                        selectedMediaList.Add(media);
                    }
                }
            }

            DialogResult result = MessageBox.Show("Replace the original media with the transcoded media?", "Replace Media", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            bool replaceMedia = (result == DialogResult.Yes);

            Dictionary<Track, bool> originalMuteStates = new Dictionary<Track, bool>();
            foreach (Track track in vegas.Project.Tracks)
            {
                originalMuteStates[track] = track.Mute;
                track.Mute = true; // Mute all existing tracks
            }

            foreach (Media media in selectedMediaList)
            {
                if (media == null)
                {
                    MessageBox.Show("Selected event has no media linked!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    continue;
                }

                Timecode newEventStart = new Timecode(0);

                VideoTrack videoTrack = new VideoTrack(vegas.Project.Tracks.Count, "TranscodeVideoTrack");
                vegas.Project.Tracks.Add(videoTrack);
                AudioTrack audioTrack = new AudioTrack(vegas.Project.Tracks.Count + 1, "TranscodeAudioTrack");
                vegas.Project.Tracks.Add(audioTrack);

                videoTrack.Mute = false;
                audioTrack.Mute = false;

                TrackEvent newVideoEvent = videoTrack.AddVideoEvent(newEventStart, media.Length);
                TrackEvent newAudioEvent = audioTrack.AddAudioEvent(newEventStart, media.Length);

                MediaStream videoStream = media.GetVideoStreamByIndex(0);
                MediaStream audioStream = media.GetAudioStreamByIndex(0);

                if (videoStream != null)
                {
                    newVideoEvent.AddTake(videoStream);
                    newVideoEvent.Mute = false; // Unmute video event
                }

                if (audioStream != null)
                {
                    newAudioEvent.AddTake(audioStream);
                    newAudioEvent.Mute = false; // Unmute audio event
                }

                string mediaDirectory = Path.GetDirectoryName(media.FilePath);
                string outputFileName = $"{Path.GetFileNameWithoutExtension(media.FilePath)}_transcoded{fileExtension}";
                string outputFilePathForMedia = Path.Combine(mediaDirectory, outputFileName);

                RenderArgs renderArgs = new RenderArgs
                {
                    OutputFile = outputFilePathForMedia,
                    RenderTemplate = renderTemplate,
                    Start = newEventStart,
                    Length = media.Length
                };

                RenderProject(renderArgs);

                if (replaceMedia)
                {
                    Media newMedia = new Media(outputFilePathForMedia);

                    foreach (TrackEvent ev in selectedEvents)
                    {
                        foreach (Take take in ev.Takes)
                        {
                            if (take.Media == media)
                            {
                                take.Media.ReplaceWith(newMedia);
                            }
                        }
                    }
                }

                // Remove the temporary events and tracks after rendering
                videoTrack.Events.Remove(newVideoEvent);
                audioTrack.Events.Remove(newAudioEvent);
                vegas.Project.Tracks.Remove(videoTrack);
                vegas.Project.Tracks.Remove(audioTrack);
            }

            foreach (KeyValuePair<Track, bool> trackMuteState in originalMuteStates)
            {
                trackMuteState.Key.Mute = trackMuteState.Value;
            }

            vegas.UpdateUI();
        }

 

Last changed by iEmby

PROCESSOR
     

Operating System: Windows 11 Pro 64-bit (Always Updated)
System Manufacturer: ASUS
12th Gen Intel(R) Core(TM) i7-12700 (20 CPUs), ~2.1GHz - 4.90GHz
Memory: 32GB RAM
Page File: 11134MB used, 7934MB Available
DirectX Version: DirectX 12

-----------------------------------------------

MOTHERBOARD

 

ASUS PRIME H610-CS D4
Intel® H610 (LGA 1700)
Ready for 12th Gen Intel® Processors
Micro-ATX Motherboard with DDR4
Realtek 1 Gb Ethernet
PCH Heatsink
PCIe 4.0 | M.2 slot (32Gbps) 
HDMI® | D-Sub | USB 3.2 Gen 1 ports
SATA 6 Gbps | COM header
LPT header | TPM header
Luminous Anti-Moisture Coating
5X Protection III
(Multiple Hardware Safeguards
For all-round protection)

-----------------------------------------------
EXTERNAL GRAPHIC CARD

-----------------------------------------------

INTERNAL GRAPHIC CARD (iGPU)

------------------------------------------------

LED - MONITOR

Monitor Name: Generic PnP Monitor
Monitor Model: HP 22es
Monitor Id: HWP331B
Native Mode: 1920 x 1080(p) (60.000Hz)
Output Type: HDMI

-----------------------------------------------

STORAGE DRIVE

Drive: C:
Free Space: 182.3 GB
Total Space: 253.9 GB
File System: NTFS
Model: WD Blue SN570 1TB (NVMe)

---------------O----------------

My System Info (PDF File).

https://drive.google.com/open?id=1-eoLmuXzshTRH_8RunAYAuNocKpiLoiV&usp=drive_fs

 

Also Check

VEGAS Scripts Collection By Me

GitHub Profile

My YouTube Channel Dedicated to Only VEGAS Pro Tutorials

EDITROOM : My YouTube Channel (For VEGAS Tutorials)

Comments

iEmby wrote on 8/8/2024, 5:44 AM

@zzzzzz9125 @jetdv please check.

PROCESSOR
     

Operating System: Windows 11 Pro 64-bit (Always Updated)
System Manufacturer: ASUS
12th Gen Intel(R) Core(TM) i7-12700 (20 CPUs), ~2.1GHz - 4.90GHz
Memory: 32GB RAM
Page File: 11134MB used, 7934MB Available
DirectX Version: DirectX 12

-----------------------------------------------

MOTHERBOARD

 

ASUS PRIME H610-CS D4
Intel® H610 (LGA 1700)
Ready for 12th Gen Intel® Processors
Micro-ATX Motherboard with DDR4
Realtek 1 Gb Ethernet
PCH Heatsink
PCIe 4.0 | M.2 slot (32Gbps) 
HDMI® | D-Sub | USB 3.2 Gen 1 ports
SATA 6 Gbps | COM header
LPT header | TPM header
Luminous Anti-Moisture Coating
5X Protection III
(Multiple Hardware Safeguards
For all-round protection)

-----------------------------------------------
EXTERNAL GRAPHIC CARD

-----------------------------------------------

INTERNAL GRAPHIC CARD (iGPU)

------------------------------------------------

LED - MONITOR

Monitor Name: Generic PnP Monitor
Monitor Model: HP 22es
Monitor Id: HWP331B
Native Mode: 1920 x 1080(p) (60.000Hz)
Output Type: HDMI

-----------------------------------------------

STORAGE DRIVE

Drive: C:
Free Space: 182.3 GB
Total Space: 253.9 GB
File System: NTFS
Model: WD Blue SN570 1TB (NVMe)

---------------O----------------

My System Info (PDF File).

https://drive.google.com/open?id=1-eoLmuXzshTRH_8RunAYAuNocKpiLoiV&usp=drive_fs

 

Also Check

VEGAS Scripts Collection By Me

GitHub Profile

My YouTube Channel Dedicated to Only VEGAS Pro Tutorials

EDITROOM : My YouTube Channel (For VEGAS Tutorials)

jetdv wrote on 8/8/2024, 7:47 AM

You're not replacing the media in the project media.

iEmby wrote on 8/8/2024, 4:28 PM

Thankyou for ur response sir..
it was my mistake in my other code in full script.

i solved it... thanks for response.

PROCESSOR
     

Operating System: Windows 11 Pro 64-bit (Always Updated)
System Manufacturer: ASUS
12th Gen Intel(R) Core(TM) i7-12700 (20 CPUs), ~2.1GHz - 4.90GHz
Memory: 32GB RAM
Page File: 11134MB used, 7934MB Available
DirectX Version: DirectX 12

-----------------------------------------------

MOTHERBOARD

 

ASUS PRIME H610-CS D4
Intel® H610 (LGA 1700)
Ready for 12th Gen Intel® Processors
Micro-ATX Motherboard with DDR4
Realtek 1 Gb Ethernet
PCH Heatsink
PCIe 4.0 | M.2 slot (32Gbps) 
HDMI® | D-Sub | USB 3.2 Gen 1 ports
SATA 6 Gbps | COM header
LPT header | TPM header
Luminous Anti-Moisture Coating
5X Protection III
(Multiple Hardware Safeguards
For all-round protection)

-----------------------------------------------
EXTERNAL GRAPHIC CARD

-----------------------------------------------

INTERNAL GRAPHIC CARD (iGPU)

------------------------------------------------

LED - MONITOR

Monitor Name: Generic PnP Monitor
Monitor Model: HP 22es
Monitor Id: HWP331B
Native Mode: 1920 x 1080(p) (60.000Hz)
Output Type: HDMI

-----------------------------------------------

STORAGE DRIVE

Drive: C:
Free Space: 182.3 GB
Total Space: 253.9 GB
File System: NTFS
Model: WD Blue SN570 1TB (NVMe)

---------------O----------------

My System Info (PDF File).

https://drive.google.com/open?id=1-eoLmuXzshTRH_8RunAYAuNocKpiLoiV&usp=drive_fs

 

Also Check

VEGAS Scripts Collection By Me

GitHub Profile

My YouTube Channel Dedicated to Only VEGAS Pro Tutorials

EDITROOM : My YouTube Channel (For VEGAS Tutorials)