💡(Feature Request) Match Output Aspect without rescaling!

Comments

jetdv wrote on 1/18/2023, 9:56 AM

@m3lquixd That's what I said above...

I really think my logo resize script should work (for instances where the image is TALLER like in most examples listed above). It would have to modified to handle WIDER as in the #3 wide image. It does a match aspect but then matches the height.

I need a good example of a wide one. It's worked fine for all images I've taken with my cell phone (both horizontal and vertical).

m3lquixd wrote on 1/18/2023, 9:59 AM

@jetdv Here on my PC it only worked with taller images, no wider images were correct. All the wide images were farther apart and didn't fill the screen.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

jetdv wrote on 1/18/2023, 10:01 AM

@m3lquixd, That's what I've now said TWICE. I agree with you. But to get it working on wide images I need a sample "wide" image to test with.

m3lquixd wrote on 1/18/2023, 10:04 AM

I did a new test, they are all decreasing in size, not filling the screen. I thought it was working because the images I had tested before were of high resolution.


https://drive.google.com/drive/folders/13ocx38QEkLgI0I70iQWADcaAsfEEKFMI?usp=share_link

@jetdv Here are the images I used for testing. The result I expect. That's what I showed at the end of the video.

 

Last changed by m3lquixd on 1/18/2023, 11:43 AM, changed a total of 2 times.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

m3lquixd wrote on 1/18/2023, 10:16 AM

Yes. As I thought. This does not do what I asked. This is what @Yelandkeil wanted.

Last changed by m3lquixd on 1/18/2023, 10:30 AM, changed a total of 1 times.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

m3lquixd wrote on 1/18/2023, 10:17 AM

As I said.

@jetdv
In this case solves the problem of @Yelandkeil

4,
My request: Match project aspect and remain size when thumbnails added to timeline.


In my case. When the image is taller than it is wide, it should be fit to frame height. And when the image is bigger in width it has to fit to the width of the frame.

3,
Your request: Match project aspect when still images added to timeline.

As the @lan-mLMC showed.

I know what you mean. What you want is something like this:

 

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

m3lquixd wrote on 1/18/2023, 10:19 AM

@jetdv Sorry for repeating this several times, but I think you still don't understand what I need.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

jetdv wrote on 1/18/2023, 10:33 AM

@m3lquixd, it should do #2 and #3 left side. NOT #3 right side. You can see the result in the images I got in the first script post. I'd use the second script, though.

jetdv wrote on 1/18/2023, 11:01 AM

@m3lquixd Ok, this version will now do wide images as well.

Original:

Doing a "Match Output Aspect"

Running the script to Match Output Aspect and fill the width:


 

