An OBS lua script to zoom a display-capture source to focus on the mouse.
I made this for my own use when recording videos as I wanted a way to zoom into my IDE when highlighting certain sections of code. My particular setup didn't seem to work very well with the existing zooming solutions so I created this.
Built with OBS v29.1.3
Now works on Windows, Linux, and Mac
Inspired by tryptech's obs-zoom-and-follow
obs-zoom-to-mouse.lua
)Display Capture
source (if you don't have one already)+
button to add a new scriptobs-zoom-to-mouse.lua
scriptFor best results use the following settings on your Display Capture
source
Top Left
Scale to inner bounds
Top Left
Crop/Pad
False
Note: If you don't use this form of setup for your display source (E.g. you have bounding box set to No bounds
or you have a Crop
set on the transform), the script will attempt to automatically change your settings to zoom compatible ones.
This may have undesired effects on your layout (or just not work at all).
Note: If you change your desktop display properties in Windows (such as moving a monitor, changing your primary display, updating the orientation of a display), you will need to re-add your display capture source in OBS for it to update the values that the script uses for its auto calculations. You will then need to reload the script.
You can customize the following settings in the OBS Scripts window:
Toggle follow
hotkey to be pressed firstIn OBS, open File -> Settings -> Hotkeys
Toggle zoom to mouse
to zoom in and outToggle follow mouse during zoom
to turn mouse tracking on and off (Optional)obs-zoom-to-mouse.lua
, the following settings will also be available:
When you press the Toggle zoom
hotkey the script will use the current mouse position as the center of the zoom. The script will then animate the width/height values of a crop/pan filter so it appears to zoom into that location. If you have Auto follow mouse
turned on, then the x/y values of the filter will also change to keep the mouse in view as it is animating the zoom. Once the animation is complete, the script gives you a "safe zone" to move your cursor in without it moving the "camera". The idea was that you'd want to zoom in somewhere and move your mouse around to highlight code or whatever, without the screen moving so it would be easier to read text in the video.
When you move your mouse to the edge of the zoom area, it will then start tracking the cursor and follow it around at the Follow Speed
. It will continue to follow the cursor until you hold the mouse still for some amount of time determined by Lock Sensitivity
at which point it will stop following and give you that safe zone again but now at the new center of the zoom.
How close you need to get to the edge of the zoom to trigger the 'start following mode' is determined by the Follow Border
setting. This value is a pertentage of the area from the edge. If you set this to 0%, it means that you need to move the mouse to the very edge of the area to trigger mouse tracking. Something like 4% will give you a small border around the area. Setting it to full 50% causes it to begin following the mouse whenever it gets closer than 50% to an edge, which means it will follow the cursor all the time essentially removing the "safe zone".
You can also modify this behavior with the Auto Lock on reverse direction
setting, which attempts to make the follow work more like camera panning in a video game. When moving your mouse to the edge of the screen (how close determined by Follow Border
) it will cause the camera to pan in that direction. Instead of continuing to track the mouse until you keep it still, with this setting it will also stop tracking immediately if you move your mouse back towards the center.
If you enable the Show all sources
option, you will be able to select any OBS source as the Zoom Source
. This includes any non-display capture items such as cloned sources, browsers, or windows (or even things like audio input - which really won't work!).
Selecting a non-display capture zoom source means the script will not be able to automatically calculate the position and size of the source, so zooming and tracking the mouse position will be wrong!
To fix this, you MUST manually enter the size and position of your selected zoom source by enabling the Set manual source position
option and filling in the X
, Y
, Width
, and Height
values. These values are the pixel topleft position and pixel size of the source on your overall desktop. You may also need to set the Scale X
and Scale Y
values if you find that the mouse position is incorrectly offset when you zoom, which is due to the source being scaled differently than the monitor you are using.
Example 1 - A 500x300 window positioned at the center of a single 1000x900 monitor, would need the following values:
Example 2 - A cloned display-capture source which is using the second 1920x1080 monitor of a two monitor side by side setup:
Example 3 - A cloned scene source which is showing a 1920x1080 monitor but the scene canvas size is scaled down to 1024x768 setup:
I don't know of an easy way of getting these values automatically otherwise I would just have the script do it for you.
Note: If you are also using a transform crop
on the non-display capture source, you will need to manually convert it to a Crop/Pad Filter
instead (the script has trouble trying to auto convert it for you for non-display sources).
Only works on Display Capture
sources (automatically)
Show all sources
option to select a non-display capture source, but you MUST set manual source position valuesUsing Linux:
XSHM
display capture sources. This source acts most like the ones used by Windows and Mac so the script can auto calculate sizes for you.Pipewire
sources, but you will need to enable Allow any zoom source
and Set manual source position
since the script cannot get the size by itself.Using Mac:
Set manual source position
you may need to set the Monitor Height
value as it is used to invert the Y coordinate of the mouse position so that it matches the values of Windows and Linux that the script expects.obs-zoom-to-mouse.lua
Reload Scripts
in the OBS Scripts windowWant to support me staying awake long enough to add some more features?