Beispiel #1
0
    void ExportVideoMotion(XmlElement parent, VideoMotion videoMotion)
    {
        XmlElement elt = AddChild(parent, "VideoMotion");

        ChildBoolean(elt, "ScaleToFill", videoMotion.ScaleToFill);
        ExportViideoMotionKeyframes(elt, videoMotion.Keyframes);
    }
Beispiel #2
0
    void ImportVideoMotion(XmlElement parent, VideoMotion videoMotion)
    {
        XmlElement elt = parent["VideoMotion"];

        if (null == elt)
        {
            return;
        }
        try { videoMotion.ScaleToFill = ChildBoolean(elt, "ScaleToFill"); } catch {}
        ImportVideoMotionKeyframes(elt, videoMotion.Keyframes);
    }
 public static VideoEncoderOptions OptimizedFor(
     int width,
     int height,
     int maxFramesPerSecond,
     VideoMotion minVideoMotion = VideoMotion.Low,
     VideoMotion maxVideoMotion = VideoMotion.High)
 {
     return(new VideoEncoderOptions
     {
         MaxFramesPerSecond = maxFramesPerSecond,
         MinBitsPerSecond = OptimalBitsPerSecond(width, height, maxFramesPerSecond, minVideoMotion),
         MaxBitsPerSecond = OptimalBitsPerSecond(width, height, maxFramesPerSecond, maxVideoMotion),
     });
 }
Beispiel #4
0
        /// <summary>
        /// http://blog.sporv.com/restoration-tips-kush-gauge/
        /// </summary>
        public static int OptimalBitsPerSecond(int width, int height, int framesPerSecond, VideoMotion motionAmount)
        {
            long area = width * height;

            return((int)(area * framesPerSecond * (int)motionAmount * 7 / 100));
        }
    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 != 1)
        {
            MessageBox.Show("You have to select exactly 1 video events in order for this script to work.\nThe events must contain the \"" + MOTION_TRACKING_FX_NAME + "\" effect with at least one mask enabled. You then zoom in, using pan and crop options. Then after clicking on this script, the pan and crop option will be reset and the point moved, so that it stays on the pixel you selected.\n\nTerminating...", "Wrong selection", 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...", "Wrong selection", 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;
        }

        Timecode cursorTime = null;

        Double motionStart = ve.Start.ToMilliseconds();
        Double motionEnd   = ve.End.ToMilliseconds();

        Double cursorStart = vegas.Transport.CursorPosition.ToMilliseconds();

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

        if (max != cursorStart || min != cursorStart)
        {
            MessageBox.Show("The cursor must be placed within the event borders!\n\nTerminating...", "Invalid cursor position", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }

        cursorTime = new Timecode(cursorStart);

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

        if (cursorTime == null)
        {
            MessageBox.Show("Something went wrong as the script tried to determine the cursor position...\n\nTerminating...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            return;
        }

        VideoMotion vevm = ve.VideoMotion;

        VideoMotionKeyframe currKeyframe = new VideoMotionKeyframe(currProject, (cursorTime - ve.Start));

        vevm.Keyframes.Add(currKeyframe);

        Single cutoutWidth  = currKeyframe.TopRight.X - currKeyframe.TopLeft.X;
        Single cutoutHeight = currKeyframe.BottomLeft.Y - currKeyframe.TopLeft.Y;
        Single originX      = currKeyframe.TopLeft.X;
        Single originY      = currKeyframe.BottomLeft.Y;

        OFXDouble2D cursorValue = motionParam.GetValueAtTime(cursorTime - ve.Start);

        Double newCoordX = originX + (cutoutWidth * cursorValue.X);
        Double newCoordY = originY - (cutoutHeight * cursorValue.Y);

        cursorValue.X = newCoordX / videoWidth;
        cursorValue.Y = 1 - (newCoordY / videoHeight);
        motionParam.SetValueAtTime((cursorTime - ve.Start), cursorValue);

        DialogResult dialogResult = MessageBox.Show("If you choose to also adapt the mask scale, this would mean that the mask will be shrunk together with the video frame.\nIf you have zoomed in alot, it sometimes makes sense to not do this as the control handles would get so small that you can't grab them.\nIf you choose to also adjust the size, you can also later on change the width/height from the mask settings.\n\nWould you like to also adapt the mask scale?", "Also adjust mask scale?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

        if (dialogResult == DialogResult.Yes)
        {
            OFXDoubleParameter widthParam     = fx.FindParameterByName("Width_" + mask_to_use.ToString()) as OFXDoubleParameter;
            OFXDoubleParameter heightParam    = fx.FindParameterByName("Height_" + mask_to_use.ToString()) as OFXDoubleParameter;
            Double             maskWidth      = widthParam.GetValueAtTime(cursorTime - ve.Start);
            Double             maskHeight     = heightParam.GetValueAtTime(cursorTime - ve.Start);
            Double             widthRelation  = videoWidth / cutoutWidth;
            Double             heightRelation = videoHeight / cutoutHeight;

            widthParam.SetValueAtTime((cursorTime - ve.Start), (maskWidth / widthRelation));
            heightParam.SetValueAtTime((cursorTime - ve.Start), (maskHeight / heightRelation));
        }

        VideoMotionBounds restoreBounds = new VideoMotionBounds(
            new VideoMotionVertex(0, 0),
            new VideoMotionVertex(videoWidth, 0),
            new VideoMotionVertex(videoWidth, videoHeight),
            new VideoMotionVertex(0, videoHeight)
            );

        currKeyframe.Bounds = restoreBounds;
        currKeyframe.Center = new VideoMotionVertex((videoWidth / 2), (videoHeight / 2));

        MessageBox.Show("Please select a different effect, or move the cursor to a differen event, in order to update the control handles of the mask", "Refresh control handles", MessageBoxButtons.OK, MessageBoxIcon.Information);

        fx.AllParametersChanged();
    }
Beispiel #6
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();
    }