Add clip to timeline

Post » Wed Jul 21, 2010 4:30 am

Hi,

I am trying to do something very basic. Create a new project. Import one video clip. Put that clip on a timeline. Then crop the clip at the beginning and the end by 5 seconds and put a fade in and a fade out. then export to different file types.

So afer I do this...
Vegas.NewProject(false, false);
var myMedia = new Media("E:\myVideo.avi");

How do I add that media clip to the timeline?

Thanks,
-Roman
User avatar
Eire Charlotta
 
Posts: 498
Joined: Thu Nov 09, 2006 12:00 pm

Post » Tue Jul 20, 2010 7:21 pm

First you need to add a video track to the project with something like:
VideoTrack videoTrack = new VideoTrack(0, "Video");
vegas.Project.Tracks.Add(videoTrack);
Then here is a C# routine that will add a file to a video track and return the newly created event or a null if the media wasnt valid:
public VideoEvent AddVideoMediaToTrack(string filename, VideoTrack track)
{
VideoEvent videoEvent = null;

Media media = new Media(filename);
if (media.IsValid())
{
videoEvent = new VideoEvent(); // create a new video event
track.Events.Add(videoEvent); // add it to the track

// Get the stream for this event so we can add a take
MediaStream stream = media.Streams.GetItemByMediaType(MediaType.Video, 0);

// Add the media to the event as a take
videoEvent.Takes.Add(new Take(stream, true));
}
return videoEvent;
}
The key is you have to add an event and then add at least one Take to the event.

~jr
User avatar
teeny
 
Posts: 516
Joined: Sat Feb 24, 2007 7:51 pm

Post » Wed Jul 21, 2010 12:37 am

Thank you very much for the routine. I just tried it out,

and I am getting an error "Error: media stream not specified"
Any idea?

(unfortunately I am still waiting on getting Visual Studio installed, so I am doing this in javaScript for now..., they do translate pretty effortelessly, but JS is harder to debug)

import System;
import System.IO;
import System.Windows.Forms;
import System.Collections;
import Sony.Vegas;

try
{
//create a new project
Vegas.NewProject(false, false);

//add an audio and video tracks
var myVideoTrack = new VideoTrack();
Vegas.Project.Tracks.Add(myVideoTrack);
var myAudioTrack = new AudioTrack();
Vegas.Project.Tracks.Add(myAudioTrack);

//link to media clip
var myMedia = new Media("E:\myVideo.avi");
if(myMedia.IsValid())
{
//create a video event
var myVideoEvent = new VideoEvent();

// add it to the track
myVideoTrack.Events.Add(myVideoEvent);

// Get the stream for this event so we can add a take
var myMediaStream = myMedia.Streams.GetItemByMediaType(MediaType.Video, 0);

//create a new take with the mediaStream
var myTake = new Take(myMediaStream, true);

// Add the media to the event as a take
myVideoEvent.Takes.Add(myTake);
}
}
catch (e)
{
MessageBox.Show(e);
}

Thanks,
-Roman
User avatar
e.Double
 
Posts: 525
Joined: Tue Jul 24, 2007 5:17 pm

Post » Tue Jul 20, 2010 4:41 pm

If that is really the code then you need to escape the \ character to turn this:
var myMedia = new Media("E:\myVideo.avi");
into this:
var myMedia = new Media("E:\\myVideo.avi");
~jr
User avatar
Quick Draw
 
Posts: 523
Joined: Sat Sep 29, 2007 10:56 pm


Return to Vegas Pro Forum