First my disclaimer... I have very little ideal what I'm doing!!
Second, I'm about ready to give up on this effort, so if things are too complicated, any readers of this post should not spend much time on this problem.
That said, over in this thread: Extending the head material of clip, Rory Cooper made the request to extend the beginning of a video event with a still as a header.
So, my thoughts were: it takes about 15 secs to move the cursor to the beginning of an event, take a snapshot and then insert the snapshot at the beginning of the event. With Auto Ripple on, everything is properly shifted on the Timetline. How complicated can it be to write a script to preform the same function? Well, either I'm making this much more complicated than it needs to be, or it is, indeed, more complicated than I thought.
After learning/copying/plagiarizing much code in this forum (thanks to all!!), I got it pretty much to work in hardcoded/debug form. Except one or two things.
My biggest problem is that I can't get my script to ripple (either in the code, or manually setting Auto Ripple). Here's what I get
Before:
After:
The other (lesser) problem is... it would be nice to be able to insert the still on the same track as the original Video media.
Edit: The following downloads have been fixed with the code listed the following post
Here's the bare script as a .dll SnapShotDLL.zip
Here's the VS2010 Project: SnapShotProj.zip
Here's a code listing (remember, lots of hardcoded statements & Debug code):
Phew!!
...Jerry
Second, I'm about ready to give up on this effort, so if things are too complicated, any readers of this post should not spend much time on this problem.
That said, over in this thread: Extending the head material of clip, Rory Cooper made the request to extend the beginning of a video event with a still as a header.
So, my thoughts were: it takes about 15 secs to move the cursor to the beginning of an event, take a snapshot and then insert the snapshot at the beginning of the event. With Auto Ripple on, everything is properly shifted on the Timetline. How complicated can it be to write a script to preform the same function? Well, either I'm making this much more complicated than it needs to be, or it is, indeed, more complicated than I thought.
After learning/copying/plagiarizing much code in this forum (thanks to all!!), I got it pretty much to work in hardcoded/debug form. Except one or two things.
My biggest problem is that I can't get my script to ripple (either in the code, or manually setting Auto Ripple). Here's what I get
Before:
After:
The other (lesser) problem is... it would be nice to be able to insert the still on the same track as the original Video media.
Edit: The following downloads have been fixed with the code listed the following post
Here's the bare script as a .dll SnapShotDLL.zip
Here's the VS2010 Project: SnapShotProj.zip
Here's a code listing (remember, lots of hardcoded statements & Debug code):
using System;
using System.Text;
using System.Windows.Forms;
using Sony.Vegas;
namespace SnapShot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void goButton_Click(object sender, EventArgs e)
{
// secs will need to be set from the Form
Timecode secs = Timecode.FromSeconds(5);
Environment.SpecialFolder special = Environment.SpecialFolder.MyPictures;
string path = Environment.GetFolderPath(special) + "\\aaaSnapTest.png";
Media mySnapShot = new Media(path);
// save the Initial Properties
VideoRenderQuality saveQuality = EntryPoint.myVegas.Project.Preview.RenderQuality;
VideoPreviewSize saveSize = EntryPoint.myVegas.Project.Preview.PreviewSize;
int iCtr = 0;
Timecode saveCursorPosition = EntryPoint.myVegas.Transport.CursorPosition;
try
{
// We want to capture at Best Full, so set the Preview Settings
EntryPoint.myVegas.Project.Preview.RenderQuality = VideoRenderQuality.Best;
EntryPoint.myVegas.Project.Preview.PreviewSize = VideoPreviewSize.Full;
EntryPoint.myVegas.UpdateUI();
foreach (Track aTrack in EntryPoint.myVegas.Project.Tracks)
{
if (aTrack.IsVideo())
{
foreach (VideoEvent vEvent in aTrack.Events)
{
if (vEvent.Selected)
{
iCtr++;
if (iCtr == 1)
{
//logic will go here for either start of finish of Event
EntryPoint.myVegas.Cursor = vEvent.Start;
EntryPoint.myVegas.UpdateUI();
//Save the SnapShot (hardcoded for testing)
// eventually we'll want to put code here for unique file name;
EntryPoint.myVegas.SaveSnapshot(path, ImageFileFormat.PNG);
// save the cursor position so we know where to add the Picture
saveCursorPosition = vEvent.Start;
// move the event to the right by the length of the still
vEvent.Start = saveCursorPosition + secs;
//MessageBox.Show(vEvent.ActiveTake.Name);
}
}
}
}
}
// if nothing has been selected, inform the user
if (iCtr != 1)
{
MessageBox.Show("You must select as least one and only one Video Event, Please try again");
}
else
{
// Here we add a new Video Track and insert the picture we just created
VideoTrack newTrack = EntryPoint.myVegas.Project.AddVideoTrack();
VideoEvent newEvent = newTrack.AddVideoEvent();
newEvent.Length = secs;
newEvent.Start = saveCursorPosition;
newEvent.Takes.Add(new Take(mySnapShot.GetVideoStreamByIndex(0)));
}
}
catch (Exception eCapture)
{
MessageBox.Show(eCapture.Message);
}
// Restore Preview Settings
EntryPoint.myVegas.Project.Preview.RenderQuality = saveQuality;
EntryPoint.myVegas.Project.Preview.PreviewSize = saveSize;
EntryPoint.myVegas.UpdateUI();
this.Dispose();
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void Form1_Load(object sender, EventArgs e)
{
descLabel.Text = "This is a really crude attempt at taking a snapshot of the\r\n" +
"first frame of a video event and placing that snapshot as\r\n" +
"a header to the event. Lots of hardcoding and debug code";
}
}
public class EntryPoint
{
//In order to access the myVegas object in the Windows Form, it must be have public access
public static Vegas myVegas;
public void FromVegas(Vegas vegas)
{
myVegas = vegas;
try
{
// Display the Windows Form
Form1 form1 = new Form1();
form1.ShowDialog();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}
Phew!!
...Jerry