jellyfin / jellyfin-mpv-shim

MPV Cast Client for Jellyfin
Other
1.5k stars 88 forks source link

Ext mpv, scripts set in ext mpv.conf are overridden by command line scripts #320

Closed Ashyni closed 1 year ago

Ashyni commented 1 year ago

Describe the bug With external mpv, scripts set in external mpv.conf are overridden by command line scripts mouse.lua/trickplay.lua. It is seen in mpv logs provided.

To Reproduce

  1. add any script=C:\Users\Jeffrey\repos\mpv-scripts-dev\dynamic-crop.lua to %appdata%/Roaming/mpv/mpv.conf

Expected behavior Append additional scripts, don't override previous one.

Alternative Set custom scripts in C:\Users\Jeffrey\AppData\Roaming\jellyfin-mpv-shim\mpv.conf, like it's included after mouse.lua and trickplay.lua.

Desktop:

Error Messages

[   0.000][v][cplayer] Command line options: '--player-operation-mode=pseudo-gui' '--input-default-bindings=yes' '--input-vo-keyboard=yes' '--input-media-keys=yes'
'--player-operation-mode=cplayer' '--osc=no' '--scripts=C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\mouse.lua;C:\Program Files (x86)\Jellyfin MPV
Shim\jellyfin_mpv_shim\trickplay.lua' '--include=C:\Users\Jeffrey\AppData\Roaming\jellyfin-mpv-shim\mpv.conf'
'--input-conf=C:\Users\Jeffrey\AppData\Roaming\jellyfin-mpv-shim\input.conf' '--idle=yes' '--input-ipc-server=mpv274245904092166' '--input-terminal=no' '--terminal=no'
[   0.000][v][cplayer] mpv 0.35.0-252-g68df517e Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
[   0.000][v][cplayer]  built on Thu Feb 23 11:48:01 2023
[   0.000][v][cplayer] libplacebo version: v5.229.1-270-g6f8510f
[   0.000][v][cplayer] FFmpeg version: N-109903-g89fe2ffe1
[   0.000][v][cplayer] FFmpeg library versions:
[   0.000][v][cplayer]    libavutil       58.3.100
[   0.000][v][cplayer]    libavcodec      60.4.100
[   0.000][v][cplayer]    libavformat     60.4.100
[   0.000][v][cplayer]    libswscale      7.2.100
[   0.000][v][cplayer]    libavfilter     9.4.100
[   0.000][v][cplayer]    libswresample   4.11.100
[   0.000][v][cplayer]
[   0.000][v][cplayer] Configuration: meson configure build -Dprefix=/home/ashyni/mpv-winbuild-cmake/build64-v3/install/mingw -Dbuildtype=release -Doptimization=3
[   0.000][v][cplayer] List of enabled features: av-channel-layout build-date cuda-hwaccel cuda-interop d3d-hwaccel d3d11 d3d9-hwaccel direct3d dos-paths dvdnav egl-angle
egl-angle-win32 egl-helpers ffmpeg ffnvcodec gl gl-dxinterop gl-dxinterop-d3d9 gl-win32 glob glob-win32 gpl iconv javascript jpeg jpegxl lcms2 libarchive libass libavdevice libbluray
libm libplacebo libplacebo-next luajit manpage-build noexecstack openal pdf-build rubberband rubberband-3 sdl2 sdl2-audio sdl2-gamepad sdl2-video shaderc spirv-cross stdatomic threads
uchardet vapoursynth vector vk_khr_display vulkan wasapi win32 win32-desktop win32-executable win32-internal-pthreads zimg zlib
[   0.000][v][cplayer] Built with NDEBUG.
[   0.000][v][cplayer] Reading config file C:\Users\Jeffrey\AppData\Roaming\mpv/mpv.conf
[   0.000][v][cplayer] Applying profile 'default'...
[   0.000][v][cplayer] Setting option 'profile' = 'gpu-hq' (flags = 4)
[   0.000][v][cplayer] Applying profile 'gpu-hq'...
[   0.000][v][cplayer] Setting option 'scale' = 'spline36' (flags = 4)
[   0.000][v][cplayer] Setting option 'cscale' = 'spline36' (flags = 4)
[   0.000][v][cplayer] Setting option 'dscale' = 'mitchell' (flags = 4)
[   0.000][v][cplayer] Setting option 'dither-depth' = 'auto' (flags = 4)
[   0.000][v][cplayer] Setting option 'correct-downscaling' = 'yes' (flags = 4)
[   0.000][v][cplayer] Setting option 'linear-downscaling' = 'yes' (flags = 4)
[   0.000][v][cplayer] Setting option 'sigmoid-upscaling' = 'yes' (flags = 4)
[   0.000][v][cplayer] Setting option 'deband' = 'yes' (flags = 4)
[   0.000][v][cplayer] Setting option 'vo' = 'gpu-next' (flags = 4)
[   0.000][v][cplayer] Setting option 'gpu-api' = 'vulkan' (flags = 4)
[   0.000][v][cplayer] Setting option 'fbo-format' = 'rgba16hf' (flags = 4)
[   0.000][v][cplayer] Setting option 'hwdec' = 'auto-copy' (flags = 4)
[   0.000][v][cplayer] Setting option 'log-file' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\mpv.log' (flags = 4)
[   0.000][v][cplayer] Setting option 'scripts-append' = 'C:\Users\Jeffrey\repos\mpv-scripts-dev\dynamic-crop.lua' (flags = 4)
[   0.000][v][cplayer] Setting option 'script-opts-append' = 'dynamic_crop-fix_windowed_behavior=2' (flags = 4)
[   0.000][v][cplayer] Setting option 'scripts-append' = 'C:\Users\Jeffrey\repos\mpv-scripts\audio-bluetooth.lua' (flags = 4)
[   0.000][v][cplayer] Setting option 'linear-downscaling' = 'no' (flags = 4)
[   0.000][v][cplayer] Setting option 'dscale' = 'mitchell' (flags = 4)
[   0.000][v][cplayer] Setting option 'glsl-shaders-append' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\shaders\FSRCNNX_x2_16-0-4-1.glsl' (flags = 4)
[   0.000][v][cplayer] Setting option 'glsl-shaders-append' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\shaders\KrigBilateral.glsl' (flags = 4)
[   0.000][v][cplayer] Setting option 'glsl-shaders-append' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\shaders\SSimSuperRes.glsl' (flags = 4)
[   0.000][v][cplayer] Setting option 'glsl-shaders-append' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\shaders\SSimDownscaler.glsl' (flags = 4)
[   0.000][v][cplayer] Setting option 'ytdl-format' = 'bestvideo[height<=?1440]+bestaudio/best' (flags = 4)
[   0.000][v][cplayer] Setting option 'player-operation-mode' = 'pseudo-gui' (flags = 8)
[   0.000][v][cplayer] Setting option 'input-default-bindings' = 'yes' (flags = 8)
[   0.000][v][cplayer] Setting option 'input-vo-keyboard' = 'yes' (flags = 8)
[   0.000][v][cplayer] Setting option 'input-media-keys' = 'yes' (flags = 8)
[   0.000][v][cplayer] Setting option 'player-operation-mode' = 'cplayer' (flags = 8)
[   0.000][v][cplayer] Setting option 'osc' = 'no' (flags = 8)
[   0.000][v][cplayer] Setting option 'scripts' = 'C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\mouse.lua;C:\Program Files (x86)\Jellyfin MPV
Shim\jellyfin_mpv_shim\trickplay.lua' (flags = 8)
[   0.000][v][cplayer] Setting option 'include' = 'C:\Users\Jeffrey\AppData\Roaming\jellyfin-mpv-shim\mpv.conf' (flags = 8)
[   0.000][v][cplayer] Reading config file C:\Users\Jeffrey\AppData\Roaming\jellyfin-mpv-shim\mpv.conf
[   0.000][v][cplayer] Applying profile 'default'...
[   0.000][v][cplayer] Setting option 'input-conf' = 'C:\Users\Jeffrey\AppData\Roaming\jellyfin-mpv-shim\input.conf' (flags = 8)
[   0.000][v][cplayer] Setting option 'idle' = 'yes' (flags = 8)
[   0.000][v][cplayer] Setting option 'input-ipc-server' = 'mpv274245904092166' (flags = 8)
[   0.000][v][cplayer] Setting option 'input-terminal' = 'no' (flags = 8)
[   0.000][v][cplayer] Setting option 'terminal' = 'no' (flags = 8)
[   0.008][v][cplayer] mpv 0.35.0-252-g68df517e Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
iwalton3 commented 1 year ago

