Can't copy split event

johnmeyer wrote on 6/22/2006, 1:13 PM
This problem has been hinted at in earlier posts. If I use this code:
var patch_frame : VideoEvent =  VideoEvent(evnt.Copy(VideoTrack(track),Vegas.Cursor));
to create a copy of an existing event, I can then use this line:
for (var i=patch_frame.Takes.Count - 1; i >= 0; i--) {
patch_frame.Takes[i].Offset = Vegas.Cursor - one_frame - evnt.Start;
}
to change the frame that displays at the event start.

HOWEVER, if I split the event on the timeline and then run the code on the event immediately after the split, the offset function doesn't work. Upon further inspection, it is clear that the copy function is copying the original unsplit event. Thus, the first frame of video is the first frame of video from the unsplit event, and NOT the first frame of video from the "new" event that is created by the split.

I still haven't figured out a workaround.


[Edit] Perhaps the problem is that I am not adding a take to this new event. However, since it is part of existing media, I am not sure how to get the media class for this object in order to add the take. I think I need to use code something like this:
       var stream = media.Streams[0];
var videoTake = new Take(videostream);
patch_frame.Takes.Add(videoTake);
but I don't know how to get "media" for the events that already exist.

Comments

JohnnyRoy wrote on 6/23/2006, 6:22 AM
> but I don't know how to get "media" for the events that already exist.

That’s because Events don’t have media. Takes have media. When you copy or split an event, all of the takes and their corresponding media are still associated with the copy or split so this is not your problem and you don’t have to add any takes.

To get the media for an event you need to:
var media : Media = trackEvent.ActiveTake.Media;
Or iterate through all of the takes to get all of the media.

Are you sure you are working with the correct event? When you split an event, the old event is the event on the left and the new event (that is returned from the split) is the event on the right.

~jr
johnmeyer wrote on 6/23/2006, 9:31 AM
I should have not mentioned the takes business. That is a red herring. And yes, I am working with the correct event because every time I run the script, the enum class gets recreated. The event gets selected by its proximity to the cursor. If the cursor timecode is within the bounds of the event, then that event is selected.

The script works perfectly for any media that is dragged to the timeline: It splits that media, correctly selects the event before that split, copies it, and then uses the last frame from that copy to place it immediately after the split. It then correctly shortens the event immediately after the split to "make room" for the one-frame event. Pretty neat way to "fix" a bad frame by duplicating the previous frame.

However, if the event has previously been split, either "manually" by me splitting it before running the script, or by having run the script on an earlier portion of the original event, then the copy of the event that gets made starts with the first frame of the original media, NOT the first frame of the event that was copied.

The entire problem is with the ".copy" method. I am pretty sure it contains a bug where it copies the entire media, rather than the specific event. I was hoping to find a workaround or another way to accomplish my goal. Doesn't look like I'm going to find one. I'll put this in my folder labeled "great script ideas that can't be done in Vegas." I have almost half a dozen that I started, only to find out you can't do it -- like incorporating a bitrate calculator into an MPEG render so you could set the average bitrate to create an encode that will "just" fit a single DVD.

jetdv wrote on 6/23/2006, 11:22 AM
I'm not seeing what you're seeing. I split and copy all the time in Excalibur. In fact, the "Fix Frame" tool splits out a frame and then copies it to either the frame before or frame after using the .copy command. (i.e. mynewEvent = evNext.Copy(evPrev.Track, CurrFrame);) and it is not going back to the first frame of the event.

However, as a workaround, couldn't you just change the offset of the new copy to be the offset of the original copy? Or maybe the changing of the offset mentioned in the first post is coming back with the wrong value? (i.e. not taking the original offset into account)
johnmeyer wrote on 6/23/2006, 11:22 AM
patch_frame.Takes[i].Offset = patch_frame.Takes[i].Offset + Vegas.Cursor - one_frame - evnt.Start;  // Make change for ALL takes.
Never program late at night.

Apparently the way a take offset works, that offset is a reference to the initial media and NOT to the event itself. Thus, if you look at the Takes[i].Offset for an event that hasn't been split, it will be zero. However, once the event has been split, then the offset equals the value needed to make the initial frame of the new event be one more than the last frame of the event at the cursor location prior to the split. The solution is therefore to use that initial offset as the starting point for the further shift needed to get to the last frame of the newly split event. The above line of code does that.

johnmeyer wrote on 6/23/2006, 11:39 AM
Ed,

We must have posted at the same time. Thanks for the help.

Didn't know you had this feature in Excalibur. Should have known.

BTW, is there any script you know of that demonstrates how to group events? It would be a nice touch to group these "fixup" frames with the two events that result from splitting, so they would move together during subsequent editing.
jetdv wrote on 6/23/2006, 11:43 AM
Yeah, I figured we were typing at the same time when I hit post and your message appeared at the same time as mine.

I group the missing audio/video back to the original in Excalibur. I'll get you the details.
jetdv wrote on 6/23/2006, 11:52 AM
You first create a new group, add that group to the project, and then add as many events as needed to that group.

//Group these two items together
TrackEventGroup grp = new TrackEventGroup();
Vegas.Project.Groups.Add(grp);
grp.Add(mynewEvent);
grp.Add(MyEvent);

johnmeyer wrote on 6/23/2006, 11:54 AM
Ed,

I wish I could IM you, so you don't waste any of your valuable time. I figured it out how to add an event to an existing group:
        if (evnt.IsGrouped) {
var grp : TrackEventGroup = evnt.Group;
grp.Add(evnt2);
grp.Add(patch_frame)
}
In this case, "evnt2" is the new event that results from the split operation, and "patch_frame" is the one frame event I created using the copy operation. This code groups them all together with the initial event and, most importantly with its audio.