Created
November 10, 2020 03:58
-
-
Save logchan/508843805234ca24bc96d5cdafb11eea to your computer and use it in GitHub Desktop.
Vegas Pro script that fits a track event to the media's original size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Vegas Pro script that fits a track event to the media's original size | |
| // Background: when a media is added to a track, it is scaled to fit the project's video dimensions | |
| // This script scales it back to its original size | |
| // It works by changing the first frame of video motion | |
| // If using Vegas Pro 14 or later, comment Sony.Vegas and uncomment ScriptPortal.Vegas | |
| using Sony.Vegas; | |
| // using ScriptPortal.Vegas; | |
| public class EntryPoint { | |
| public void FromVegas(Vegas vegas) { | |
| var projWidth = vegas.Project.Video.Width; | |
| var projHeight = vegas.Project.Video.Height; | |
| var projRatio = projWidth / (float) projHeight; | |
| foreach (var track in vegas.Project.Tracks) { | |
| foreach (var ev in track.Events) { | |
| if (!ev.Selected) { | |
| continue; | |
| } | |
| if (!(ev is VideoEvent)) { | |
| continue; | |
| } | |
| var ve = (VideoEvent) ev; | |
| var motion = ve.VideoMotion; | |
| var frame = motion.Keyframes[0]; | |
| var w = frame.TopRight.X - frame.TopLeft.X; | |
| var h = frame.BottomLeft.Y - frame.TopLeft.Y; | |
| var ratio = w / h; | |
| var zoom = ratio > projRatio ? projWidth / w : projHeight / h; | |
| frame.ScaleBy(new VideoMotionVertex(zoom, zoom)); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment