Get current frame of footage (not project)?

sheilan wrote on 8/13/2020, 11:32 AM

Hello,

 

I have a script that is loading velocity envelope and gets the frame & value of all points.

Now because my video has slow motion effect, what might be frame 214 isn't really the 214th frame of the sequence. Is there a way I can get the actual frame displayed from the footage?

Here's my code

public void FromVegas(Vegas myVegas)
{
    // Loop over tracks
    foreach (Track track in myVegas.Project.Tracks)
        // Check if track is video
        if (track.IsVideo())
            // Loop over events in the trakc
            foreach (TrackEvent evnt in track.Events)
                // Load if selected
                if (evnt.Selected)
                {
                    // Video event
                    VideoEvent vevnt = (VideoEvent)evnt;
                    // Media name
                    string videoName = vevnt.ActiveTake.Name;
                    // Video envelope
                    Envelope VelEnv = FindVEEnvelope(vevnt, EnvelopeType.Velocity);
                    // Check if video has envelope
                    if (null == VelEnv)
                    {
                        MessageBox.Show("Selected video has no velocity");
                        return;
                    }
                    // Loop over points
                    foreach (var point in VelEnv.Points)
                    {
                        // Get frame & value
                        var frame = point.X.FrameCount; // Here I want it to be footage frame, and not project frame.
                        var value = point.Y;
                    }
                }
}

 

 

 

Comments

sheilan wrote on 8/13/2020, 12:02 PM

I believe you will get more response if you ask your question in the Scripting Forum.

I thought this was the scripting forum

jetdv wrote on 8/13/2020, 2:09 PM

You could add the clip to a new track, solo that track, go to the 214th frame, save an image, and then delete that track.

Musicvid wrote on 8/13/2020, 2:30 PM

@sheilan

My bad day is coming back to haunt me. Glad you found an answer.

sheilan wrote on 8/13/2020, 3:36 PM

You could add the clip to a new track, solo that track, go to the 214th frame, save an image, and then delete that track.

Thanks for the reply, but what I meant is that I'd like to get the original frame number, rather than the one shown in Vegas project. Here's an example -

The velocity point is on frame 221, but the actual frame you see is frame 256 from the original footage (it came earlier because of velocity speed up) so when I get the point using the code I posted earlier, it gives me frame 221 + the speed of the point. What I would like to do, is get the original number of the displayed frame, which is 256, rather than the one in Vegas.

 

@Musicvid

Happens to the best of us!

joelsonforte.br wrote on 8/13/2020, 4:10 PM

You can apply the Timecode effect as Media FX and use markers to identify the current frame of the footage.

sheilan wrote on 8/13/2020, 5:06 PM

@joelsonforte.br

Yeah that method seems to do it. Do you know how can I get that frame with the code?

VEGASPascal wrote on 8/14/2020, 3:34 AM

@sheilan ...or you do a quick math in C#. Use your loop with frame count and value and multiply the value for each frame... the result will give you the original frame number for the selected video.

sheilan wrote on 8/14/2020, 4:10 AM

@VEGASPascal Value*frame did not give me the original frame number though.. unless this isn't the math you're talking about? 😄

I did a loop for every frame, got the current value in velocity and multiplied the value by current frame.

VEGASPascal wrote on 8/14/2020, 5:23 AM

using ScriptPortal.Vegas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VegasTestLibrary
{

    public class EntryPoint
    {
        public void FromVegas(Vegas myVegas)
        {
            // Loop over tracks
            foreach (Track track in myVegas.Project.Tracks)
            {
                // Check if track is video
                if (track.IsVideo())
                {
                    // Loop over events in the trakc
                    foreach (TrackEvent evnt in track.Events)
                    {
                        // Load if selected
                        if (evnt.Selected)
                        {
                            // Video event
                            VideoEvent vevnt = (VideoEvent)evnt;
                            // Media name
                            string videoName = vevnt.ActiveTake.Name;
                            // Video envelope
                            Envelope VelEnv = FindVEEnvelope(vevnt, EnvelopeType.Velocity);
                            // Check if video has envelope
                            if (null == VelEnv)
                            {
                                MessageBox.Show("Selected video has no velocity");
                                return;
                            }
                            
                            double frameNumber = 0.0;
                            long relativeCursorPosition = myVegas.Cursor.FrameCount - vevnt.Start.FrameCount;
                            for (long i = 0; i < relativeCursorPosition; ++i)
                            {
                                Timecode valueAt = Timecode.FromFrames(i);
                                frameNumber += VelEnv.ValueAt(valueAt);
                            }

                            MessageBox.Show("Absolute frame: " + relativeCursorPosition +
                                            "\nFrame number: " + Math.Round(frameNumber, 1));
                        }
                    }
                }
            }
        }

        private Envelope FindVEEnvelope(VideoEvent vevnt, EnvelopeType velocity)
        {
            if (vevnt.Envelopes.Count == 0)
            {
                return null;
            }
            return vevnt.Envelopes.First(env => env.Type == velocity);
        }
    }
}
 

VEGASPascal wrote on 8/14/2020, 5:28 AM

@sheilan For 50% velocity for test (but it also workes for curves)

sheilan wrote on 8/14/2020, 6:05 AM

@VEGASPascal

 

Thanks alot!