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(); }