Resource icon

Zoom to Mouse 1.0.1

BlankSourceCode submitted a new resource:

Zoom to Mouse - Zoom a display capture source to your mouse position

An OBS lua script to zoom a display-capture source to focus on the mouse when you press the assigned hotkey.

I made this script for my own use when recording videos. I wanted a way to zoom into my IDE when highlighting certain sections of code. I know there are existing solutions for zooming in OBS but I couldn't get them working the way I wanted with my setup, so I made this.

Maybe it will be useful for someone else too.

Currently Windows only.

Read more about this resource...
 
I followed the instructions on the github page and it didn't work. I added the dependencies from https://github.com/tryptech/obs-zoom-and-follow and installed phyton and now it does work.

Have you tried installing it with a fresh system? Do I need the dependencies and phyton for this to work?
I'm sorry that you had trouble getting the script to work. The obs-zoom-to-mouse.lua script itself is written in pure lua with no external dependencies (unless you count lua FFI but that comes built into OBS) and it doesn't use any python at all so I'm not sure why you needed to install anything extra.

Just to be sure, I installed OBS 30 to a fresh machine, added a display capture source, then added the obs-zoom-to-mouse.lua script and set the zoom hotkey. It seemed to work just fine on that machine which has never had python (or anything else beyond Windows) installed.

My only guess is that OBS got into some odd state and restarting after you installed python fixed it for you?

Thanks for trying out the script though.
 

Kintaric

New Member
Thank you for this amazing script! I might be over looking something and forgive me if I am, but was there any way for multiple sources to be used in conjunction with this script? As of right now I can only have one lua script of zoom-to-mouse added for all sources. I was hoping to add two more monitors but was not able to since one instance of the script can be applied for any given source at a time. Thank you for any advice or guidance and thank you again for this amazing script!
 

Alva

New Member
Thanks for this amazing script. It works peprfectly for my desktop capture and nested scene of it. But it doesnt work if its a source clone of it on another scene. Maybe a thing for the next update, i would love it :)
 
Thanks for this amazing script. It works peprfectly for my desktop capture and nested scene of it. But it doesnt work if its a source clone of it on another scene. Maybe a thing for the next update, i would love it :)
Yes, currently the script can only work against one source at a time, and the source-clone creates a new one which is separate to the original.

A workaround could be to have 2 copies of the script:
  1. Copy/paste/rename obs-zoom-to-mouse.lua to some other name
  2. Add that new script to obs alongside the original
  3. In the second copy of the script, enable "Allow any zoom source" to allow you to pick from non-display capture sources
  4. Select your source-clone as the zoom source
  5. Enable "Set manual source position" so that you can specify the size and location of the display the clone is copying
  6. Set those correct X,Y,Width/Height/ScaleX/ScaleY values
  7. Add a zoom toggle hotkey (you might even be able to use the same one - I'm not sure)
Then you should be able to zoom into the original display capture source using script1, and script2 will zoom into the cloned source.

You will have to play around with the manual source position values because the script won't be able to auto calculate them for the non-display source. You can take a look at the readme on the github page for an example of what you might need to set, but it's usually just the position of the source on your desktop. So if you are cloning your primary display, it'll be x0,y0 and w1920,h1080 (or whatever your resolution is). The scaling values gets tricky if the clone isn't using a 1:1 pixel mapping (aka your desktop is 4k but you are recording at 2k so the canvas and clone are smaller than your actual monitor resolution) but you should be able figure it out with some trial and error.
 
Thank you for this amazing script! I might be over looking something and forgive me if I am, but was there any way for multiple sources to be used in conjunction with this script? As of right now I can only have one lua script of zoom-to-mouse added for all sources. I was hoping to add two more monitors but was not able to since one instance of the script can be applied for any given source at a time. Thank you for any advice or guidance and thank you again for this amazing script!
Oh, I just noticed this.

You should be able to add a second copy of the script (with a rename) and add that to obs too. Then in the second copy just point it at a different zoom source.

Take a look at the reply above for some better steps to follow (though it'll be easier if you aer just using another display source in script2)

Thanks for trying the script!
 
Its still captures only display source, so I cannot use it with many sources.
In the latest script (maybe you need to download it again) there is an option to "Allow any zoom source". If you enable that, you should be able to select non-display capture sources from the zoom source drop down.

You will need to manually set the source position though using the settings, because the script won't be able to calculate it for you when using a non-display capture source (which is why it is behind a checkbox option).

Take a look at the GitHub readme for more information.
 

troyhammaren

New Member
I love this script. Awsome work! With my 32:9 Display, it only follows the mouse within a16:9 area (in the center). Is there a setting to change this behavior so it follows the mouse within the full display width?
 
I love this script. Awsome work! With my 32:9 Display, it only follows the mouse within a16:9 area (in the center). Is there a setting to change this behavior so it follows the mouse within the full display width?
What does OBS show for the properties of your display-capture source? It's possible the script is calculating the wrong size for the monitor.

You could try enabling "Set manual source position" and then setting width and height to the correct resolution of your monitor, and x,y to 0 (unless it isn't your primary display).

Enabling debug logs may show some useful information too. Feel free to open a GitHub issue with the log if there is something unusual.

Thanks for trying the script.
 

wellzish

New Member
Great script. Installed on Laptop OBS and works like a charm. However on my Multi monitor (3) Desktop Zoom and follow mouse function "works" but is tracking mouse movement on a monitor that isn't the display capture source (ie Mouse movement on monitor 3 is the what is being tracked for display capture on monitor 2)
 
Great script. Installed on Laptop OBS and works like a charm. However on my Multi monitor (3) Desktop Zoom and follow mouse function "works" but is tracking mouse movement on a monitor that isn't the display capture source (ie Mouse movement on monitor 3 is the what is being tracked for display capture on monitor 2)
That's weird, it must be calculating the bounds of the display incorrectly. What does OBS show for the properties of your display-capture source?

You could try enabling "Set manual source position" and then setting width and height to the resolution of your monitor, and x,y to actual position of monitor 3 on your overall desktop. So if you have 3 1920x1080 monitors side by side, the third would probably be x=3840,y=0
 

wellzish

New Member
That's weird, it must be calculating the bounds of the display incorrectly. What does OBS show for the properties of your display-capture source?

You could try enabling "Set manual source position" and then setting width and height to the resolution of your monitor, and x,y to actual position of monitor 3 on your overall desktop. So if you have 3 1920x1080 monitors side by side, the third would probably be x=3840,y=0
Thanks for the reply I think I figured it out. So I use (2) 2560 x 1440 monitors and a vertical 1080x1920 monitor. The Center Monitor Is set as the Primary Display. If I Make the Left Monitor the Primary everything works like a charm. Doing some checking with the Bar Raider Move Window plugin To Check how windows sees the Transform, it Sees the Left monitor top left as x = -2560 and y as 0. Currently the script only allows positive integers for X offset. May be worth implementing, but it's likely a edge case. Thanks again for the awesome plugin
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    14 KB · Views: 55
Thanks for the reply I think I figured it out. So I use (2) 2560 x 1440 monitors and a vertical 1080x1920 monitor. The Center Monitor Is set as the Primary Display. If I Make the Left Monitor the Primary everything works like a charm. Doing some checking with the Bar Raider Move Window plugin To Check how windows sees the Transform, it Sees the Left monitor top left as x = -2560 and y as 0. Currently the script only allows positive integers for X offset. May be worth implementing, but it's likely a edge case. Thanks again for the awesome plugin

This is great detective work, thanks!

You are correct in that the script wasn't correctly accounting for negative offsets when it calculated the display position (aka parsed OBS properties for that source).

I've updated the script in github with a fix, and also fixed it to allow you to set negative offset values in the settings UI.
 

troyhammaren

New Member
What does OBS show for the properties of your display-capture source? It's possible the script is calculating the wrong size for the monitor.

You could try enabling "Set manual source position" and then setting width and height to the correct resolution of your monitor, and x,y to 0 (unless it isn't your primary display).

Enabling debug logs may show some useful information too. Feel free to open a GitHub issue with the log if there is something unusual.

Thanks for trying the script.
Not sure if it is a bug or just my settings, or maybe what I'm trying to achieve is simply not possible :D

These are my transform settings for the desktop capture:

2023-11-26_06-28-48.png


By default (zoom disabled), it shows the middle area (2560x1440) of the capture (5120x1440), which is scaled to the height of 1080px.

Is it possible to follow the mouse across the whole width of the capture while using the full height of the canvas (1080)? If I scale down the capture to the width (instead of height) of the capture, it works, but then I can't use the full height even though it's zoomed.

I tried setting "Set manual source position" to the the resolution of my display, but it didn't make a difference.

Example, scaled to height: https://streamable.com/f5npzr
Example, scaled to width: https://streamable.com/5ryvi9
 
Not sure if it is a bug or just my settings, or maybe what I'm trying to achieve is simply not possible :D

These are my transform settings for the desktop capture:

By default (zoom disabled), it shows the middle area (2560x1440) of the capture (5120x1440), which is scaled to the height of 1080px.

Is it possible to follow the mouse across the whole width of the capture while using the full height of the canvas (1080)? If I scale down the capture to the width (instead of height) of the capture, it works, but then I can't use the full height even though it's zoomed.

I tried setting "Set manual source position" to the the resolution of my display, but it didn't make a difference.

Example, scaled to height: https://streamable.com/f5npzr
Example, scaled to width: https://streamable.com/5ryvi9

I can see the problem you are describing in the videos (in that the mouse isn't always visible in the zoom area even though it should be).

I think this is a limitation of how the script tries to stay within the bounds of the display, it doesn't account for really wide/high sources that go outside of the canvas (or something like that)

I'll need more time to be able to figure out a good way to calculate what those bounds are supposed to be (especially because I don't have a really wide monitor, awww).

As a really quick work around, you could delete lines 607 and 608 (assuming you are using the latest version of the script):

If you remove those lines it won't try to clamp the coordinates so you should see the mouse go all the way to the edge. Unfortunately, it will show a black area when it goes too far rather than stopping at the edge. Try it and reload the script to see what I mean.

You could also try modifying the lines instead of deleting them to add an offset to the clamp, for example:
Lua:
crop.x = math.floor(clamp(-500, (zoom.source_size.width - new_size.width) + 500, crop.x))
crop.y = math.floor(clamp(-200, (zoom.source_size.height - new_size.height) + 200, crop.y))

Here I've adjusted the x and y min/max values by 500 and 200 respectively. You'd need to play around a bit with the values to find the correct ones for your monitor. I'm sure there is some way to calculate what it should be, but I can't quite figure that out at the moment.

Hope that helps.
 

troyhammaren

New Member
I can see the problem you are describing in the videos (in that the mouse isn't always visible in the zoom area even though it should be).

I think this is a limitation of how the script tries to stay within the bounds of the display, it doesn't account for really wide/high sources that go outside of the canvas (or something like that)

I'll need more time to be able to figure out a good way to calculate what those bounds are supposed to be (especially because I don't have a really wide monitor, awww).

As a really quick work around, you could delete lines 607 and 608 (assuming you are using the latest version of the script):

If you remove those lines it won't try to clamp the coordinates so you should see the mouse go all the way to the edge. Unfortunately, it will show a black area when it goes too far rather than stopping at the edge. Try it and reload the script to see what I mean.

You could also try modifying the lines instead of deleting them to add an offset to the clamp, for example:
Lua:
crop.x = math.floor(clamp(-500, (zoom.source_size.width - new_size.width) + 500, crop.x))
crop.y = math.floor(clamp(-200, (zoom.source_size.height - new_size.height) + 200, crop.y))

Here I've adjusted the x and y min/max values by 500 and 200 respectively. You'd need to play around a bit with the values to find the correct ones for your monitor. I'm sure there is some way to calculate what it should be, but I can't quite figure that out at the moment.

Hope that helps.

I modified the first line and it now works exactly as I want it to (with a zoom factor of 2.0) :D

Lua:
crop.x = math.floor(clamp(-640, (zoom.source_size.width - new_size.width) + 640, crop.x))
crop.y = math.floor(clamp(0, (zoom.source_size.height - new_size.height), crop.y))

Thank you so much!
 

JR3D

New Member
I've installed this on my dual monitor setup and nothing happens, i get no errors or anything, hotkeys are set, but no zooming is occurring
 
Top