Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access playing time - feature request #4653

Closed
ghost opened this issue Jul 24, 2017 · 15 comments
Closed

access playing time - feature request #4653

ghost opened this issue Jul 24, 2017 · 15 comments

Comments

@ghost
Copy link

ghost commented Jul 24, 2017

Any platform or version

A simple way to access time and duration...
With Media player classic or pot player we can either:

  1. assign a key so player copies current time / duration to clipboard

    press key x ( clipboard is now 01:25 / 11:16 )

  2. or use windows messages, (better) eg with autohotkey

    ControlGetText, time, Static2, ahk_class mpv
    (time variable is now 01:25 / 11:16)

It may be possible using lua and socat and json ipc, but these technologies may be too complicated for a lot of potential developers

@Argon-
Copy link
Member

Argon- commented Jul 24, 2017

On OSX you can create a keybinding like this:

l run "/bin/sh" "-c" "echo ${playback-time} | pbcopy"

This should be possible for other systems as well when you swap the pasteboard program with whatever your system is using.

@wiiaboo
Copy link
Member

wiiaboo commented Jul 24, 2017

Here's some lua code to copy some text to clipboard. Right below there's also code that does what you probably want.

You would place this in a script, add a couple of lines to get current time/duration and then a key binding to copy those to clipboard.

This, of course, only works for Windows. For different systems there's different ways to use the clipboard.

Here's some other code to paste from clipboard that does work with all three common platforms. All you'd need to do is find the respective commands/programs to copy to clipboard instead.

@ghost
Copy link
Author

ghost commented Jul 24, 2017

thanks very much for your help,
I'll try testing the sample code you gave tomorrow.

@garoto
Copy link
Contributor

garoto commented Jul 24, 2017

For Windows Vista and later that ships with clip.exe, this works:

<KEY> run "cmd.exe" "/d" "/c" "echo ${playback-time} / ${duration}|clip"

Annoyingly with a \n at the end thanks to the shitastic cmd built-in echo. I recommend some GNU echo port as a better alternative.

@medhefgo
Copy link
Contributor

Maybe mpv should provide a set-clipboard command, then anyone can easily rebind their command to use it:
o show-text ${playback-time}; set-clipboard ${playback-time}

Would have the benefit of being cross platform and not requiring to run extra binaries just to clipboard something.

@Argon-
Copy link
Member

Argon- commented Jul 25, 2017

This command would be cross platform because then mpv would have to maintain platform-specific implementations for it.
Personally, I don't see why a movie player would implement platform-specific clipboard code, especially when it's so easy to write a "run shell" line.

@ghost
Copy link
Author

ghost commented Jul 25, 2017

you might be onto something. This works pefectly with ffmpeg...

   Run %COMSPEC% /c ffmpeg.exe -i test.mp4 2>&1 | find "Duration" | Clip, , hide && exit

so are you saying mpv can do something like this too ?
I have tried a few options, but can't get it to work.

@ghost
Copy link
Author

ghost commented Jul 25, 2017

thanks wiiaboo, but i could not get the lua code to work
this is my input file..

local function set_clipboard(text)
local res = utils.subprocess({ args = {
'powershell', '-NoProfile', '-Command', string.format([[& {
Trap {
Write-Error -ErrorRecord $_
Exit 1
}
Add-Type -AssemblyName PresentationCore
[System.Windows.Clipboard]::SetText('%s')
}]], text)
} })
end

mp.add_key_binding("5", "set_clipboard",
function () set_clipboard("hello world") end)

thanks medhefgo

i tried
p::
run "cmd.exe" "/d" "/c" "echo ${playback-time} / ${duration}|clip"
and
Run %COMSPEC% /c "cmd.exe" "/d" "/c" "echo ${playback-time} / ${duration}|clip"

neither seem to work
but
Run %COMSPEC% /c ffmpeg.exe -i test.mp4 2>&1 | find "Duration" | Clip, , hide && exit
works ok for ffmpeg

