Time Lapse Script (Delete all but n frames from each event)

johnmeyer wrote on 10/22/2003, 1:10 PM

/**
*
* The script will use exactly one frame from each event on the selected video track,
* and delete everything else. All gaps between events will be eliminated,
* resulting in a single smooth movie.
*
* Each event should be from a discrete, separate video file (i.e., make sure
* "Enable DV Scene Detection" is checked in Vegas Capture).
*
* The script could probably be modified to work on a single file that has been
* broken up into events, but I didin't have time to figure out how to do this, and
* I figure most time lapse captures would be captured into separate files for each clip
*
* The main use envisioned for this script is the creation of true time
* lapse movies from the multiple one-second clips that many camcorders
* record when put in "time-lapse" mode.
*
* A video track must be selected. If an audio track is selected, nothing happens.
* Only the first selected track is affected. If more than one video track is selected,
* subsequent tracks are ignored.
*
* This script uses the LAST frame(s) in the event on the theory that the first frame from
* a time lapse capture may be slightly corrupted from tape startup glitches.
*
* Written By: John Meyer
* Written: October 22, 2003
*
**/

import System;
import System.IO;
import System.Windows.Forms;
import SonicFoundry.Vegas;


/**
**************************************************************************
* Start of main program *
**************************************************************************
**/

try {

//Change the next line to set the number of frames to keep.
var SaveFrames : Timecode = new Timecode("00:00:00:01"); //This is 1 frame.
var DeleteTime : double = SaveFrames.ToMilliseconds(); // Convert frames to milliseconds.

//Global declarations
var dStart : Double;
var trackEnum : Enumerator;
var evnt : TrackEvent;

//Use the FindSelectedTrack() function to find the first selected track.

var track = FindSelectedTrack();
var eventEnum = new Enumerator(track.Events);

if (track.IsVideo()) { // Proceed only if selected track is a video track.
TrimEvent(); // Function that "trims" event down to "n" frames
}
Vegas.UpdateUI();

} catch (e) {
MessageBox.Show(e);
}

// End of main program

// ***********************************************************************

// Beginning of functions

/**
**************************************************************************
* This function finds the first selected track *
**************************************************************************
**/

function FindSelectedTrack() : Track {
trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());
if (track.Selected) {
return track;
}
trackEnum.moveNext();
}
return null;
}


/**
***************************************************************************
* The following function trims all events on the selected track *
* by "n" (usually 1) frame(s). Only the LAST n frames in the event remain.*
***************************************************************************
**/

function TrimEvent() {

dStart = 0; // Initialize the starting point.

//Go through each event on the track.

while (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item()); // Get the next event on the timeline.
evnt.AdjustStartLength(new Timecode(dStart), new Timecode(DeleteTime), true);
dStart = evnt.Start.ToMilliseconds()+ DeleteTime; // Next event will start at end of this event.
eventEnum.moveNext(); // Go to next event on this timeline.
}

return null;
}

Comments

taliesin wrote on 10/22/2003, 3:21 PM
Wow, works great. Thanks John!!!

Marco
johnmeyer wrote on 10/22/2003, 3:23 PM
You're welcome.

I was amazed, since I don't do this much, that it only took a few minutes to adapt an old script to do this. I had actually thought of doing this a few weeks ago for another reason, and when I saw someone in the Vegas forum actually using the silly one second "time lapse" clips and trying to do real time lapse with them, I figured it was time to give that poor soul some help.
RichMacDonald wrote on 10/27/2003, 9:37 AM
>when I saw someone in the Vegas forum actually using the silly one second "time lapse" clips and trying to do real time lapse with them, I figured it was time to give that poor soul some help.

Since I resemble that remark, thanks :-)

So with a 0.5, 1, or 2 second "time lapse" clip, I'll be getting a speedup factor of 15, 30, or 60. Perhaps a little fast for my needs, but I'll give it a try and its always good to have another tool in the bag.

Or perhaps one might modify the script to keep every n'th frame. That might be a good way to get around the unfortunate max threefold speedup in Vegas. Hmm :-)

Incidentally, why is the "time lapse" approach silly? I do a lot of this where the camera is out there all day. Too long for a 60min tape and too far away from a power supply for some laptop n'th frame streaming capture alternative. Sure, the "stop/start" camera approach leads to jerky video at some speeds, but afaik its the only game in town for me.

Anyway, much obliged.
johnmeyer wrote on 10/27/2003, 10:19 AM
I figured it was time to give that poor soul some help. ... "Since I resemble that remark, thanks :-)"

Oops, that does sound a little insulting, doesn't it? Sorry Rich.

Incidentally, why is the "time lapse" approach silly?

I called it silly because it really isn't true time lapse, and the results are anything but smooth. The only reason the camcorder operates this way is that it is pretty tough to start/stop videotape for just one frame, and then stop for a minute or two.

The real problem is during playback. You've done it, so you know what it looks like. It looks exactly like what it is: One second of motion, then a jump cut; one second of motion, then a jump cut; etc. It sure isn't timelapse.

You are correct that using only one frame from each "take" is going to result in a clip that goes by way too fast. However, I think you will find that rendering the results of my script and then using Vegas to slow that down will result in much truer looking time lapse.

The script does allow you to take more than one frame from each take, so you can do things that way if you prefer. It is true that, if you use more than one frame per event, that those are all contiguous (next to each other). However, since you are using frames from a one second clip, followed by frames from a one second clip taken a minute later, the difference from taking the last "n" frames in the clip, and taking an equally dispersed "n" frames from the same clip, will probably not be noticeable.

If you decide to try the script, try it both ways (i.e., sample one frame, render result, then put back on timeline and slow down in Vegas; then, sample "n" frames, so no Vegas slow down is needed).

Of course, as I've said in other posts, if you really want to do professional time lapse, use Scenalyzer to capture directly to a computer (use a laptop if you're in the field). The results are perfect.
RichMacDonald wrote on 10/27/2003, 1:56 PM
>Oops, that does sound a little insulting, doesn't it? Sorry Rich.

It was funny, not insulting :-)

>I called it silly because it really isn't true time lapse, and the results are anything but smooth.

No question about it. As you may remember, this conversation started because I was pondering ways to "morph" the two events to reduce that annoyance.

>However, I think you will find that rendering the results of my script and then using Vegas to slow that down will result in much truer looking time lapse.

I'm looking forward to testing it.

In case you missed my last posting, I'm now applying an overlap and simple transition between the two events. So, for example, if I have 2 second events, I use a 1 second overlaps. This greatly reduces the jerkiness, but it is replaced with a wierd "ghost-in-ghost-out" effect on transient objects. Its actually very cool, but its certainly not "time-lapse". And I use the 2-second-every-30-second setting on my camera, which is the "smoothest" source I can generate.

Additionally, you can sync the jerkiness to the beat of the accompanying music, so the viewer thinks it was intentional. But I digress...

>Of course, as I've said in other posts, if you really want to do professional time lapse, use Scenalyzer to capture directly to a computer (use a laptop if you're in the field). The results are perfect.

I bet they are. Now I just need a laptop and a 1,000 foot extension cord or portable generator :-)

Hmm. I wonder how much a powerinverter and car battery combo would cost? $30 for the powerinverter, $5 for the car battery hookups, a car battery, find a cheapo used laptop, add a beefy hard drive...maybe I can handle this :-) Hmm, need weather protection for it all; that plastic shopping bag I use as rain gear for my camera needs an upgrade....anyone know how long a car battery could run a laptop :-?

Anyway, thanks very much for the tool. I'll report back when I have a chance to test. It may be some time coming, though, as I've just finished all my time lapse work and I'm now busy editing a wedding slide show. But maybe I can sneak it in as I'm itching to try it.
JJKizak wrote on 11/3/2003, 6:37 PM
I have this real stupid question. How do I download this script as there is no heading on it.

JJK
jetdv wrote on 11/3/2003, 9:26 PM
Copy everything from the first /** to the last } in the first message. Paste it into notepad, and save it is "TimeLapse.js"
JJKizak wrote on 11/4/2003, 7:50 AM
Thanks

JJK