Here is a script that will let you quickly "fix" a bad frame of video. The audio is unaffected.
/**
* PURPOSE OF THIS SCRIPT:
*
* Fix a bad video frame by deleting bad frame and replacing with previous frame.
*
* A video track must be selected. If an audio track is selected, nothing happens.
*
* To use, select the event that contains the bad frame. Position the cursor so you can
* see the bad frame in the preview window. Then, run the script.
*
* Copyright © John Meyer 2006
* Written: June 23, 2006
*
* Tested on Vegas 6.0d and 5.0d. Will NOT work on Vegas 4.
*
**/
import System;
import System.IO;
import System.Windows.Forms;
import Sony.Vegas;
try {
//Global declarations
var dStart : Double;
var dLength : Double;
var dCursor : Double;
var trackEnum : Enumerator;
var evnt : VideoEvent;
var evnt2 : VideoEvent;
var one_frame = new Timecode("00:00:00:01");
var track = FindSelectedTrack(); // Use this function to find the first selected track.
if (track.IsVideo()) { // Proceed only if selected track is video track.
var eventEnum = new Enumerator(track.Events);
dCursor = Vegas.Cursor.ToMilliseconds(); // Remember the cursor position.
//Go through each event on the track.
while (!eventEnum.atEnd()) {
evnt = (eventEnum.item());
// Get the event's start and length timecode, in milliseconds.
dStart = evnt.Start.ToMilliseconds();
dLength = evnt.Length.ToMilliseconds();
// If the cursor timecode is between the beginning and end of the
// event timecodes, then split the event, delete first frame from event to right of split.
// Copy last frame from event to left of split and put into the one-frame gap.
if ( (dCursor > dStart) && ( dCursor <= (dLength + dStart) ) ) {
var patch_frame : VideoEvent = VideoEvent(evnt.Copy(VideoTrack(track),Vegas.Cursor));
// Make first frame of new event equal frame to left of cursor (for all takes)
for (var i=patch_frame.Takes.Count - 1; i >= 0; i--) {
patch_frame.Takes[i].Offset = patch_frame.Takes[i].Offset + Vegas.Cursor - one_frame - evnt.Start; // Make change for ALL takes.
}
patch_frame.Start = Vegas.Cursor; // Move new event to right of cursor.
patch_frame.Length = one_frame; // Truncate event to only one frame in length.
evnt.Split (Vegas.Cursor - evnt.Start);
// Next several lines truncate start of NEXT event by one frame.
eventEnum.moveNext(); // Go to next event on this timeline.
evnt2 = VideoEvent(eventEnum.item()); // Get next event.
evnt2.AdjustStartLength(evnt2.Start+one_frame, evnt2.Length-one_frame, true);
if (evnt.IsGrouped) { // Add new events to existing grouping.
var grp : TrackEventGroup = evnt.Group;
grp.Add(evnt2);
grp.Add(patch_frame)
}
} // End if dCursor ...
eventEnum.moveNext(); // Go to next event on this timeline.
} // End While
} // End If Track
else {
MessageBox.Show("You must select a video track.");
}
} catch (e) {
MessageBox.Show(e);
}
// End of main program
// Beginning of functions
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;
}