@garoto
Copy link
Contributor

garoto commented Jul 25, 2017

You're supposed to add the run line to your input.conf file located at %appdata\mpv\. Create one (input.conf) if it doesn't exist already.

It should read something like this after:

image

Lua scripts should go into a scripts dir at the same %appdata% location and have a .lua extension.

@ghost
Copy link
Author

ghost commented Jul 25, 2017

Thanks garoto, that totally worked now.

I really appreciate all your help guys.

@TunnelThruTime
Copy link

I've tried everything that's been written here with absolutely no success! it's a little ridiculous!!
I'm not a developer and am rather a user, but I feel it should be allot easier to write a single line of code for this kind of thing.
That is after all what everyone on the thread is saying.
Instead for the:
l run "/bin/sh" "-c" "echo ${playback-time} | pbcopy"
"subprocess failed: init"
I've also attempted:
echo 'show-text ${playback-time}' | socat - /tmp/mpvsocket

@ghost
Copy link

ghost commented May 12, 2020

Are you on OSX? The first method works for me with xclip on x11. The second method also works (of course that requires enabling IPC).

@Akemi
Copy link
Member

Akemi commented May 12, 2020

both methods also work for me on macOS.

@bharathyes
Copy link

You're supposed to add the run line to your input.conf file located at %appdata\mpv\. Create one (input.conf) if it doesn't exist already.

image

Copying to clipboard works fine on Windows10, mpv installed via chocolatey.

But I want the timestamp to be appended to a particular text file, so I can use it at a later point instead of having to switch apps and paste.

I tried this: t run "cmd.exe" "/d" "/c" "echo ${playback-time}>>D:\mpv\trim-video.txt"

Is there any obvious errors with this command? It worked for a couple of days. I used it more than a dozen times. But now it doesn't work and I can't figure out what changed.

@garoto
Copy link
Contributor

garoto commented Jun 12, 2021

On Windows, use single forward slashes (D:/mpv/...) or escaped backslashes (D:\\mpv\\...) as path separators in input.conf.

dexeonify referenced this issue in dexeonify/mpv-config Dec 24, 2021
This allows seek-to.lua to accept and paste timestamps from copyTime.lua
directly. The format accepted is HH:MM:SS.SSS and it can be invoked with
ctrl+v by default. The copy from clipboard code is for Windows only, but
it can be modified to accept clipboard on other OS too, see below.

Psst... occivink/mpv-scripts#43

Getting data from clipboard is harder than it looks, there isn't a
native and unified command to communicate with the clipboard for all OS.
Instead, you have to call a function/program specific to your OS through
a shell to get your clipboard data. Here is how mpv officially does it:
https://github.com/mpv-player/mpv/blob/master/player/lua/console.lua#L619-L672

Here is some issues related to it:
`https://github.com/mpv-player/mpv/issues/7361`
`https://github.com/mpv-player/mpv/issues/4695`
`https://github.com/mpv-player/mpv/issues/4653`
(backticks around it so I don't create a reference to all of them)
dexeonify added a commit to dexeonify/mpv-config that referenced this issue Dec 24, 2021
This allows seek-to.lua to accept and paste timestamps from copyTime.lua
directly. The format accepted is HH:MM:SS.SSS and it can be invoked with
ctrl+v by default. The copy from clipboard code is for Windows only, but
it can be modified to accept clipboard on other OS too, see below.

Psst... occivink/mpv-scripts#43

Getting data from clipboard is harder than it looks, there isn't a
native and unified command to communicate with the clipboard for all OS.
Instead, you have to call a function/program specific to your OS through
a shell to get your clipboard data. Here is how mpv officially does it:
https://github.com/mpv-player/mpv/blob/master/player/lua/console.lua#L619-L672

Here is some issues related to it:
mpv-player/mpv#7361
mpv-player/mpv#4695
mpv-player/mpv#4653
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants