You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a command to set multiple ab-loop of the same file #7975
Perhaps you could get this sort of effect using edit decision lists (EDLs, documented here: https://github.com/mpv-player/mpv/blob/master/DOCS/edl-mpv.rst). For instance you could create one EDL file for each segment you want to loop and put them into a shuffled mpv playlist. e.g. mpv --shuffle loop1.edl loop2.edl ...
EDL files themselves are fairly straight forward, for your purposes an EDL file of a loop starting at the 150 second second mark including the next 5 seconds might look like:
# mpv EDL v0
/path/to/your/video.mp4,150,5
These files may also contain many entries/lines, including duplicate entries, which you can reorder as you like. Each segment will be played back to back in the order they appear in the EDL file, or you could create multiple EDL files and manage their order as you would any other mpv playlist.
(Note that if your video's filename contains a , character any EDL file for it will get a little bit more complicated. Writing these EDL files by hand is very far from ideal. It might be a good candidate for an mpv userscript though.)
A character class is used to represent a set of characters. The following combinations are allowed in describing a character class:
- x: (where x is not one of the magic characters ^$()%.[]*+-?) represents the character x itself.
So forward slash is not in the list of special characters. AI says I need to escape forward slash? Or is AI doing me dirty again?
Nice, thanks. It's definitely shorter. But is it also faster? 😄
Again, not familiar with Lua syntax (basically the first thing in Lua I've ever written), but is path:find(<pattern>) some special method? Or is it the same as string.find(path, <pattern>), basically? Just syntactic sugar?
If you're trying to convert it to an absolute path you can use utils.join_path which returns paths as they are when already absolute.
I've found that one in the manual actually, and it is what I've tried first.
But I had one problem, where it did not work in a specific case. Might be a Windows specific issue again, not sure.
Consider this:
Directory
D:\Example\Test
File
RandomClip-0001.mp4
If I run mpv like this:
mpv D:\Example\Test\RandomClip-0001.mp4
utils.join_path (with the second parameter, just as described in the manual) returns the correct path, exactly as used on the command-line.
Regardless of working directory in the terminal.
With the terminal in the directory mentioned above
mpv RandomClip-0001.mp4
gets me D:\Example\Test/Random-Clip-0001.mp4. So it joins with the "wrong" path separator, but it's not really a big deal, the path still works.
But on the other hand, again, same current location in terminal:
mpv .\RandomClip-0001.mp4
returns D:\Example\Test./Random-Clip-0001.mp4, which is a bit, well, dubious...
Nice, thanks. It's definitely shorter. But is it also faster? 😄
Yes but there's nothing slow in either one.
Again, not familiar with Lua syntax (basically the first thing in Lua I've ever written), but is path:find(<pattern>) some special method? Or is it the same as string.find(path, <pattern>), basically? Just syntactic sugar?
Yes, path:find(pattern) is short for path.find(path, pattern).
Yes, paths are a mess on Windows because mpv mixes both kinds of slashes, using different paths also breaks the watch later feature. If #12303 is merged and someone is willing to adapt it in on Windows, we can implement a normalize-path command to handle this for script writers.
@guidocella Such a normalize-path function seems very useful, I agree.
Would this also address the issue which I just stumbled upon, namely, given the same directory structure from my comment above (i.e. terminal in D:\Example\Test), but I now play a file named unnamedvid.mp4 in the parent directory (so D:\Example), which works just fine with mpv (as well as with any other cli program). IOW, the command would be
mpv ..\unnamedvid.mp4
with local x, y = utils.split_path(mp.get_property('path')) I get this
Variable
Value
x
..\
y
unnamedvid.mp4
Which is perfectly fine and as expected. But the way I try to convert to absolute paths, I'll end up with this path here:
D:\Example\Test\unnamedvid.mp4
Which is just wrong, unnamedvid.mp is in Example, not in Test.
But it's not because I do anything funny, this gives the same result:
I checked the relevant parts of the manual again, and this is even expected behavior, as I understand it.
Because both
utils.getcwd()
mp.get_property('working-directory')
Return the working directory of the mpv process, or the directory from which mpv was launched from.
Seems like the documentation is correct, but this leads me to the following questions:
What's the point of having both of these functions, if they return the same thing? What is the difference?
How can I get the working-directory of the currently active file?
I also tried the playlist-path property, but I just get an lua error. Basically the wrong type, but I assume this just means that this property does not return anything useful. Maybe because if one opens a single file, it will maybe have an internal "playlist", but it is not a "real" playlist?
I assume playlist/N/playlist-path won't make a difference here?
Would this also address the issue which I just stumbled upon...
Yes.
What's the point of having both of these functions, if they return the same thing? What is the difference?
utils.getcwd() is older, then working-directory was added to access it from JSON IPC. There is no reason to keep using utils.getcwd() which just calls mp.get_property("working-directory").
How can I get the working-directory of the currently active file?
On Unix you call realpath with subprocess. I don't know if on Windows you can call GetFullPathNameW with Luajit's FFI.
I also tried the playlist-path property, but I just get an lua error. Basically the wrong type, but I assume this just means that this property does not return anything useful. Maybe because if one opens a single file, it will maybe have an internal "playlist", but it is not a "real" playlist? I assume playlist/N/playlist-path won't make a difference here?
That's the path of directories expanded at runtime, archives and m3u playlists.
Activity
SmootheSmooth commentedon Aug 6, 2020
I tried again and found nothing.
It's not supported. Currently I use this mpv version on Windows.
https://sourceforge.net/projects/mpv-player-windows/files/64bit/mpv-x86_64-20200802-git-b238897.7z/download
Therefore make this report a feature request.
SmootheSmooth commentedon Aug 6, 2020
Expected behavior of the wanted feature
The expected behaviour could be to add new commands, like
ab-loop-a-number=2andab-loop-b-number=2When use these commands, you can add up to 2x
ab-loop-aand 2xab-loop-bfor the same video file.[-]How can I add a second ab-loop for the same file?[/-][+]Add a command to set multiple ab-loop of the same file[/+]jgreco commentedon Sep 17, 2020
Perhaps you could get this sort of effect using edit decision lists (EDLs, documented here: https://github.com/mpv-player/mpv/blob/master/DOCS/edl-mpv.rst). For instance you could create one EDL file for each segment you want to loop and put them into a shuffled mpv playlist. e.g.
mpv --shuffle loop1.edl loop2.edl ...EDL files themselves are fairly straight forward, for your purposes an EDL file of a loop starting at the 150 second second mark including the next 5 seconds might look like:
These files may also contain many entries/lines, including duplicate entries, which you can reorder as you like. Each segment will be played back to back in the order they appear in the EDL file, or you could create multiple EDL files and manage their order as you would any other mpv playlist.
(Note that if your video's filename contains a
,character any EDL file for it will get a little bit more complicated. Writing these EDL files by hand is very far from ideal. It might be a good candidate for an mpv userscript though.)Akemi commentedon Apr 30, 2021
yeah i think this is a case where EDL should be used. alternatively/additionally a script that writes such a file on the fly.
guidocella commentedon Dec 16, 2023
I generate them with this script. It is bound to
g-ePublished to https://gist.github.com/guidocella/5f05794d0a8400b2393fe7a9995ebb43
hrxn commentedon Dec 16, 2023
What would this script look like if I wanted to use a binding in
input.confwithscript-binding?guidocella commentedon Dec 16, 2023
I updated the script giving the binding a name. You can bind
script-binding generate-edl, or just edit the key in the script.hrxn commentedon Dec 16, 2023
Thanks!
But this still binds a key from the script, no?
What would I have to do? Use
ignoreas the param formp.add_key_binding()?Or, another example, what if I change this script to this?
guidocella commentedon Dec 16, 2023
or
An existing function is passed with
hrxn commentedon Dec 16, 2023
k, thanks!
9 remaining items
guidocella commentedon Jan 3, 2024
mp.get_property('platform')hrxn commentedon Jan 3, 2024
Ah, thanks, just found it.
Strange, Lua docs says
So forward slash is not in the list of special characters. AI says I need to escape forward slash? Or is AI doing me dirty again?
guidocella commentedon Jan 3, 2024
You don't have to escape forward slashes in Lua patterns. It's getting confused with regular expressions using
/as delimiters.hrxn commentedon Jan 3, 2024
Okay, it was actually also working with
utils.getcwd(), but it's more clear and sane this way:I hope it's not too bad 😄
guidocella commentedon Jan 3, 2024
If you're trying to convert it to an absolute path you can use
utils.join_pathwhich returns paths as they are when already absolute.Edit: even shorter:
hrxn commentedon Jan 3, 2024
Nice, thanks. It's definitely shorter. But is it also faster? 😄
Again, not familiar with Lua syntax (basically the first thing in Lua I've ever written), but is
path:find(<pattern>)some special method? Or is it the same asstring.find(path, <pattern>), basically? Just syntactic sugar?I've found that one in the manual actually, and it is what I've tried first.
But I had one problem, where it did not work in a specific case. Might be a Windows specific issue again, not sure.
Consider this:
D:\Example\TestRandomClip-0001.mp4If I run mpv like this:
utils.join_path(with the second parameter, just as described in the manual) returns the correct path, exactly as used on the command-line.Regardless of working directory in the terminal.
With the terminal in the directory mentioned above
gets me
D:\Example\Test/Random-Clip-0001.mp4. So it joins with the "wrong" path separator, but it's not really a big deal, the path still works.But on the other hand, again, same current location in terminal:
returns
D:\Example\Test./Random-Clip-0001.mp4, which is a bit, well, dubious...guidocella commentedon Jan 3, 2024
Yes but there's nothing slow in either one.
Yes,
path:find(pattern)is short forpath.find(path, pattern).Yes, paths are a mess on Windows because mpv mixes both kinds of slashes, using different paths also breaks the watch later feature. If #12303 is merged and someone is willing to adapt it in on Windows, we can implement a
normalize-pathcommand to handle this for script writers.hrxn commentedon Jan 3, 2024
@guidocella Such a
normalize-pathfunction seems very useful, I agree.Would this also address the issue which I just stumbled upon, namely, given the same directory structure from my comment above (i.e. terminal in
D:\Example\Test), but I now play a file namedunnamedvid.mp4in the parent directory (soD:\Example), which works just fine with mpv (as well as with any other cli program). IOW, the command would bewith
local x, y = utils.split_path(mp.get_property('path'))I get this..\unnamedvid.mp4Which is perfectly fine and as expected. But the way I try to convert to absolute paths, I'll end up with this path here:
Which is just wrong,
unnamedvid.mpis inExample, not inTest.But it's not because I do anything funny, this gives the same result:
(Reusing
yfromutils.split_path()above)I checked the relevant parts of the manual again, and this is even expected behavior, as I understand it.
Because both
utils.getcwd()mp.get_property('working-directory')Return the working directory of the mpv process, or the directory from which mpv was launched from.
Seems like the documentation is correct, but this leads me to the following questions:
working-directoryof the currently active file?I also tried the
playlist-pathproperty, but I just get an lua error. Basically the wrong type, but I assume this just means that this property does not return anything useful. Maybe because if one opens a single file, it will maybe have an internal "playlist", but it is not a "real" playlist?I assume
playlist/N/playlist-pathwon't make a difference here?guidocella commentedon Jan 3, 2024
Yes.
utils.getcwd()is older, thenworking-directorywas added to access it from JSON IPC. There is no reason to keep usingutils.getcwd()which just callsmp.get_property("working-directory").On Unix you call
realpathwithsubprocess. I don't know if on Windows you can callGetFullPathNameWwith Luajit's FFI.That's the path of directories expanded at runtime, archives and m3u playlists.
DOCS/lua: deprecate utils.getcwd() and getpid()
DOCS/lua: deprecate utils.getcwd() and utils.getpid()
DOCS/lua: deprecate utils.getcwd() and utils.getpid()
DOCS/lua: note that properties are preferred to getcwd and getpid
DOCS/lua: note that properties are preferred to getcwd and getpid
DOCS/lua: explain that getcwd and getpid just fetch properties