Advertisement
constantin-net

mpv_get_mouse_coord_v02

Sep 29th, 2023
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. capture = {}
  2. local gp
  3. if mp.get_property == nil then
  4.     gp = mp.property_get
  5. else
  6.     gp = mp.get_property
  7. end
  8. function capture.handler()
  9.     local c = capture
  10.     local osd_w, osd_h = mp.get_osd_size()
  11.     local x, y = mp.get_mouse_pos()
  12.     local rw = mp.get_property("width")
  13.     local rh = mp.get_property("height")
  14.     local ml = mp.get_property("osd-dimensions/ml")
  15.     local mt = mp.get_property("osd-dimensions/mt")
  16.     x = ( x - ml ) * rw / ( osd_w - 2 * ml )
  17.     y = ( y - mt ) * rh / ( osd_h - 2 * mt )
  18.     if c.trig then
  19.         mp.commandv("show-text", string.format("coord 2 x=%d ; y=%d" , x, y))
  20.         local f = assert(io.open("/tmp/webm_crop2", "w"))
  21.         f:write(string.format("%d:%d", x, y))
  22.         f:close()
  23.         c.trig = nil
  24.     else
  25.         mp.commandv("show-text", string.format("coord 1 x=%d ; y=%d" , x, y))
  26.         local f = assert(io.open("/tmp/webm_crop1", "w"))
  27.         f:write(string.format("%d:%d", x, y))
  28.         f:close()
  29.         c.trig = 1
  30.     end
  31. end
  32. mp.add_forced_key_binding("F9", capture.handler)
  33. if bindings_enabled then toggle_bindings(true, true) end
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement