home: Add mpv

This commit is contained in:
Simon Bruder 2020-11-07 17:49:02 +01:00
parent dea242488f
commit ff74abc107
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F
2 changed files with 205 additions and 0 deletions

View file

@ -37,6 +37,7 @@ in
./modules/htop.nix
./modules/misc.nix
./modules/mpd.nix
./modules/mpv.nix
./modules/neovim.nix
./modules/sway.nix
./modules/tmux.nix

204
users/simon/modules/mpv.nix Normal file
View file

@ -0,0 +1,204 @@
{ config, pkgs, ... }:
let
stdenv = pkgs.stdenv;
mpv-prescalers = builtins.fetchGit {
url = "https://github.com/bjin/mpv-prescalers";
ref = "master";
rev = "b37d0f12223720f5ce48e149678162ae0a984176";
};
pitchcontrol = (stdenv.mkDerivation rec {
name = "pitchcontrol.lua";
scriptName = name;
src = builtins.fetchGit {
url = "https://github.com/FichteFoll/mpv-scripts";
ref = "master";
rev = "28ce548e82460b1ca40d3d0149faffff97c874a0";
};
installPhase = ''
mkdir -p $out/share/mpv/scripts/
cp pitchcontrol.lua $out/share/mpv/scripts
'';
});
gallery-view = builtins.fetchGit {
url = "https://github.com/occivink/mpv-gallery-view";
ref = "master";
rev = "5139d346de67e8dbee8c8983777026502d6bc627";
};
cycleShaders = shaders: "cycle-values glsl-shaders ${builtins.concatStringsSep " " shaders}";
in
{
programs.mpv = {
enable = true;
config = {
# Main application font
osd-font = "DINW07-Medium"; # not included in repository (unfree)
# Subtitles
sub-font = "Gandhi Sans"; # see osd-font
sub-bold = true;
sub-font-size = 44;
sub-use-margins = false;
sub-border-size = 2;
# Nicer looking vobsub/PGS subtitles
sub-gauss = 0.5;
sub-gray = true;
# Allow higher volumes
volume-max = 150;
# Downmix to stereo by default
audio-channels = "stereo";
# Allow seeking in streamed media
force-seekable = true;
# Enable hardware decoding when avaliable
hwdec = "auto-safe";
# Do not show images only one second
image-display-duration = "inf";
# Better quality (but not too high, otherwise too high frame drop)
profile = "gpu-hq";
deband = false;
dither-depth = "auto";
# Lossless screenshots
screenshot-format = "png";
};
bindings = {
# Audio filter bs2b (for headphones)
"b" = "af toggle bs2b";
# Toggle debanding
"D" = "cycle deband";
# Variable correction of audio pitch when changing speed
"k" = "cycle-values audio-pitch-correction no yes";
# Reverse cycling for audio and video (shift modifier on german keyboard layout)
"'" = "cycle audio down";
"-" = "cycle video down";
# Cycle between audio downmixes
"c" = "cycle-values audio-channels stereo mono auto";
# Cycle between smart scalers (and /dev/null = disabled)
"K" = cycleShaders [
"${mpv-prescalers}/compute/ravu-lite-r4.hook"
"${mpv-prescalers}/compute/ravu-lite-r3.hook"
"${mpv-prescalers}/compute/ravu-lite-r2.hook"
"/dev/null"
];
"Alt+K" = cycleShaders [
"${mpv-prescalers}/compute/ravu-zoom-r4-yuv.hook"
"${mpv-prescalers}/compute/ravu-zoom-r3-yuv.hook"
"${mpv-prescalers}/compute/ravu-zoom-r2-yuv.hook"
"/dev/null"
];
"Alt+k" = cycleShaders [
"${mpv-prescalers}/compute/nnedi3-nns256-win8x4.hook"
"${mpv-prescalers}/compute/nnedi3-nns128-win8x4.hook"
"/dev/null"
];
# Toggle pitchcontrol
"Ctrl+p" = "script-message-to pitchcontrol toggle";
# more granular panning
"Alt+left" = "add video-pan-x 0.05";
"Alt+right" = "add video-pan-x -0.05";
"Alt+up" = "add video-pan-y 0.05";
"Alt+down" = "add video-pan-y -0.05";
# sub-delay for fixing 24 empty frames on blu-ray
"Alt+z" = "add sub-delay -1";
"Alt+Z" = "add sub-delay +1";
};
profiles = {
musicvideo = {
lavfi-complex = "[aid1]asplit=4[ao][a1][a2][a3];[a1]avectorscope=m=lissajous:s=640x600:draw=dot:r=25[avectorscope];[a2]aresample=44100,showwaves=s=1280x600:mode=p2p:colors=red|lightgreen:r=25[showwaves];[a3]showcqt=s=1920x600:axis=0:axis_h=0:r=25[showcqt];[showwaves][avectorscope]hstack=shortest=1[top];[top][showcqt]vstack=shortest=1,fps=25[vo]";
alpha = false;
};
musicvideo-1080 = {
lavfi-complex = "[aid1]asplit=4[ao][a1][a2][a3];[a1]avectorscope=m=lissajous:s=640x540:draw=dot:r=25[avectorscope];[a2]aresample=44100,showwaves=s=1280x540:mode=p2p:colors=red|lightgreen:r=25[showwaves];[a3]showcqt=s=1920x540:axis=0:axis_h=0:r=25[showcqt];[showwaves][avectorscope]hstack=shortest=1[top];[top][showcqt]vstack=shortest=1,fps=25[vo]";
alpha = false;
};
musicvideo-c64 = {
lavfi-complex = "[aid1]channelsplit=4.0[mono][c1][c2][c3];[mono]channelmap=mono,asplit=2[ao][a2];[c1][c2][c3]join=inputs=3:channel_layout=3.0[a1];[a1]aresample=44100,showwaves=s=1920x600:mode=p2p:colors=red|lightgreen|yellow:split_channels=1:r=25[showwaves];[a2]showcqt=s=1920x600:axis=0:axis_h=0:r=25[showcqt];[showwaves][showcqt]vstack=shortest=1,fps=25,format=rgba[vo]";
alpha = false;
};
hqencode = {
ovc = "libx264";
ovcopts-add = "crf=18";
oac = "flac";
audio-format = "s16";
};
lq = {
scale = "bicubic_fast";
cscale = "bicubic_fast";
dscale = "bicubic_fast";
};
hq = {
scale = "ewa_lanczossharp";
dscale = "ewa_lanczossharp";
cscale = "ewa_lanczossharp";
glsl-shader = [
"${mpv-prescalers}/compute/nnedi3-nns256-win8x4.hook"
"${mpv-prescalers}/compute/ravu-zoom-r4-chroma.hook"
];
};
interpolate = {
blend-subtitles = true;
video-sync = "display-resample";
interpolation = true;
tscale = "box";
tscale-window = "sphinx";
tscale-radius = 1.0;
tscale-clamp = 0.0;
};
# https://github.com/mpv-player/mpv/issues/4418#issuecomment-368272929
clear-speed.af-add = "scaletempo=stride=28:overlap=.9:search=25";
};
scripts = [
pitchcontrol
];
};
# mpv-gallery-view is not compatible with home-managers script injection meachanism
xdg.configFile."mpv/scripts/gallery-thumbgen-0.lua".source = "${gallery-view}/scripts/gallery-thumbgen.lua";
xdg.configFile."mpv/scripts/gallery-thumbgen-1.lua".source = "${gallery-view}/scripts/gallery-thumbgen.lua";
xdg.configFile."mpv/scripts/gallery-thumbgen-2.lua".source = "${gallery-view}/scripts/gallery-thumbgen.lua";
xdg.configFile."mpv/scripts/gallery-thumbgen-3.lua".source = "${gallery-view}/scripts/gallery-thumbgen.lua";
xdg.configFile."mpv/scripts/lib/gallery.lua".source = "${gallery-view}/scripts/lib/gallery.lua";
xdg.configFile."mpv/scripts/playlist-view.lua".source = "${gallery-view}/scripts/playlist-view.lua";
xdg.configFile."mpv/script-opts/playlist_view.conf".text = ''
thumbs_dir=${config.xdg.cacheHome}/thumbnails/mpv
'';
home.file."${config.xdg.cacheHome}/thumbnails/mpv/.create".text = "";
xdg.configFile."mpv/script-opts/stats.conf".text = ''
font=DINW07-Regular
font_mono=DINW07-Regular
font_size=10
redraw_delay=0.25
'';
}