From 0fdfec4385d46b0db0baaec3d369d33eb71bb8ca Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Thu, 25 Feb 2021 12:07:20 +0100 Subject: [PATCH] mpv: Add motion vector interpolation script --- users/simon/modules/default.nix | 2 +- .../modules/{mpv.nix => mpv/default.nix} | 21 ++++++++++++++----- users/simon/modules/mpv/mvinterpolate.py | 20 ++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) rename users/simon/modules/{mpv.nix => mpv/default.nix} (95%) create mode 100644 users/simon/modules/mpv/mvinterpolate.py diff --git a/users/simon/modules/default.nix b/users/simon/modules/default.nix index bcb9934..0a46975 100644 --- a/users/simon/modules/default.nix +++ b/users/simon/modules/default.nix @@ -9,7 +9,7 @@ ./htop.nix ./misc.nix ./mpd.nix - ./mpv.nix + ./mpv ./neovim.nix ./pass.nix ./programs.nix diff --git a/users/simon/modules/mpv.nix b/users/simon/modules/mpv/default.nix similarity index 95% rename from users/simon/modules/mpv.nix rename to users/simon/modules/mpv/default.nix index 1f36629..47a185d 100644 --- a/users/simon/modules/mpv.nix +++ b/users/simon/modules/mpv/default.nix @@ -48,6 +48,20 @@ in # mpv can also be useful without a display (e.g. for encoding) enable = nixosConfig.sbruder.gui.enable || nixosConfig.sbruder.full; + package = pkgs.wrapMpv + (pkgs.mpv-unwrapped.override { + vapoursynthSupport = true; + vapoursynth = pkgs.vapoursynth.withPlugins (with pkgs; [ + vapoursynth-mvtools + ]); + }) + { + scripts = with pkgs.mpvScripts; [ + pitchcontrol + sponsorblock + ]; + }; + defaultProfiles = [ "gpu-hq" # High quality by default ]; @@ -208,14 +222,11 @@ in tscale-clamp = 0.0; }; + mvinterpolate.vf-add = "vapoursynth=${./mvinterpolate.py}"; + # adapted from https://github.com/mpv-player/mpv/issues/4418#issuecomment-368272929 clear-speed.af-add = "scaletempo=stride=18:overlap=.6:search=10"; }; - - scripts = with pkgs.mpvScripts; [ - pitchcontrol - sponsorblock - ]; }; # mpv-gallery-view is not compatible with home-manager’s script injection meachanism diff --git a/users/simon/modules/mpv/mvinterpolate.py b/users/simon/modules/mpv/mvinterpolate.py new file mode 100644 index 0000000..520b33f --- /dev/null +++ b/users/simon/modules/mpv/mvinterpolate.py @@ -0,0 +1,20 @@ +import vapoursynth as vs + +core = vs.core + +clip = core.std.AssumeFPS(video_in, fpsnum=int(container_fps * 1000), fpsden=1000) + +sup = core.mv.Super(clip, pel=2) +bvec = core.mv.Analyse(sup, isb=True) +fvec = core.mv.Analyse(sup, isb=False) +hfr = core.mv.BlockFPS( + clip, + sup, + bvec, + fvec, + num=int(display_fps * 1000), + den=1000, + thscd1=140, + thscd2=38, +) +hfr.set_output()