0

我想使用 MPV 播放器来执行对象的手动跟踪。我只是想在电影运行时跟踪鼠标在视频窗口上的点击,并将视频时间(如果可能的话以帧数)、x 和 y 绝对位置(相对于图像角,因此值不应该)复制到剪贴板受图像缩放或平移的影响)。我看到这段代码来获取时间,我尝试修改以获得基于我在网络上找到的另一个“.lua”脚本的 x 和 y 位置,但显然它没有运行(我不是程序员):

*require 'mp'
local function set_clipboard(text)
mp.commandv("run", "powershell", "set-clipboard", text);
end
local function copyTime()
local time_pos = mp.get_property_number("time-pos")
local time_in_seconds = time_pos
local time_seg = time_pos % 60
time_pos = time_pos - time_seg
local time_hours = math.floor(time_pos / 3600)
time_pos = time_pos - (time_hours * 3600)
local time_minutes = time_pos/60
time_seg,time_ms=string.format("%.09f", time_seg):match"([^.]*).(.*)"
time = string.format("%02d:%02d:%02d.%s", time_hours, time_minutes, time_seg, time_ms)
mp.osd_message(string.format("Copied to Clipboard: %s", time))
set_clipboard(time)
end
mp.add_key_binding("c", "copyTime", copyTime)*

我试图“合并”这段代码和另一段代码:

*-[[
usage: place script into $HOME/.mpv/lua/ directory (mpv 0.4 and later)
or run mpv --lua path/to/capture.lua
or add "lua=/absolute/path/to/capture.lua" to ~/.mpv/config
keybindings:
a - capture fragment: at first press script remembers start position, at second outputs command for encoding
c - crop: first press remembers mouse cursor coords, second outputs crop filter parameters.
]]
capture = {}
local gp
if mp.get_property == nil then
gp = mp.property_get
else
gp = mp.get_property
end
function capture.handler()
local c = capture
if c.start then
print(string.format("ffmpeg -ss %s -i '%s' -t %s",
c.start, gp("path"), gp("time-pos")-c.start))
print(string.format("WebMaster -s %s -t %s '%s'",
c.start, gp("time-pos")-c.start, gp("path")))
c.start = nil
else
c.start = gp("time-pos")
end
end
function capture.crop()
local x, y = mp.get_mouse_pos()
local resX, resY = mp.get_osd_resolution()
-- print(x .. ":" .. y .. " " .. resX .. "x" .. resY )
local c = capture
if c.pos then
local pos2 = mp.get_mouse_pos()
local w, h = gp('width'), gp('height')
print(string.format("crop=%d:%d:%d:%d",
(x - c.pos[1]) * w / resX, (y - c.pos[2]) * h / resY,
c.pos[1] * w / resX, c.pos[2] * h / resY))
c.pos = nil
else
c.pos = {x, y}
end
end
--mp.add_key_binding("a", "capture", capture.handler)
mp.set_key_bindings({
{"c", capture.crop},
{"a", capture.handler}
})
mp.enable_key_bindings()*

所以我生成了这段代码:

*require 'mp'
local function set_clipboard(text)
mp.commandv("run", "powershell", "set-clipboard", text);
end
local function copyTime_and_XY()
local x, y = mp.get_mouse_pos()
local resX, resY = mp.get_osd_resolution()
-- print(x .. ":" .. y .. " " .. resX .. "x" .. resY )
c.pos = {x, y, z}
mp.osd_message(string.format("Copied to Clipboard: c.pos))
local time_pos = mp.get_property_number("time-pos")
local time_in_seconds = time_pos
local time_seg = time_pos % 60
time_pos = time_pos - time_seg
local time_hours = math.floor(time_pos / 3600)
time_pos = time_pos - (time_hours * 3600)
local time_minutes = time_pos/60
time_seg,time_ms=string.format("%.09f", time_seg):match"([^.]*).(.*)"
time = string.format("%02d:%02d:%02d.%s", time_hours, time_minutes, time_seg, time_ms)
mp.osd_message(string.format("Copied to Clipboard: %s", time, x, y))
set_clipboard(time, x, y)
end
mp.add_key_binding("c", "copyTime_and_XY", copyTime_and_XY)*

如果有人可以帮助我,我将不胜感激,因为我无法执行这个看似简单的任务。

谢谢,

加布里埃尔

4

0 回答 0