Last I checked I thought it still used lua scripts in the config too. If not I may need to map a script directory.

iwalton3 commented 1 year ago

I have confirmed scripts are still working with libmpv playback backend but are broken with external mpv.

iwalton3 commented 1 year ago

I added a scripts folder in the config folder where you can place scripts so that they get auto-loaded. I also made it so that mpv_ext_no_ovr suppresses script overriding and instead prints the locations of the stock scripts.

You can download a build from GitHub Actions to test this.

Ashyni commented 1 year ago

Using --script= instead of --scripts= append script instead of overriding every other scripts, so loading them one by one is a better solution.

[   0.000][v][cplayer] Command line options: '--script=C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\mouse.lua' '--script=C:\Program Files (x86)\Jellyfin MPV
Shim\jellyfin_mpv_shim\trickplay.lua' 'D:\Interstellar (2014) - [FR+EN][BLURAY-1080P][DTS 5.1][X264].mkv'
[   0.000][v][cplayer] mpv 0.35.0-252-g68df517e Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
[   0.000][v][cplayer]  built on Thu Feb 23 11:48:01 2023
[   0.000][v][cplayer] libplacebo version: v5.229.1-270-g6f8510f
[   0.000][v][cplayer] FFmpeg version: N-109903-g89fe2ffe1
[   0.000][v][cplayer] FFmpeg library versions:
[   0.000][v][cplayer]    libavutil       58.3.100
[   0.000][v][cplayer]    libavcodec      60.4.100
[   0.000][v][cplayer]    libavformat     60.4.100
[   0.000][v][cplayer]    libswscale      7.2.100
[   0.000][v][cplayer]    libavfilter     9.4.100
[   0.000][v][cplayer]    libswresample   4.11.100
[   0.000][v][cplayer]
[   0.000][v][cplayer] Configuration: meson configure build -Dprefix=/home/ashyni/mpv-winbuild-cmake/build64-v3/install/mingw -Dbuildtype=release -Doptimization=3
[   0.000][v][cplayer] List of enabled features: av-channel-layout build-date cuda-hwaccel cuda-interop d3d-hwaccel d3d11 d3d9-hwaccel direct3d dos-paths dvdnav egl-angle
egl-angle-win32 egl-helpers ffmpeg ffnvcodec gl gl-dxinterop gl-dxinterop-d3d9 gl-win32 glob glob-win32 gpl iconv javascript jpeg jpegxl lcms2 libarchive libass libavdevice libbluray
libm libplacebo libplacebo-next luajit manpage-build noexecstack openal pdf-build rubberband rubberband-3 sdl2 sdl2-audio sdl2-gamepad sdl2-video shaderc spirv-cross stdatomic threads
uchardet vapoursynth vector vk_khr_display vulkan wasapi win32 win32-desktop win32-executable win32-internal-pthreads zimg zlib
[   0.000][v][cplayer] Built with NDEBUG.
[   0.000][v][cplayer] Reading config file C:\Users\Jeffrey\AppData\Roaming\mpv/mpv.conf
[   0.000][v][cplayer] Applying profile 'default'...
[   0.000][v][cplayer] Setting option 'profile' = 'gpu-hq' (flags = 4)
[   0.000][v][cplayer] Applying profile 'gpu-hq'...
[   0.000][v][cplayer] Setting option 'scale' = 'spline36' (flags = 4)
[   0.000][v][cplayer] Setting option 'cscale' = 'spline36' (flags = 4)
[   0.000][v][cplayer] Setting option 'dscale' = 'mitchell' (flags = 4)
[   0.000][v][cplayer] Setting option 'dither-depth' = 'auto' (flags = 4)
[   0.000][v][cplayer] Setting option 'correct-downscaling' = 'yes' (flags = 4)
[   0.000][v][cplayer] Setting option 'linear-downscaling' = 'yes' (flags = 4)
[   0.000][v][cplayer] Setting option 'sigmoid-upscaling' = 'yes' (flags = 4)
[   0.000][v][cplayer] Setting option 'deband' = 'yes' (flags = 4)
[   0.000][v][cplayer] Setting option 'vo' = 'gpu-next' (flags = 4)
[   0.000][v][cplayer] Setting option 'gpu-api' = 'vulkan' (flags = 4)
[   0.000][v][cplayer] Setting option 'fbo-format' = 'rgba16hf' (flags = 4)
[   0.000][v][cplayer] Setting option 'hwdec' = 'auto-copy' (flags = 4)
[   0.000][v][cplayer] Setting option 'log-file' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\mpv.log' (flags = 4)
[   0.000][v][cplayer] Setting option 'scripts-append' = 'C:\Users\Jeffrey\repos\mpv-scripts-dev\dynamic-crop.lua' (flags = 4)
[   0.000][v][cplayer] Setting option 'script-opts-append' = 'dynamic_crop-fix_windowed_behavior=2' (flags = 4)
[   0.000][v][cplayer] Setting option 'scripts-append' = 'C:\Users\Jeffrey\repos\mpv-scripts\audio-bluetooth.lua' (flags = 4)
[   0.000][v][cplayer] Setting option 'linear-downscaling' = 'no' (flags = 4)
[   0.000][v][cplayer] Setting option 'dscale' = 'mitchell' (flags = 4)
[   0.000][v][cplayer] Setting option 'glsl-shaders-append' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\shaders\FSRCNNX_x2_16-0-4-1.glsl' (flags = 4)
[   0.000][v][cplayer] Setting option 'glsl-shaders-append' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\shaders\KrigBilateral.glsl' (flags = 4)
[   0.000][v][cplayer] Setting option 'glsl-shaders-append' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\shaders\SSimSuperRes.glsl' (flags = 4)
[   0.000][v][cplayer] Setting option 'glsl-shaders-append' = 'C:\Users\Jeffrey\AppData\Roaming\mpv\shaders\SSimDownscaler.glsl' (flags = 4)
[   0.000][v][cplayer] Setting option 'ytdl-format' = 'bestvideo[height<=?1440]+bestaudio/best' (flags = 4)
[   0.000][v][cplayer] Setting option 'scripts-append' = 'C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\mouse.lua' (flags = 8)
[   0.000][v][cplayer] Setting option 'scripts-append' = 'C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\trickplay.lua' (flags = 8)

