Script To Remove First/Last Frames?

jrazz wrote on 9/5/2010, 10:56 AM
Was there ever one of these made that will remove them (first and last couple of frames) and butt the events back together again (or butt them back together with the use of Ripple Edit)?

I still deal with this issue when I capture- it always puts the first couple (or just one) frame of the next event on the event right before it. Thus causing me to have to remove them.

I know this has been discussed and I think that someone made a script- if so, please point me to it. Thanks.

j razz

Comments

Randy Brown wrote on 9/5/2010, 11:08 AM
Good question, I only recently moved to hi-def and have noticed this behavior...are you using a Canon XHA1 per chance or does Vegas Capture do this to all hi-def?
jrazz wrote on 9/5/2010, 11:37 AM
I'm using the Sony HVR-A1u's. I know it is a known issue amongst us on the forum, but I think it only affected some of us.

j razz
altarvic wrote on 9/5/2010, 12:56 PM
jrazz, I don't know whether there is a free script. But I know the paid tool, which can do what you want. Let me know if you are interested.
jrazz wrote on 9/5/2010, 2:16 PM
I'm interested. I don't usually have this as a problem as I don't always (hardly ever) use the last portions of an event, but this particular project I did.

j razz
altarvic wrote on 9/5/2010, 9:27 PM
OK, go to Vegasaur website, download it and install (You can freely use it for 30 days)

1) Select events that need to be processed. Go to View>Extensions>Vegasaur>Editing and
select Quick Properties tool. Open the Event Properties tab.
2) Select Starting Frame option to remove frames from the start of events, enter the desired number of frames. Make sure
that the Adjust Length option is also checked.
Select Length option to remove frames from the end of events, specify the number of frames and select Decrease mode
(do not select the Time stretch option)
Click here to preview
Click Apply button
3) Now all your events are trimmed. If you selected only video events on the first step then you'll see that they are not
synchronized with audio. Go to View>Extensions>Vegasaur>1-Click Commands and select Sync Audio to Video to fix it.
4) And the final step: Go to View>Extensions>Vegasaur>1-Click Commands and select Close Gaps (Selected Events)
to place the events next to each other
NickHope wrote on 9/5/2010, 11:00 PM
j razz, the original discussion about that is here.

Phil Hemel's excellent script to trim top and tail frames from clips on the timeline is now offline, and he hasn't posted here for 4 years. I've taken the liberty of posting the script here.

This topic comes around now and then, so if anyone has a more appropriate and permanent place to host this then please do so.

You must go into the script and edit the number of frames that you want to trim from the beginning and end.

By the way, I used to use this script to trim repeat frames from the end of clips that I had captured with HDVSplit, but since the Vegas HDV reader (codec) was improved (at about 8.0c) I haven't needed it.
jrazz wrote on 9/6/2010, 8:23 AM
Thanks Nick.

Yeah, I looked for it as I thought there was a "fix" out there. Also, thanks for sharing.

One thread I found that I read had your comments in it and your usage of HDVSplit. I used to use HDVSplit, but like the other poster on that thread, it invokes MainConcept instead of the Sony Codec.

Thanks for sharing, I will adjust the script for my needs.

j razz
NickHope wrote on 9/6/2010, 8:55 PM
j razz, when I capture from my Sony Z1P using HDVSplit, the captured files invoke the Sony Codec.
Malcolm D wrote on 9/6/2010, 11:35 PM
I think you may be thinking of a script by Edward Troxel 'jetdv'
called TrimFront+Back.js from 2008.
Follow it with the script DeleteSpaces.js
Try a search for them.
Malcolm
jetdv wrote on 9/7/2010, 7:05 AM
Trim front and back.js

/**
* This script will trim the front and back for all selected events.
*
* Written By: Edward Troxel
* Copyright 2004 - JETDV Scripts
* Modified: 08-03-2005
**/

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


var trimAmt = new Timecode("00:00:01:00");


try {

//Go through the list of Tracks
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());

//Go through the list of Events
var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd()) {
var evnt : TrackEvent = TrackEvent(eventEnum.item());

if (evnt.Selected) {
var dStart = evnt.Start + trimAmt;
var dLength = evnt.Length;

//Get current take offset
var tke = evnt.ActiveTake;
var tkeoffset = tke.Offset;
tkeoffset = tkeoffset + trimAmt;
evnt.Start = dStart;
tke.Offset = tkeoffset;

dLength = dLength - trimAmt - trimAmt;
evnt.Length = new Timecode(dLength);
}
eventEnum.moveNext();
}
trackEnum.moveNext();
}


} catch (e) {
MessageBox.Show(e);
}
NickHope wrote on 9/7/2010, 8:27 PM
For what it's worth, here's Phil Hemel's script Trim_Captured_Clips_v1.0.cs

Edit the number of frames to trim in lines 39 and 40, as you can see I have done.

/*

This script will remove the first two and the last three frames of each selected event.
Note that associated audio events also needs to be selected.
?@If multiple events are selected on the same track, they will be shifted to the left in order
to not get any gaps between the events.

This script has been verified using Sony HDR-HC3 (NTSC version), HDVSlit v0.75 (http://strony.aster.pl/paviko/hdvsplit.htm)
and Vegas version 7.0b.

Your camera and capture program might require a different number of frames to be removed.
In that case, make changes in the code below (the clipStartTrim and clipEndTrim variables).

The script has been verified using the project templates "HDV 1080-60i (1440x1080, 29.970 fps)" and "HDV 1080-50i (1440x1080, 25.000 fps)".
Other templates with either 29.970 fps or 25.000 fps should also work.

However, there is no quarantee that it works. Use it at your own risk.

Place this file in the following folder C:\Program Files\Sony\Vegas 7.0\Script Menu
In Vegas, execute Tools->Scripting->Rescan Script Menu Folder
This script will then be available at Tools->Scripting.

History:
v1.0 2006-10-15 Verfified that v0.9 also works for 25.000 fps (PAL).
v0.9 2006-10-14 First version. Supports 29.970 fps (NTSC).

*/

using System;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using Sony.Vegas;

public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Timecode clipStartTrim = Timecode.FromFrames(2); // Change here if different number of frames should be deleted at the beginning of the clip. Changed by Nick
Timecode clipEndTrim = Timecode.FromFrames(0); // Change here if different number of frames should be deleted at the end of the clip. Changed by Nick

Project proj = vegas.Project;
foreach (Track track in proj.Tracks)
{
Timecode totalTrim = Timecode.FromFrames(0);
foreach (TrackEvent trackEvent in track.Events)
{
if (!trackEvent.Selected)
continue;
Take activeTake = trackEvent.ActiveTake;
if (activeTake == null)
continue;
Media media = activeTake.Media;
if (media == null)
continue;

Timecode eventStart = trackEvent.Start;
Timecode eventEnd = trackEvent.Start + trackEvent.Length;
Timecode takeOffset = activeTake.Offset;

// Modify the beginning of the clip
takeOffset = takeOffset + clipStartTrim;
activeTake.Offset = takeOffset;

// Shift the clip to the left and make the starting point correct for a 29.970 fps project (as well as for 25.000 fps)
trackEvent.Start = Timecode.FromNanos(((((eventStart.Nanos - totalTrim.Nanos)*3 + 500)/1000)*1000)/3);

// Update how much the followin clip on the same track should be shifted.
totalTrim = totalTrim + clipStartTrim + clipEndTrim;

// Make the length correct for a 29.970 fps project (as well as for 25.000 fps)
trackEvent.Length = Timecode.FromNanos(((((eventEnd.Nanos - totalTrim.Nanos)*3 + 500)/1000)*1000)/3 - trackEvent.Start.Nanos);
}
}
}
}
john_dennis wrote on 12/19/2022, 4:42 PM

@NickHope

RE: Phil Hemel's script Trim_Captured_Clips_v1.0.cs

I'm working with media from a pocket camera that stopped recording audio four frames before the video. It was getting tedious trimming each clip before I did any real editing. Converting this script to run on current versions of Vegas has been invaluable to me.