Add clip to timeline

Roman wrote on 4/13/2006, 11:04 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

Comments

JohnnyRoy wrote on 4/13/2006, 11:22 AM
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 wasn’t 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
Roman wrote on 4/13/2006, 1:10 PM
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
JohnnyRoy wrote on 4/13/2006, 2:31 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