Using external mpv allow me to have only one mpv to update, config and customize with scripts. Also, mpv_ext_no_ovr don't load the osc.

iwalton3 commented 1 year ago

--script causes issues due to how MPV is invoked via python. If you use mpv_ext_no_ovr you need to add script entries to your config for 'C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\trickplay.lua' or disable trickplay to get a working OSC.

Ashyni commented 1 year ago

--script causes issues due to how MPV is invoked via python.

What issues exactly ? I'm not going to annoy you more after this, i just try to learn and understand. Thanks for your works on Jellyfin.

At least for external mpv, with the following changes, It's working properly, without or with one or multiple scripts. https://github.com/jellyfin/jellyfin-mpv-shim/blob/2c449961657e5b009c60c346122586f2ae4cbb58/jellyfin_mpv_shim/player.py#L195-L198 change to:

 if scripts:
     if settings.mpv_ext and not settings.mpv_ext_no_ovr:
         mpv_options["scripts"] = scripts
     else:
         mpv_options["scripts"] = (
             ";" if sys.platform.startswith("win32") else ":"
         ).join(scripts)

and python_mpv_jsonipc.py change to:

 scripts = kwargs.pop("scripts", None)
 args.extend("--{0}={1}".format(v[0].replace("_", "-"), self._mpv_fmt(v[1]))
             for v in kwargs.items())
 if scripts is not None:
     args.extend("--script={0}".format(self._mpv_fmt(v))
                 for v in scripts)

