VideoHelp Forum


Try D·V·D Fab Video Downloader and rip Netflix video! Or Try D·V·D Fab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 6 of 6
Thread
  1. Member
    Join Date
    Mar 2021
    Location
    Granada, Espaņa
    Search Comp PM
    Hello all,

    I want to use MPV player to perform manual tracking of object. I simply want to track the mouse click on a video window while a movie is running and copy to clipboard the video time (in number of frames if possible), the x and y absolute position (respect to the image corner so the value should not be affected by the zoom or the pan of the image).

    I see this code to obtain the time and I try to modify to also obtain the x and y position based on another ".lua" script I find in the web but obviously it doesnīt run (I am not programmer):
    ------------------------------------------------------------------------------------------------------------------------
    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)
    -----------------------------------------------------------------------------------------------------------------


    I tried to "merge" this code and this other one code:
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------
    -[[
    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()
    ------------------------------------------------------------------------------------------------------------------------------------------
    So I generate this code:

    --------------------------------------------------------------------------------------------------------------------------------------------
    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)
    ------------------------------------------------------------------------------------------------------------------

    I attach the files.

    If someone could help me I would appreciate a lot since I am not capable to perform this apparently simple task.

    Thanks,

    Gabriel
    Image Attached Files
    Quote Quote  
  2. - start mpv from command-line, it will report any errors there.

    1) get video time (in number of frames if possible), the x and y absolute mouse position
    try printing the properties to the OSD, console or window title.
    standard video time isn't difficult to obtain.

    2) copy a string to the Windows clipboard.
    certainly there are scripts which can do this.
    Quote Quote  
  3. Member
    Join Date
    Mar 2021
    Location
    Granada, Espaņa
    Search Comp PM
    Hi Butterw,

    Thanks a lot for the fast reply... I have tried to run mpv from the command line but I am not capable. I have no programming knowledge (I only know a little of Visual Basic for Applications, but very little).

    I do not know how to print the properties on the OSD (I do not know what is the OSD)

    The time is easy to obtain, I use the script I sent in the previous message and I obtain it. Do you think it is also possible to obtain the mouse coordinates when clicking? I haven't seen any script for this purpose...

    It would be fantastic to generate a .txt or .csv file with the values of the mouse clicks but I imagine that this is more difficult that only having it in the clipboard.

    Obtaining the x, y and time and having it recorded on the clipboard I would be very happy

    Thanks,

    Gabriel
    Quote Quote  
  4. There is a learning curve with mpv scripting.
    I'm afraid I am not familiar with .lua, and haven't used the mouse-pos property.

    mpv video.mp4 --title="${time-pos} ${mouse-pos}"
    Quote Quote  
  5. Member
    Join Date
    Mar 2021
    Location
    Granada, Espaņa
    Search Comp PM
    Hi Butter,

    Thanks a lot!!

    Wow, I didnīt knew the code was so easy... Where I have to paste this code? This is from the command prompt? Please could you show me a simple code to obtain the coordinates of a video with this path:
    C:\Users\gabri\OneDrive\Escritorio\Slow motion video of vertical jump with synchronized vertical force data.mp4

    I open the command prompt (do you recommend me to do this from the PowerShell?). And then what I have to do?

    I have tried this in the command prompt:

    C:\Users\gabri>C:\zportables\mwp\mpv.exe

    The software open and then I type this:

    C:\Users\gabri>mpv video.mp4 --title="${time-pos} ${mouse-pos}"
    "mpv" no se reconoce como un comando interno o externo,
    programa o archivo por lotes ejecutable.

    The error in english would say: mpv is not recognized as a internal or external command, software or file exectuable (or something similar)...

    Regards
    Quote Quote  
  6. Member
    Join Date
    Mar 2021
    Location
    Granada, Espaņa
    Search Comp PM
    I have tried to open the video from the command prompt but I have a message error:

    C:\zportables\mwp>mpv OP\C:\Users\gabri\OneDrive\Escritorio\idea Software digitalizacion comprimido.mp4/

    Cannot find main.* for any supported scripting backend in: C:\Users\gabri\AppData\Roaming/mpv/scripts/fuera de juego
    Can't load unknown script: C:\Users\gabri\AppData\Roaming/mpv/scripts/copyTime_and_XY - copia.txt
    Can't load unknown script: C:\Users\gabri\AppData\Roaming/mpv/scripts/Capture.txt
    [copyTime_and_XY]
    [copyTime_and_XY] stack traceback:
    [copyTime_and_XY] [C]: at 0x01041a50
    [copyTime_and_XY] Lua error: [string "C:\Users\gabri\AppData\Roaming/mpv/scripts/co..."]:13: unfinished string near '"Copied to Clipboard: c.pos)) '
    Playing: OP\C:\Users\gabri\OneDrive\Escritorio\idea
    [file] Cannot open file 'OP\C:\Users\gabri\OneDrive\Escritorio\idea': Invalid argument
    Failed to open OP\C:\Users\gabri\OneDrive\Escritorio\idea.

    Playing: Software
    [file] Cannot open file 'Software': No such file or directory
    Failed to open Software.

    Playing: digitalizacion
    [file] Cannot open file 'digitalizacion': No such file or directory
    Failed to open digitalizacion.

    Playing: comprimido.mp4/
    [file] Cannot open file 'comprimido.mp4/': No such file or directory
    Failed to open comprimido.mp4/.

    Exiting... (Errors when loading file)
    Quote Quote  



Similar Threads