using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            float scrWidth = myVegas.Project.Video.Width;
            float scrHeight = myVegas.Project.Video.Height;

            foreach (Track myTrack in myVegas.Project.Tracks)
            {
              if (myTrack.isVideo())
              {
                foreach (VideoEvent evnt in myTrack.Events)
                {
                    if (evnt.Selected)
                    {
                        MatchAspect(evnt);

                        VideoEvent videoEvent = evnt as VideoEvent;
                        VideoMotionKeyframes keyframes = videoEvent.VideoMotion.Keyframes;
                        int cKeyframes = keyframes.Count;
                        for (int jj = cKeyframes - 1; jj >= 0; jj--)
                        {
                            VideoMotionKeyframe thisKeyframe = keyframes[jj] as VideoMotionKeyframe;

                            float dWidth = Math.Abs(thisKeyframe.TopRight.X - thisKeyframe.TopLeft.X);
                            float dHeight = Math.Abs(thisKeyframe.BottomLeft.Y - thisKeyframe.TopLeft.Y); ;

                            MediaStream mediaStream = GetActiveMediaStream(videoEvent);
                            VideoStream videoStream = mediaStream as VideoStream;
                            VideoOutputRotation vRotation = videoStream.Rotation;

                            float dFullHeight = videoStream.Height;
                            float dFullWidth = videoStream.Width;
                            if ((vRotation == VideoOutputRotation.QuarterTurnClockwise) || (vRotation == VideoOutputRotation.QuarterTurnCounterclockwise))
                            {
                                dFullHeight = videoStream.Width;
                                dFullWidth = videoStream.Height;
                            }

                            float pwid = 0.0F;
                            float wpwid = 0.0F;

                            if (dFullHeight > scrHeight)
                            {
                                pwid = dFullHeight / dHeight * 100;
                            }
                            else
                            {
                                pwid = dHeight / scrHeight * 100;
                            }

                            if (dFullWidth > scrWidth)
                            {
                                wpwid = dFullWidth / dWidth * 100;
                            }

                            if (wpwid > pwid)
                            {
                                pwid = wpwid;
                            }

                            ScaleKeyframe(thisKeyframe, pwid, 0);

                        }
                    }
                }
              }
            }
        }

        public void MatchAspect(TrackEvent trackEvent)
        {
            float dWidthProject = myVegas.Project.Video.Width;
            float dHeightProject = myVegas.Project.Video.Height;
            double dPixelAspect = myVegas.Project.Video.PixelAspectRatio;
            double dAspect = dPixelAspect * dWidthProject / dHeightProject;

            MediaStream mediaStream = GetActiveMediaStream(trackEvent);
            if (!(mediaStream == null))
            {
                VideoStream videoStream = mediaStream as VideoStream;

                double dMediaPixelAspect = videoStream.PixelAspectRatio;
                VideoEvent videoEvent = trackEvent as VideoEvent;
                VideoMotionKeyframes keyframes = videoEvent.VideoMotion.Keyframes; ;

                int cKeyframes = keyframes.Count;

                for (int jj = cKeyframes - 1; jj >= 0; jj--)
                {
                    VideoMotionKeyframe thisKeyframe = keyframes[jj] as VideoMotionKeyframe;
                    MatchOutputAspect(thisKeyframe, dMediaPixelAspect, dAspect);
                }
            }
            myVegas.UpdateUI();
        }

        public MediaStream GetActiveMediaStream(TrackEvent trackEvent)
        {
            try
            {
                if (!(trackEvent.ActiveTake.IsValid()))
                {
                    throw new ArgumentException("empty or invalid take");
                }

                Media media = myVegas.Project.MediaPool.Find(trackEvent.ActiveTake.MediaPath);
                if (null == media)
                {
                    MessageBox.Show("missing media");
                    throw new ArgumentException("missing media");
                }

                MediaStream mediaStream = media.Streams.GetItemByMediaType(MediaType.Video, trackEvent.ActiveTake.StreamIndex);
                return mediaStream;
            }
            catch (Exception e)
            {
               MessageBox.Show("{0}", e.Message);
              return null;
            }
        }


        public void MatchOutputAspect(VideoMotionKeyframe keyframe, double dMediaPixelAspect, double dAspectOut)
        {
            VideoMotionKeyframe keyframeSave = keyframe;

            try
            {
                double rotation = keyframe.Rotation;
                keyframe.RotateBy(-rotation);

                float dWidth = Math.Abs(keyframe.TopRight.X - keyframe.TopLeft.X);
                float dHeight = Math.Abs(keyframe.BottomLeft.Y - keyframe.TopLeft.Y);
                double dCurrentAspect = dMediaPixelAspect * dWidth / dHeight;
                float centerY = keyframe.Center.Y;
                float centerX = keyframe.Center.X;
                double dFactor;

                VideoMotionBounds bounds = new VideoMotionBounds(keyframe.TopLeft, keyframe.TopRight, keyframe.BottomRight, keyframe.BottomLeft);
                if (dCurrentAspect < dAspectOut)
                {
                    // alter y coords            
                    dFactor = dCurrentAspect / dAspectOut;

                    bounds.TopLeft.Y = (bounds.TopLeft.Y - centerY) * (float)dFactor + centerY;
                    bounds.TopRight.Y = (bounds.TopRight.Y - centerY) * (float)dFactor + centerY;
                    bounds.BottomLeft.Y = (bounds.BottomLeft.Y - centerY) * (float)dFactor + centerY;
                    bounds.BottomRight.Y = (bounds.BottomRight.Y - centerY) * (float)dFactor + centerY;
                }
                else
                {
                    // alter x coords
                    dFactor = dAspectOut / dCurrentAspect;

                    bounds.TopLeft.X = (bounds.TopLeft.X - centerX) * (float)dFactor + centerX;
                    bounds.TopRight.X = (bounds.TopRight.X - centerX) * (float)dFactor + centerX;
                    bounds.BottomLeft.X = (bounds.BottomLeft.X - centerX) * (float)dFactor + centerX;
                    bounds.BottomRight.X = (bounds.BottomRight.X - centerX) * (float)dFactor + centerX;
                }

                // set it to new bounds
                keyframe.Bounds = bounds;

                // restore rotation.        
                keyframe.RotateBy(rotation);
            }
            catch
            {
                // restore original settings on error
                keyframe = keyframeSave;
            }
        }

        public void ScaleKeyframe(VideoMotionKeyframe keyframe, float szChange, float rotAngle)
        {
            float cWidth = (1 / (szChange / 100));
            float cHeight = (1 / (szChange / 100));

            if (szChange > 100)
            {
                cWidth = (szChange / 100);
                cHeight = (szChange / 100);
            }

            VideoMotionVertex bounds = new VideoMotionVertex(cWidth, cHeight);

            keyframe.ScaleBy(bounds);
            keyframe.RotateBy((rotAngle * (Math.PI / 180)));
        }

    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

 

jetdv wrote on 1/18/2023, 11:02 AM

After running the script, visually you will see NO change. However, it HAS changed. If you open Pan/Crop, that is where you will see the changes.

m3lquixd wrote on 1/18/2023, 11:08 AM

@jetdv Still having the same problem. Media smaller than the project makes small. And that's not the idea.


If you want to download the images.
https://drive.google.com/drive/folders/13ocx38QEkLgI0I70iQWADcaAsfEEKFMI?usp=share_link

Last changed by m3lquixd on 1/18/2023, 11:43 AM, changed a total of 1 times.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

m3lquixd wrote on 1/18/2023, 11:10 AM

The result I expect. That's what I showed at the end of the video.

@jetdv Here I showed.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

jetdv wrote on 1/18/2023, 11:18 AM

@m3lquixd If the image is LARGER than the frame, it is resizing it back down to fit the frame.

If the image is SMALLER than the frame, it is making it it's ORIGINAL size within the frame.

 

jetdv wrote on 1/18/2023, 11:36 AM

@m3lquixd Ok, this version doesn't go back to the "original" size and, instead, continues to fill the screen even if it's smaller than the frame size.
 

using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            float scrWidth = myVegas.Project.Video.Width;
            float scrHeight = myVegas.Project.Video.Height;

            foreach (Track myTrack in myVegas.Project.Tracks)
            {
                foreach (VideoEvent evnt in myTrack.Events)
                {
                    if (evnt.Selected)
                    {
                        MatchAspect(evnt);

                        VideoEvent videoEvent = evnt as VideoEvent;
                        VideoMotionKeyframes keyframes = videoEvent.VideoMotion.Keyframes;
                        int cKeyframes = keyframes.Count;
                        for (int jj = cKeyframes - 1; jj >= 0; jj--)
                        {
                            VideoMotionKeyframe thisKeyframe = keyframes[jj] as VideoMotionKeyframe;

                            float dWidth = Math.Abs(thisKeyframe.TopRight.X - thisKeyframe.TopLeft.X);
                            float dHeight = Math.Abs(thisKeyframe.BottomLeft.Y - thisKeyframe.TopLeft.Y); ;

                            MediaStream mediaStream = GetActiveMediaStream(videoEvent);
                            VideoStream videoStream = mediaStream as VideoStream;
                            VideoOutputRotation vRotation = videoStream.Rotation;

                            float dFullHeight = videoStream.Height;
                            float dFullWidth = videoStream.Width;
                            if ((vRotation == VideoOutputRotation.QuarterTurnClockwise) || (vRotation == VideoOutputRotation.QuarterTurnCounterclockwise))
                            {
                                dFullHeight = videoStream.Width;
                                dFullWidth = videoStream.Height;
                            }

                            float pwid = 0.0F;
                            float wpwid = 0.0F;
                            bool smaller = false;

                            if (dFullHeight > scrHeight)
                            {
                                pwid = dFullHeight / dHeight * 100;
                            }
                            else
                            {
                                pwid = dHeight / dFullHeight * 100;
                                smaller = true;
                            }

                            if (dFullWidth > scrWidth)
                            {
                                wpwid = dFullWidth / dWidth * 100;
                            }
                            else
                            {
                                smaller = true;
                                wpwid = dWidth / dFullWidth * 100;
                            }

                            if (wpwid > pwid && !smaller)
                            {
                                pwid = wpwid;
                            }
                            if (wpwid < pwid && smaller)
                            {
                                pwid = wpwid;
                            }

                            ScaleKeyframe(thisKeyframe, pwid, 0);
                        }
                    }
                }
            }
        }

        public void MatchAspect(TrackEvent trackEvent)
        {
            float dWidthProject = myVegas.Project.Video.Width;
            float dHeightProject = myVegas.Project.Video.Height;
            double dPixelAspect = myVegas.Project.Video.PixelAspectRatio;
            double dAspect = dPixelAspect * dWidthProject / dHeightProject;

            MediaStream mediaStream = GetActiveMediaStream(trackEvent);
            if (!(mediaStream == null))
            {
                VideoStream videoStream = mediaStream as VideoStream;

                double dMediaPixelAspect = videoStream.PixelAspectRatio;
                VideoEvent videoEvent = trackEvent as VideoEvent;
                VideoMotionKeyframes keyframes = videoEvent.VideoMotion.Keyframes; ;

                int cKeyframes = keyframes.Count;

                for (int jj = cKeyframes - 1; jj >= 0; jj--)
                {
                    VideoMotionKeyframe thisKeyframe = keyframes[jj] as VideoMotionKeyframe;
                    MatchOutputAspect(thisKeyframe, dMediaPixelAspect, dAspect);
                }
            }
            myVegas.UpdateUI();
        }

        public MediaStream GetActiveMediaStream(TrackEvent trackEvent)
        {
            try
            {
                if (!(trackEvent.ActiveTake.IsValid()))
                {
                    throw new ArgumentException("empty or invalid take");
                }

                Media media = myVegas.Project.MediaPool.Find(trackEvent.ActiveTake.MediaPath);
                if (null == media)
                {
                    MessageBox.Show("missing media");
                    throw new ArgumentException("missing media");
                }

                MediaStream mediaStream = media.Streams.GetItemByMediaType(MediaType.Video, trackEvent.ActiveTake.StreamIndex);
                return mediaStream;
            }
            catch (Exception e)
            {
               MessageBox.Show("{0}", e.Message);
              return null;
            }
        }


        public void MatchOutputAspect(VideoMotionKeyframe keyframe, double dMediaPixelAspect, double dAspectOut)
        {
            VideoMotionKeyframe keyframeSave = keyframe;

            try
            {
                double rotation = keyframe.Rotation;
                keyframe.RotateBy(-rotation);

                float dWidth = Math.Abs(keyframe.TopRight.X - keyframe.TopLeft.X);
                float dHeight = Math.Abs(keyframe.BottomLeft.Y - keyframe.TopLeft.Y);
                double dCurrentAspect = dMediaPixelAspect * dWidth / dHeight;
                float centerY = keyframe.Center.Y;
                float centerX = keyframe.Center.X;
                double dFactor;

                VideoMotionBounds bounds = new VideoMotionBounds(keyframe.TopLeft, keyframe.TopRight, keyframe.BottomRight, keyframe.BottomLeft);
                if (dCurrentAspect < dAspectOut)
                {
                    // alter y coords            
                    dFactor = dCurrentAspect / dAspectOut;

                    bounds.TopLeft.Y = (bounds.TopLeft.Y - centerY) * (float)dFactor + centerY;
                    bounds.TopRight.Y = (bounds.TopRight.Y - centerY) * (float)dFactor + centerY;
                    bounds.BottomLeft.Y = (bounds.BottomLeft.Y - centerY) * (float)dFactor + centerY;
                    bounds.BottomRight.Y = (bounds.BottomRight.Y - centerY) * (float)dFactor + centerY;
                }
                else
                {
                    // alter x coords
                    dFactor = dAspectOut / dCurrentAspect;

                    bounds.TopLeft.X = (bounds.TopLeft.X - centerX) * (float)dFactor + centerX;
                    bounds.TopRight.X = (bounds.TopRight.X - centerX) * (float)dFactor + centerX;
                    bounds.BottomLeft.X = (bounds.BottomLeft.X - centerX) * (float)dFactor + centerX;
                    bounds.BottomRight.X = (bounds.BottomRight.X - centerX) * (float)dFactor + centerX;
                }

                // set it to new bounds
                keyframe.Bounds = bounds;

                // restore rotation.        
                keyframe.RotateBy(rotation);
            }
            catch
            {
                // restore original settings on error
                keyframe = keyframeSave;
            }
        }

        public void ScaleKeyframe(VideoMotionKeyframe keyframe, float szChange, float rotAngle)
        {
            float cWidth = (1 / (szChange / 100));
            float cHeight = (1 / (szChange / 100));

            if (szChange > 100)
            {
                cWidth = (szChange / 100);
                cHeight = (szChange / 100);
            }

            VideoMotionVertex bounds = new VideoMotionVertex(cWidth, cHeight);

            keyframe.ScaleBy(bounds);
            keyframe.RotateBy((rotAngle * (Math.PI / 180)));
        }

    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

 

jetdv wrote on 1/18/2023, 11:58 AM

@m3lquixd @3POINT Here's what I'm getting with images smaller than the frame size in this last version:

Original:

And what I get after running the script:

It's honestly very close to the video I originally posted but did need a few modifications to get to this point.

m3lquixd wrote on 1/18/2023, 12:00 PM

It only worked for lower resolution media. The bigger ones didn't work.
@jetdv Is there any way for the script to automatically identify when it's bigger and smaller than the project?

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

m3lquixd wrote on 1/18/2023, 12:02 PM

I've uploaded here the images I'm using, you can test with them. @jetdv
https://drive.google.com/drive/folders/13ocx38QEkLgI0I70iQWADcaAsfEEKFMI?usp=share_link

Last changed by m3lquixd on 1/18/2023, 12:02 PM, changed a total of 1 times.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

m3lquixd wrote on 1/18/2023, 12:04 PM

@m3lquixd @3POINT Here's what I'm getting with images smaller than the frame size in this last version:

I think you don't need to mark the 3POINT. Who needed the script was me and @Yelandkeil

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

jetdv wrote on 1/18/2023, 12:16 PM

@m3lquixd, @3POINT, @Yelandkeil Thanks for the examples. That helped. I had been testing with images that are bigger/bigger or smaller/smaller than the frame size. I had not tested any that were bigger/smaller or smaller/bigger than the frame size which is why it was failing for those two images. Try this one:
 

using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            float scrWidth = myVegas.Project.Video.Width;
            float scrHeight = myVegas.Project.Video.Height;

            foreach (Track myTrack in myVegas.Project.Tracks)
            {
              if (myTrack.isVideo())
              {
                foreach (VideoEvent evnt in myTrack.Events)
                {
                    if (evnt.Selected)
                    {
                        MatchAspect(evnt);

                        VideoEvent videoEvent = evnt as VideoEvent;
                        VideoMotionKeyframes keyframes = videoEvent.VideoMotion.Keyframes;
                        int cKeyframes = keyframes.Count;
                        for (int jj = cKeyframes - 1; jj >= 0; jj--)
                        {
                            VideoMotionKeyframe thisKeyframe = keyframes[jj] as VideoMotionKeyframe;

                            float dWidth = Math.Abs(thisKeyframe.TopRight.X - thisKeyframe.TopLeft.X);
                            float dHeight = Math.Abs(thisKeyframe.BottomLeft.Y - thisKeyframe.TopLeft.Y); ;

                            MediaStream mediaStream = GetActiveMediaStream(videoEvent);
                            VideoStream videoStream = mediaStream as VideoStream;
                            VideoOutputRotation vRotation = videoStream.Rotation;

                            float dFullHeight = videoStream.Height;
                            float dFullWidth = videoStream.Width;
                            if ((vRotation == VideoOutputRotation.QuarterTurnClockwise) || (vRotation == VideoOutputRotation.QuarterTurnCounterclockwise))
                            {
                                dFullHeight = videoStream.Width;
                                dFullWidth = videoStream.Height;
                            }

                            float pwid = 0.0F;
                            float wpwid = 0.0F;
                            bool smaller = false;

                            if (dFullHeight > scrHeight)
                            {
                                pwid = dFullHeight / dHeight * 100;
                            }
                            else
                            {
                                pwid = dHeight / dFullHeight * 100;
                                smaller = true;
                            }

                            if (dFullWidth > scrWidth)
                            {
                                smaller = false;
                                wpwid = dFullWidth / dWidth * 100;
                            }
                            else
                            {
                                wpwid = dWidth / dFullWidth * 100;
                            }

                            if (wpwid > pwid && !smaller)
                            {
                                pwid = wpwid;
                            }
                            if (wpwid < pwid && smaller)
                            {
                                pwid = wpwid;
                            }

                            ScaleKeyframe(thisKeyframe, pwid, 0);
                        }
                    }
                }
              }
            }
        }

        public void MatchAspect(TrackEvent trackEvent)
        {
            float dWidthProject = myVegas.Project.Video.Width;
            float dHeightProject = myVegas.Project.Video.Height;
            double dPixelAspect = myVegas.Project.Video.PixelAspectRatio;
            double dAspect = dPixelAspect * dWidthProject / dHeightProject;

            MediaStream mediaStream = GetActiveMediaStream(trackEvent);
            if (!(mediaStream == null))
            {
                VideoStream videoStream = mediaStream as VideoStream;

                double dMediaPixelAspect = videoStream.PixelAspectRatio;
                VideoEvent videoEvent = trackEvent as VideoEvent;
                VideoMotionKeyframes keyframes = videoEvent.VideoMotion.Keyframes; ;

                int cKeyframes = keyframes.Count;

                for (int jj = cKeyframes - 1; jj >= 0; jj--)
                {
                    VideoMotionKeyframe thisKeyframe = keyframes[jj] as VideoMotionKeyframe;
                    MatchOutputAspect(thisKeyframe, dMediaPixelAspect, dAspect);
                }
            }
            myVegas.UpdateUI();
        }

        public MediaStream GetActiveMediaStream(TrackEvent trackEvent)
        {
            try
            {
                if (!(trackEvent.ActiveTake.IsValid()))
                {
                    throw new ArgumentException("empty or invalid take");
                }

                Media media = myVegas.Project.MediaPool.Find(trackEvent.ActiveTake.MediaPath);
                if (null == media)
                {
                    MessageBox.Show("missing media");
                    throw new ArgumentException("missing media");
                }

                MediaStream mediaStream = media.Streams.GetItemByMediaType(MediaType.Video, trackEvent.ActiveTake.StreamIndex);
                return mediaStream;
            }
            catch (Exception e)
            {
               MessageBox.Show("{0}", e.Message);
              return null;
            }
        }


        public void MatchOutputAspect(VideoMotionKeyframe keyframe, double dMediaPixelAspect, double dAspectOut)
        {
            VideoMotionKeyframe keyframeSave = keyframe;

            try
            {
                double rotation = keyframe.Rotation;
                keyframe.RotateBy(-rotation);

                float dWidth = Math.Abs(keyframe.TopRight.X - keyframe.TopLeft.X);
                float dHeight = Math.Abs(keyframe.BottomLeft.Y - keyframe.TopLeft.Y);
                double dCurrentAspect = dMediaPixelAspect * dWidth / dHeight;
                float centerY = keyframe.Center.Y;
                float centerX = keyframe.Center.X;
                double dFactor;

                VideoMotionBounds bounds = new VideoMotionBounds(keyframe.TopLeft, keyframe.TopRight, keyframe.BottomRight, keyframe.BottomLeft);
                if (dCurrentAspect < dAspectOut)
                {
                    // alter y coords            
                    dFactor = dCurrentAspect / dAspectOut;

                    bounds.TopLeft.Y = (bounds.TopLeft.Y - centerY) * (float)dFactor + centerY;
                    bounds.TopRight.Y = (bounds.TopRight.Y - centerY) * (float)dFactor + centerY;
                    bounds.BottomLeft.Y = (bounds.BottomLeft.Y - centerY) * (float)dFactor + centerY;
                    bounds.BottomRight.Y = (bounds.BottomRight.Y - centerY) * (float)dFactor + centerY;
                }
                else
                {
                    // alter x coords
                    dFactor = dAspectOut / dCurrentAspect;

                    bounds.TopLeft.X = (bounds.TopLeft.X - centerX) * (float)dFactor + centerX;
                    bounds.TopRight.X = (bounds.TopRight.X - centerX) * (float)dFactor + centerX;
                    bounds.BottomLeft.X = (bounds.BottomLeft.X - centerX) * (float)dFactor + centerX;
                    bounds.BottomRight.X = (bounds.BottomRight.X - centerX) * (float)dFactor + centerX;
                }

                // set it to new bounds
                keyframe.Bounds = bounds;

                // restore rotation.        
                keyframe.RotateBy(rotation);
            }
            catch
            {
                // restore original settings on error
                keyframe = keyframeSave;
            }
        }

        public void ScaleKeyframe(VideoMotionKeyframe keyframe, float szChange, float rotAngle)
        {
            float cWidth = (1 / (szChange / 100));
            float cHeight = (1 / (szChange / 100));

            if (szChange > 100)
            {
                cWidth = (szChange / 100);
                cHeight = (szChange / 100);
            }

            VideoMotionVertex bounds = new VideoMotionVertex(cWidth, cHeight);

            keyframe.ScaleBy(bounds);
            keyframe.RotateBy((rotAngle * (Math.PI / 180)));
        }

    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

 

m3lquixd wrote on 1/18/2023, 12:23 PM

@jetdv Tested and approved. Perfect! You're the best!

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

m3lquixd wrote on 1/18/2023, 12:24 PM

The issue is resolved, but I would still like this to be native to vegas.

About me:
Hi! Melqui Calheiros Here. I've been using Vegas as my only video editor for over 10 years. I edit professionally for various influencers, public bodies and small businesses. My goal is to squeeze Vegas to the fullest! And end the prejudice that software has here in Brazil.

⬇️ Some of my jobs. ⬇️
https://www.vegascreativesoftware.info/us/forum/post-your-vegas-creations--109464/?page=37#ca872169

PC Specs:
Operating System:
    Windows 11 Pro 64-bit
CPU:
    AMD Ryzen 3 3200G 3.60 GHz
RAM:
    32,0GB Dual-Channel DDR4 2666MHz
Motherboard:
    BIOSTAR Group B450MX-S (AM4)
Graphics:
    4095MB NVIDIA GeForce GTX 1650 (ZOTAC International)
Storage:
    465GB Seagate ST500DM002-1BD142 (SATA )
    238GB Lexar 256GB SSD (SATA (SSD))
  931GB KINGSTON SNV2S1000G (SATA-2 (SSD))

jetdv wrote on 1/18/2023, 12:27 PM

If you go to www.jetdv.com, you'll see all of my tutorials there along with other information including my old PDF newsletters (if you go far enough back in time) and, if you really like what you've seen, there's also a "donate" button available.

Vegas_Pro_Brasil wrote on 1/18/2023, 12:41 PM

@jetdv The two scripts work correctly for different purposes. The first script resize to the original size of the media and the second script resize to match output aspect without rescale the original media. Thinks! They are very useful scripts.

@m3lquixd Your suggestions are very good and reflect the real needs of those who work with video editing. Based on your screen recording, I think you must be from Brazil. It's good to see another Brazilian here on the forum. I am from Brazil too. If not, sorry for the mistake.

jetdv wrote on 1/18/2023, 12:46 PM

@Vegas_Pro_Brasil, yes, I agree. Both are useful. The "original" version resizes smaller images back to their original size which is where the script first came from - a way to resize "logos" back to their original sizes instead of them being full frame. It's actually from the "logo resize" tool in Excalibur. This new version will always fill the screen horizontally or vertically depending on which direction is larger.