Log

[   0.000][v][cplayer] Command line options: '--player-operation-mode=pseudo-gui' '--input-default-bindings=yes' '--input-vo-keyboard=yes' '--input-media-keys=yes'
'--player-operation-mode=cplayer' '--osc=no' '--include=C:\Users\Jeffrey\AppData\Roaming\jellyfin-mpv-shim\mpv.conf'
'--input-conf=C:\Users\Jeffrey\AppData\Roaming\jellyfin-mpv-shim\input.conf' '--idle=yes' '--input-ipc-server=mpv107767983125196' '--input-terminal=no' '--terminal=no'
'--script=C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\mouse.lua' '--script=C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\trickplay.lua'
...
[   0.000][v][cplayer] Setting option 'scripts-append' = 'C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\mouse.lua' (flags = 8)
[   0.000][v][cplayer] Setting option 'scripts-append' = 'C:\Program Files (x86)\Jellyfin MPV Shim\jellyfin_mpv_shim\trickplay.lua' (flags = 8)
iwalton3 commented 1 year ago

I'd have to look at how it works with the internal MPV library. But that being said if using --script is enough to get it to work with both I may just upgrade the jsonipc library since I control it. They already behave differently enough that the compatibility break may be worth it.

iwalton3 commented 1 year ago

That's probably a better solution anyways since then I don't need that annoying behavior where no override kills the built in OSC.

iwalton3 commented 1 year ago

I fixed it so that my scripts don't have any effect on user configured scripts. I did it using a similar method to what you explained, but I made it more general so that users of python_mpv_jsonipc are able to repeat any argument by passing a list of different values.

For libmpv it seems as long as the user config is configured after the scripts in the arguments, both take effect. This was the case so no additional changes are needed.

I made it so that mpv_ext_no_ovr now loads my provided scripts again since it doesn't override user scripts.