zc62/mpv-scripts

autoloop breaking animation of gifs

jgreco opened this issue · 3 comments

Are these lines really necessary? :

mpv-scripts/autoloop.lua

Lines 25 to 29 in 0dc5125

else
mp.set_property_native("loop-file", was_loop)
end
else
mp.set_property_native("loop-file", was_loop)

They seem like they should be redundent/no-ops, except they also prevent some gifs from looping in my configuration:

[extension.gif]
interpolation=no
loop-file=inf

Removing those mp.set_property_native("loop-file", was_loop) lines from my copy of autoloop.lua doesn't seem to have negatively impacted anything.

Here is one gif that doesn't loop with those lines present:
helicopter

zc62 commented

Thanks for reporting this. I didn't consider the usage of auto profiles, so that is why it had the bug. The latest version should work now.

I had those lines because I need to take playlists into account. Removing those lines is just setting loop-file=yes forever when mpv once encounters a video file that has duration < 5s. Actually, for GIFs, they have duration=nil in the lua script.

You can read the comments and the commit message to see how I fixed it. In addtion, I think you may want to have something like

[extension.mp4]
interpolation=yes
loop-file=no
[extension.mkv]
profile=extension.mp4

to undo your gjf auto profile, in case you need to mix a playlist with video files and gif files.

zc62 commented

After a small debug commit 85d9208, I realized fully resolving this problem is trickier than I expected. The bug persists, if I play a playlist contains: one short mp4 video, then gif.

Because, indeed, the set_loop function sets to inf loop when mpv is playing the mp4 video, but when it comes to resetting the property, extension.gif is also modifying the "loop-file" property to true. Auto profiles are modifying it, while my function has no way to know if the true value the function is seeing is from previous set_loop modification, or from the modification of auto profiles.

I have no idea about how to solve this for now, because mpv does not provide events like profile-loaded. Anyway, the script should work for other cases except the corner case I've mentioned (if there are no more corner cases that I haven't realized).

zc62 commented

I have come up with another trick to make it work, unless you really want to watch the video/gif for more than 5,000 times. So now it is not really an infinite loop, then I can distinguish with loop-file=yes set by auto profiles.