Esempio n. 1
0
//
// Adds a given media fileName to the current track at the specified cursorPosition
//
    void InsertFileAt(Vegas vegas, string fileName, Timecode cursorPosition)
    {
        VideoEvent videoEvent = null;

        Media      media      = new Media(fileName);
        VideoTrack videoTrack = FindSelectedVideoTrack(vegas.Project);

        videoEvent = videoTrack.AddVideoEvent(cursorPosition, Timecode.FromSeconds(stillLength));
        Take take = videoEvent.AddTake(media.GetVideoStreamByIndex(0));

        videoEvent.MaintainAspectRatio = false;

        VideoMotionKeyframe key1 = new VideoMotionKeyframe(Timecode.FromSeconds(stillLength));

        videoEvent.VideoMotion.Keyframes.Add(key1);
        VideoMotionKeyframe key0 = videoEvent.VideoMotion.Keyframes[0];

        key0.ScaleBy(new VideoMotionVertex(initialScale, initialScale));
        key0.RotateBy(initialRotationRadians * (double)rnd.Next(-1, 1));
        key0.MoveBy(new VideoMotionVertex((float)rnd.Next(-15, 15), (float)rnd.Next(-20, 20)));

        PlugInNode plugIn = vegas.Transitions.FindChildByName(desiredTransitions[rnd.Next(0, desiredTransitions.Length - 1)]);

        Effect fx = new Effect(plugIn);

        videoEvent.FadeIn.Transition = fx;
    }
 public static void PanFromCenterToLeft(Vegas vegas, VideoEvent videoEvent)
 {
     using (UndoBlock undo = new UndoBlock("Add pan/crop"))
     {
         VideoMotionKeyframe key0 = videoEvent.VideoMotion.Keyframes[0];
         int videoWidth           = vegas.Project.Video.Width;
         VideoMotionKeyframe key1 = new VideoMotionKeyframe(Timecode.FromMilliseconds(Config.splitOffset));
         videoEvent.VideoMotion.Keyframes.Add(key1);
         key1.MoveBy(new VideoMotionVertex(videoWidth, 0));
     }
 }
 public void ResetKeyframeCenter(VideoMotionKeyframe k)
 {
     k.MoveBy(new VideoMotionVertex(MyVegas.Project.Video.Width / 2 - k.Center.X, MyVegas.Project.Video.Height / 2 - k.Center.Y));
 }
        public void Randomize(VideoMotionKeyframe k, Random r)
        {
            k.MoveBy(new VideoMotionVertex(RandomHelper(r, _MinX, _MaxX), RandomHelper(r, _MinY, _MaxY)));

            float d = RandomHelper(r, _MinScale, _MaxScale);
            k.ScaleBy(new VideoMotionVertex(d, d));

            k.RotateBy(Math.PI * RandomHelper(r, _MinRotation, _MaxRotation) / 180d);
        }
Esempio n. 5
0
    public void FromVegas(Vegas vegas)
    {
        Project currProject = vegas.Project;
        Int32   videoWidth  = currProject.Video.Width;
        Int32   videoHeight = currProject.Video.Height;

        TrackEvent[] tes = FindSelectedEvents(currProject);
        VideoEvent[] ves = GetVideoEvents(tes);

        if (ves.Length != 2)
        {
            MessageBox.Show("You have to select exactly 2 video events (in no particular order) in order for this script to work.\nOne of the events must contain the \"" + MOTION_TRACKING_FX_NAME + "\" effect with at least one mask enabled and populated with motion tracking data, the second event is the target event, where the pan and crop center will be populated with the motion track data. Then after clicking on this script you can select the mask to use. The script will copy the location values of the mask to the location values of the pan and crop setting (beginning from the cursor position till the end of the motion tracked clip, or within the selection range).\n\nTerminating...", "Not enough selections", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }

        // foreach (VideoEvent ev in ves)
        // {
        //     foreach (Effect ef in ev.Effects)
        //     {
        //         MessageBox.Show(ef.Description);
        //     }
        // }

        VideoEvent ve = GetEventContainingEffect(ves, MOTION_TRACKING_FX_NAME);

        if (ve == null)
        {
            MessageBox.Show("No selected event with the \"" + MOTION_TRACKING_FX_NAME + "\" plugin found which holds the motion tracking data!\n\nTerminating...", "Not enough selections", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }

        OFXEffect fx = GetOFXFromEvent(ve, MOTION_TRACKING_FX_NAME);

        if (fx == null)
        {
            MessageBox.Show("Can't seem to grab the \"" + MOTION_TRACKING_FX_NAME + "\" effect!\n\nTerminating...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            return;
        }

        PopulateMaskBitmask(fx);

        // show_fx_parameters(fx);

        int mask_to_use = PromptForMaskNumber();

        if (mask_to_use == -1)
        {
            return;
        }

        VideoEvent ve2 = GetEventDifferentFrom(ves, ve);

        if (ve2 == null)
        {
            MessageBox.Show("No selected event different from the motion capture event found, which is the target for the motion tracking data!\n\nTerminating...", "Not enough selections", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }

        Timecode startingTime = null;
        Timecode endingTime   = null;

        DialogResult dialogResult = MessageBox.Show("You have two methods to copy the keyframes:\nOne option is to copy from the current cursor position onwards, till the script runs into the ending of one of the events (yes).\nThe other option is to use the current selection. Note however that this produces unexpected behaviour, if no selection is currently active! (no).\n\nCopy from the cursor onwards?", "Processing Method", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

        if (dialogResult == DialogResult.Cancel)
        {
            return;
        }
        else
        {
            Double motionStart = ve.Start.ToMilliseconds();
            Double motionEnd   = ve.End.ToMilliseconds();

            Double cornerStart = ve2.Start.ToMilliseconds();
            Double cornerEnd   = ve2.End.ToMilliseconds();

            if (dialogResult == DialogResult.Yes)
            {
                Double cursorStart = vegas.Transport.CursorPosition.ToMilliseconds();

                Double max = Math.Max(motionStart, Math.Max(cornerStart, cursorStart));
                Double min = Math.Min(motionEnd, Math.Min(cornerEnd, cursorStart));

                if (max != cursorStart || min != cursorStart)
                {
                    MessageBox.Show("The cursor must be placed at a position where it covers both selected events!\n\nTerminating...", "Invalid cursor position", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                startingTime = new Timecode(cursorStart);
                endingTime   = new Timecode(Math.Min(motionEnd, cornerEnd));
            }
            else if (dialogResult == DialogResult.No)
            {
                Double selectionStart = vegas.Transport.SelectionStart.ToMilliseconds();
                Double selectionEnd   = selectionStart + vegas.Transport.SelectionLength.ToMilliseconds();

                Double max = Math.Max(motionStart, Math.Max(cornerStart, selectionStart));
                Double min = Math.Min(motionEnd, Math.Min(cornerEnd, selectionEnd));

                if (max != selectionStart || min != selectionEnd)
                {
                    MessageBox.Show("The selection must be placed in a range where it covers both selected events!\n\nTerminating...", "Invalid selection", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                startingTime = new Timecode(selectionStart);
                endingTime   = new Timecode(selectionEnd);
            }
        }

        // MessageBox.Show("Current time: " + fx2.CurrentTime.ToString() + "\nCursor pos: " + vegas.Transport.CursorPosition.ToString() + "\nCalculated current time: " + (fx2.CurrentTime + ve2.Start).ToString());

        OFXDouble2DParameter motionParam = fx.FindParameterByName("Location_" + mask_to_use.ToString()) as OFXDouble2DParameter;

        if (startingTime == null || endingTime == null)
        {
            MessageBox.Show("Something went wrong as the script tried to use the method you decided...\n\nTerminating...", "Not enough selections", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            return;
        }

        double deltaX         = 0;
        double deltaY         = 0;
        double lastX          = 0;
        double lastY          = 0;
        bool   deltaPopulated = false;

        VideoMotion ve2vm = ve2.VideoMotion;

        VideoMotionKeyframe prevKeyframe = new VideoMotionKeyframe(currProject, (startingTime - ve2.Start));

        ve2vm.Keyframes.Add(prevKeyframe);

        foreach (OFXDouble2DKeyframe motionKeyframe in motionParam.Keyframes)
        {
            Timecode keyframeTime = motionKeyframe.Time + ve.Start;

            if (startingTime <= keyframeTime && keyframeTime <= endingTime)
            {
                if (!deltaPopulated)
                {
                    lastX = motionKeyframe.Value.X;
                    lastY = motionKeyframe.Value.Y;

                    deltaPopulated = true;
                }
                else
                {
                    deltaX = motionKeyframe.Value.X - lastX;
                    deltaY = motionKeyframe.Value.Y - lastY;

                    lastX = motionKeyframe.Value.X;
                    lastY = motionKeyframe.Value.Y;

                    // TODO: Delete
                    // MessageBox.Show("Delta X: " + deltaX.ToString()
                    //         + "\nDelta Y: " + deltaY.ToString()
                    //         + "\nLast X: " + lastX.ToString()
                    //         + "\nLast Y: " + lastY.ToString());

                    VideoMotionKeyframe vmKeyframe = new VideoMotionKeyframe(currProject, keyframeTime - ve2.Start);
                    ve2vm.Keyframes.Add(vmKeyframe);

                    // TODO: Delete
                    // MessageBox.Show("Current Bounds: " + vmKeyframe.Bounds.ToString()
                    //         + "\nCurrent Rotation: " + vmKeyframe.Rotation.ToString()
                    //         + "\nCurrent Type: " + vmKeyframe.Type.ToString()
                    //         + "\nCurrent Smoothness: " + vmKeyframe.Smoothness.ToString()
                    //         + "\n\nPrevious Bounds: " + prevKeyframe.Bounds.ToString()
                    //         + "\nPrevious Rotation: " + prevKeyframe.Rotation.ToString()
                    //         + "\nPrevious Type: " + prevKeyframe.Type.ToString()
                    //         + "\nPrevious Smoothness: " + prevKeyframe.Smoothness.ToString());

                    // Duplicate previous keyframe values
                    // vmKeyframe.Bounds = prevKeyframe.Bounds;
                    // vmKeyframe.Rotation = prevKeyframe.Rotation;
                    // vmKeyframe.Type = prevKeyframe.Type;
                    // vmKeyframe.Smoothness = prevKeyframe.Smoothness;

                    // bool kfGrabbed = false;
                    // foreach (VideoMotionKeyframe kf in ve2vm.Keyframes)
                    // {
                    //     if (kf.Position.Equals(vmKeyframe.Position))
                    //     {
                    //         vmKeyframe = kf;
                    //         kfGrabbed = true;
                    //         break;
                    //     }
                    // }

                    // if (!kfGrabbed)
                    // {
                    //     MessageBox.Show("Something went wrong as the script tried to regrab a created keyframe with the Timecode " + vmKeyframe.Position.ToString() + " ...\n\nTerminating...", "Error regrabbing keyframe", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    //     return;
                    // }

                    double convertedX = deltaX * videoWidth;
                    double convertedY = -1 * (deltaY * videoHeight);

                    vmKeyframe.MoveBy(new VideoMotionVertex(Convert.ToSingle(convertedX), Convert.ToSingle(convertedY)));

                    // MessageBox.Show("Next Bounds: " + vmKeyframe.Bounds.ToString()
                    //         + "\nNext Rotation: " + vmKeyframe.Rotation.ToString()
                    //         + "\nNext Type: " + vmKeyframe.Type.ToString()
                    //         + "\nNext Smoothness: " + vmKeyframe.Smoothness.ToString());

                    prevKeyframe = vmKeyframe;
                }
            }
        }

        // TODO: Bother with interpolation shit?
        // dialogResult = MessageBox.Show("Do you also want to copy the interpolation data?", "Copy interpolation data?", MessageBoxButtons.YesNo);

        // if (dialogResult == DialogResult.Yes)
        // {
        //     int curr = 0;
        //     int end = cornerParam.Keyframes.Count;

        //     foreach (OFXDouble2DKeyframe motionKeyframe in motionParam.Keyframes)
        //     {
        //         Timecode keyframeTime = motionKeyframe.Time + ve.Start;
        //         if (curr < end && startingTime <= keyframeTime && keyframeTime <= endingTime)
        //         {
        //             Timecode calculatedTime = (keyframeTime - ve2.Start);

        //             OFXDouble2DKeyframe cornerKeyframe = cornerParam.Keyframes[curr] as OFXDouble2DKeyframe;
        //             if (cornerKeyframe.Time == calculatedTime)
        //             {
        //                 cornerKeyframe.Interpolation = motionKeyframe.Interpolation;
        //             }
        //             else if (cornerKeyframe.Time < calculatedTime)
        //             {
        //                 ++curr;
        //             }
        //         }
        //     }
        // }

        // cornerParam.ParameterChanged();
    }