Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* NOTE: relevant definitions from "utility"
- # Create attrset {name=$name, value=$value}
- nameValuePair = name: value: { inherit name value; };
- # Create attrset of many keys with the same value
- repeatValueForKeys = value: listOfKeys: builtins.listToAttrs (builtins.map (key: nameValuePair key value) listOfKeys);
- */
- # TODO: modularize?
- # TODO: firejail?
- {home-manager, pkgs, fetchFromGitHub, utility, ...}:
- let
- # got the structure and idea to use profiles from https://github.com/arvigeus/nixos-config/blob/d653e29a76537eaeb8edd857d36a4d2bf0f00693/apps/mpv.nix
- # mpv scripts that aren't in nixpkgs
- customScripts = {
- cycleCommands = ( # https://github.com/CogentRedTester/mpv-scripts
- pkgs.stdenvNoCC.mkDerivation rec {
- pname = "mpv-cycleCommands";
- version = "2024-01-18_05aee33";
- src = pkgs.fetchFromGitHub {
- owner = "CogentRedTester";
- repo = "mpv-scripts";
- rev = "05aee333a232e858dc3e54f973edfe392cefe13b";
- hash = "sha256-JaPl7XcdsIJ3Y0iWxbCVxZz9yEMaFjJ8qMSbQ3Z/tr4=";
- } + "/cycle-commands.lua";
- dontBuild = true;
- dontUnpack = true;
- installPhase = "install -Dm644 ${src} $out/share/mpv/scripts/cycle-commands.lua";
- passthru.scriptName = "cycle-commands.lua";
- }
- );
- clipboard = ( # https://github.com/CogentRedTester/mpv-clipboard
- pkgs.stdenvNoCC.mkDerivation rec {
- pname = "mpv-clipboard";
- version = "2024-01-18_05aee33";
- src = pkgs.fetchFromGitHub {
- owner = "CogentRedTester";
- repo = "mpv-clipboard";
- rev = "d5cb11094da23a2153370964b65dbbc44c3058df";
- hash = "sha256-426WEPd/hfvngAIzNuQOLhcXgpP5ekX7EmtlFCbHhAM=";
- } + "/clipboard.lua";
- dontBuild = true;
- dontUnpack = true;
- installPhase = "install -Dm644 ${src} $out/share/mpv/scripts/clipboard.lua";
- passthru.scriptName = "clipboard.lua";
- }
- );
- copyPasteTime = ( # https://github.com/alaestor/mpv-copyPasteTime
- pkgs.stdenvNoCC.mkDerivation rec {
- pname = "mpv-copyPasteTime";
- version = "0.1.0";
- src = pkgs.fetchFromGitHub {
- owner = "alaestor";
- repo = "mpv-copyPasteTime";
- rev = "v${version}"; # commit or tag
- hash = "sha256-1hEj20z0/NVP3tSd4bBGCmC3O2eVIhUJWGJ5+lphx08=";
- } + "/copyPasteTime.lua";
- dontBuild = true;
- dontUnpack = true;
- installPhase = "install -Dm644 ${src} $out/share/mpv/scripts/copyPasteTime.lua";
- passthru.scriptName = "copyPasteTime.lua";
- }
- );
- };
- # mpv shaders that aren't in nixpkgs
- customShaders = {
- SSSR = ( # https://gist.github.com/igv/2364ffa6e81540f29cb7ab4c9bc05b6b
- pkgs.stdenvNoCC.mkDerivation rec {
- name = "SSimSuperRes";
- src = pkgs.fetchurl {
- url = "https://gist.githubusercontent.com/igv/2364ffa6e81540f29cb7ab4c9bc05b6b/raw/15d93440d0a24fc4b8770070be6a9fa2af6f200b/SSimSuperRes.glsl";
- sha256 = "sha256-qLJxFYQMYARSUEEbN14BiAACFyWK13butRckyXgVRg8=";
- };
- dontBuild = true;
- dontUnpack = true;
- installPhase = "install -Dm644 ${src} $out/share/shaders/SSimSuperRes.glsl";
- }
- );
- ArtCNN = ( # https://github.com/Artoriuz/ArtCNN
- pkgs.stdenvNoCC.mkDerivation rec {
- pname = "ArtCNN";
- version = "1.1.0";
- src = pkgs.fetchFromGitHub {
- owner = "Artoriuz";
- repo = "ArtCNN";
- rev = "v${version}";
- hash = "sha256-7im2NK1Jr2+Cc0lGyGjtk4YClMm5ZK6DfTZyr1jUYLI=";
- } + "/GLSL";
- dontBuild = true;
- dontUnpack = true;
- installPhase = ''
- mkdir -p $out/share/${pname}
- cp -r ${src} $out/share/${pname}
- '';
- }
- );
- };
- # paths to shaders from packages
- shaders = {
- defaultPack = "${pkgs.mpv-shim-default-shaders}/share/mpv-shim-default-shaders/shaders";
- artCNN = "${customShaders.ArtCNN}/share/ArtCNN/GLSL";
- sssrFile = "${customShaders.SSSR}/share/shaders/SSimSuperRes.glsl";
- };
- # only including the ones I care about... I'll probably change and tune these in the future.
- # got the structure and idea to use profiles from https://github.com/arvigeus/nixos-config/blob/d653e29a76537eaeb8edd857d36a4d2bf0f00693/apps/mpv.nix
- scalers = {
- ## MPV native upscaling (default)
- generic = {
- name = "hanning (default)";
- settings = {
- scale = "ewa_hanning";
- cscale = "ewa_lanczos";
- dscale = "mitchell";
- };
- };
- ## SSimSuperRes
- super = {
- name = "superRes";
- settings = {
- scale = "ewa_hanning";
- cscale = "ewa_lanczos";
- dscale = "mitchell";
- glsl-shaders = [ "${shaders.sssrFile}" ];
- };
- };
- ## FSRCNNX
- fsrcnnx = {
- name = "general purpose [FSRCNNX16/SSimDown/KrigBilat]";
- settings = {
- cscale = "mitchell";
- dscale = "mitchell";
- glsl-shaders = [ "${shaders.defaultPack}/FSRCNNX_x2_16-0-4-1.glsl" ];
- glsl-shaders-append = [
- "${shaders.defaultPack}/SSimDownscaler.glsl"
- "${shaders.defaultPack}/KrigBilateral.glsl"
- ];
- };
- };
- ## ArtCNN - NOTE: switch to non-compute variants for compatibility (omit "/Compute" and "_CMP")
- art = {
- name = "anime [ArtCNN_C4F32_CMP]";
- settings = {
- cscale = "mitchell";
- dscale = "mitchell";
- glsl-shaders = [ "${shaders.artCNN}/Compute/ArtCNN_C4F32_CMP.glsl" ];
- };
- };
- artde = {
- name = "anime denoising [ArtCNN_C4F32_DS_CMP]";
- settings = {
- cscale = "mitchell";
- dscale = "mitchell";
- glsl-shaders = [ "${shaders.artCNN}/Compute/ArtCNN_C4F32_DS_CMP.glsl" ];
- };
- };
- ## Anime4k
- anime4k_a = {
- name = "Anime4K A (HQ) - For Very Blurry/Compressed";
- settings = {
- glsl-shaders = [ "${shaders.defaultPack}/Anime4K_Clamp_Highlights.glsl" ];
- glsl-shaders-append = [
- "${shaders.defaultPack}/Anime4K_Restore_CNN_VL.glsl"
- "${shaders.defaultPack}/Anime4K_Upscale_CNN_x2_VL.glsl"
- "${shaders.defaultPack}/Anime4K_AutoDownscalePre_x2.glsl"
- "${shaders.defaultPack}/Anime4K_AutoDownscalePre_x4.glsl"
- "${shaders.defaultPack}/Anime4K_Upscale_CNN_x2_M.glsl"
- ];
- };
- };
- anime4k_b = {
- name = "Anime4K B (HQ) - For Blurry/Ringing";
- settings = {
- glsl-shaders = [ "${shaders.defaultPack}/Anime4K_Clamp_Highlights.glsl" ];
- glsl-shaders-append = [
- "${shaders.defaultPack}/CAS-scaled.glsl"
- "${shaders.defaultPack}/Anime4K_Restore_CNN_Soft_VL.glsl"
- "${shaders.defaultPack}/Anime4K_Upscale_CNN_x2_VL.glsl"
- "${shaders.defaultPack}/Anime4K_AutoDownscalePre_x2.glsl"
- "${shaders.defaultPack}/Anime4K_AutoDownscalePre_x4.glsl"
- "${shaders.defaultPack}/Anime4K_Upscale_CNN_x2_M.glsl"
- ];
- };
- };
- anime4k_c = {
- name = "Anime4K C (HQ) - For Crisp/Sharp";
- settings = {
- glsl-shaders = [ "${shaders.defaultPack}/Anime4K_Clamp_Highlights.glsl" ];
- glsl-shaders-append = [
- "${shaders.defaultPack}/Anime4K_Upscale_Denoise_CNN_x2_VL.glsl"
- "${shaders.defaultPack}/Anime4K_AutoDownscalePre_x2.glsl"
- "${shaders.defaultPack}/Anime4K_AutoDownscalePre_x4.glsl"
- "${shaders.defaultPack}/Anime4K_Upscale_CNN_x2_M.glsl"
- ];
- };
- };
- };
- in
- {
- # pull in shaders from nixpkgs and customShaders
- home.packages = [
- pkgs.mpv-shim-default-shaders
- customShaders.SSSR
- customShaders.ArtCNN
- ];
- # enable and configure mpv
- programs.mpv = {
- enable = true;
- package = pkgs.mpv;
- # pull in scripts from nixpkgs and customScripts
- scripts = [
- pkgs.mpvScripts.seekTo
- pkgs.mpvScripts.thumbfast
- customScripts.cycleCommands
- customScripts.clipboard
- customScripts.copyPasteTime
- ];
- # note: to convert from nix to raw conf files:
- # remove `= ""`, replace true/false -> yes/no, remove outer `''` and `"` quotes (not inner eg cycle-commands)
- # reference: https://github.com/mpv-player/mpv/blob/master/DOCS/man/options.rst
- config = {
- ### Player, Console, OSD/OSC, UI
- title = "\${filename} - mpv";
- keep-open = true; # don't close when finished
- border = true;
- fullscreen = false; # start windowed
- msg-color = true;
- msg-module = true;
- reset-on-next-file = "audio-delay,mute,pause,speed,sub-delay,video-aspect-override,video-pan-x,video-pan-y,video-rotate,video-zoom";
- no-resume-playback = "";
- no-input-default-bindings = ""; # disable keybinds; explicitly declared via `bindings` (input.conf)
- ### Screenshots
- screenshot-dir = "~/Pictures/mpv";
- screenshot-template = ''"T%wM%wS-%#01n-%F [%P]"'';
- screenshot-format = "jpg"; # jpg,png - png for reference/comparisons, jpg for quick sharing
- screenshot-jpeg-quality = 90;
- screenshot-png-compression = 0; # 0 to 10. 0 being no compression.
- screenshot-tag-colorspace = true;
- screenshot-high-bit-depth = true; # rame output bitdepth as the video
- ### Subtitles
- sid = "auto"; # default sub stream
- sub-auto = "fuzzy"; # external subs don't have to match the file name exactly to autoload
- sub-ass-use-video-data = "all"; # Backward compatibility for vsfilter fansubs
- sub-ass-scale-with-window = false; # May have undesired effects with signs being misplaced.
- sub-file-paths-append = ["ass" "srt" "sub" "subs" "subtitles" "en" "eng" "english"];
- demuxer-mkv-subtitle-preroll = ""; # try to correctly show embedded subs when seeking
- embeddedfonts = true; # use embedded fonts for SSA/ASS subs
- sub-fix-timing = false; # do not try to fix gaps (which might make it worse in some cases). Enable if there are scenebleeds.
- blend-subtitles = true; # yes=bake into frame before filtering, no=overlay after frame filtering
- ### Demuxer and cache
- cache = true;
- cache-on-disk = false; # false = cache in RAM rather than a temporary file
- demuxer-max-bytes = "1GiB"; # forward default is 400MiB
- demuxer-max-back-bytes = "1GiB";
- ### Renderer
- vo = "gpu-next";
- hwdec = "auto-safe"; # enable best HW decoder; `false` for software decoding
- # NOTE switch to opengl for compatibility
- gpu-api = "vulkan"; # `auto`, `vulkan`, `opengl`, or `d3d11` (typically for nvidia)
- vulkan-async-compute = true;
- vulkan-async-transfer = true;
- vd-lavc-dr = true; # decode directly to GPU video memory (or staging buffers)
- ### Audio
- volume = 50;
- volume-max = 150; # >100 is amplification
- audio-stream-silence = false; # "enabling this option is strongly discouraged" but can fix audio popping on random seek
- audio-channels = "stereo"; # downmix for headphones
- audio-file-auto = "fuzzy"; # external audio doesn't has to match the file name exactly to autoload
- audio-pitch-correction = true; # automatically insert scaletempo when playing with higher speed
- af = "lavfi=[loudnorm=I=-16:TP=-3:LRA=4]"; # loudness normalization; solves quiet dialogue problem in movies
- ## Video & Filtering
- dither = "error-diffusion";
- dither-depth = "auto";
- temporal-dither = true;
- deband = false; # could lose detail; toggle manually using hotkey (b for banding)
- deband-iterations = 3;
- deband-threshold = 20;
- deband-range = 16;
- deband-grain = 5; # dynamic grain: set to "0" if using a static grain shader
- scale = "ewa_hanning";
- scale-radius = 3.2383154841662362; # magic number from somewhere?
- cscale = "ewa_lanczos";
- dscale = "mitchell";
- scale-antiring = 0.6; # luma upscale deringing
- dscale-antiring = 0.6; # luma downscale deringing
- cscale-antiring = 0; # chroma upscale deringing
- #tscale = "box"; # frame interp... nty.
- #tscale-window = "quadric";
- #tscale-radius = 1.1;
- #tscale-clamp = 0.0;
- #tscale = "oversample";
- video-sync = "display-resample"; # resample audio to video, rather than video to audio. Try to adjust audio speed to compensate for drift
- interpolation = false; # reduce stuttering caused by mismatches
- correct-downscaling = true;
- linear-downscaling = false;
- sigmoid-upscaling = true;
- tone-mapping = "mobius"; # bt.2390
- target-colorspace-hint = true;
- target-prim = "auto"; # bt.709
- target-trc = "auto";
- target-peak = "auto"; # 960
- hdr-peak-percentile = 99.995; # from MPV's high-quality builtin profile
- hdr-contrast-recovery = 0.30; # from MPV's high-quality builtin profile
- hdr-compute-peak = true;
- #vf = ''format="colorlevels=full:colormatrix=auto"'';
- #video-output-levels = "full"; # "use your graphics driver's color range option instead, if available"
- # Default shaders
- glsl-shaders-clr = "";
- };
- # see https://github.com/mpv-player/mpv/blob/master/etc/input.conf
- # and https://mpv.io/manual/master/#key-names
- bindings = {
- ### Navigation
- "CTRL+c" = "script-message-to copyPasteTime copyTime";
- "SHIFT+c" = "script-message-to copyPasteTime copyFrame";
- "CTRL+v" = "script-message-to copyPasteTime pasteTime";
- "t" = "script-message-to seek_to toggle-seeker";
- "." = "add chapter 1";
- "," = "add chapter -1";
- "RIGHT" = "seek 5"; # vanilla
- "LEFT" = "seek -5"; # vanilla
- "WHEEL_LEFT" = "seek -10"; # vanilla
- "WHEEL_RIGHT" = "seek 10"; # vanilla
- "SHIFT+RIGHT" = "frame-step";
- "SHIFT+LEFT" = "frame-back-step";
- "CTRL+RIGHT" = "seek +0.001 keyframes";
- "CTRL+LEFT" = "seek -0.01 keyframes";
- ### Playback
- "MBTN_LEFT" = "ignore"; # vanilla
- "MBTN_RIGHT" = "cycle pause"; # vanilla
- "SPACE" = "cycle pause"; # vanilla
- "{" = "add speed -0.25";
- "}" = "add speed 0.25";
- "[" = "add sub-delay -0.1";
- "]" = "add sub-delay +0.1";
- "-" = "add audio-delay -0.1";
- "=" = "add audio-delay +0.1";
- ### Track switching
- "a" = "cycle audio";
- "v" = "cycle video";
- "s" = "cycle sub";
- ### Screenshot
- "CTRL+s" = "screenshot";
- "SHIFT+s" = "screenshot video";
- ### Volume
- "UP" = "add volume 1";
- "DOWN" = "add volume -1";
- "SHIFT+UP" = "add volume 10";
- "SHIFT+DOWN" = "add volume -10";
- "WHEEL_UP" = "add volume 2"; # vanilla
- "WHEEL_DOWN" = "add volume -2"; # vanilla
- "m" = "cycle mute"; # vanilla
- ### Filtering & Adjustments
- "l" = ''script-message cycle-commands "set af \"lavfi=[loudnorm=I=-16:TP=-3:LRA=4]\";show-text \"Normalized Loudness\"" "set af \"\";show-text \"Unnormalized Loudness\""'';
- "d" = "cycle deinterlace";
- "b" = "cycle deband";
- "1" = "add contrast -1"; # vanilla
- "2" = "add contrast 1"; # vanilla
- "3" = "add brightness -1"; # vanilla
- "4" = "add brightness 1"; # vanilla
- "5" = "add gamma -1"; # vanilla
- "6" = "add gamma 1"; # vanilla
- "7" = "add saturation -1"; # vanilla
- "8" = "add saturation 1"; # vanilla
- ### Window
- "`" = "script-binding console/enable"; # vanilla
- "SHIFT+t" = "cycle ontop";
- "f" = "cycle fullscreen"; # vanilla
- "ESC" = "set fullscreen no";
- "MBTN_LEFT_DBL" = "cycle fullscreen";
- "CTRL+WHEEL_UP" = "add video-zoom 0.1"; # vanilla
- "CTRL+WHEEL_DOWN" = "add video-zoom -0.1"; # vanilla
- "p" = "show-progress";
- "e" = "cycle edition";
- "CLOSE_WIN" = "quit"; # vanilla
- "F3" = "script-binding stats/display-stats-toggle";
- ### Scaler profiles
- "CTRL+0" = ''show-text "Profile: ${scalers.generic.name}"; no-osd change-list glsl-shaders clr all; apply-profile generic'';
- "CTRL+1" = ''show-text "Profile: ${scalers.super.name}"; no-osd apply-profile super'';
- "CTRL+2" = ''show-text "Profile: ${scalers.fsrcnnx.name}"; no-osd apply-profile fsrcnnx'';
- "CTRL+3" = ''show-text "Profile: ${scalers.art.name}"; no-osd apply-profile art'';
- "CTRL+4" = ''show-text "Profile: ${scalers.artde.name}"; no-osd apply-profile artde'';
- "CTRL+5" = ''show-text "Profile: ${scalers.anime4k_a.name}"; no-osd apply-profile anime4k_a'';
- "CTRL+6" = ''show-text "Profile: ${scalers.anime4k_b.name}"; no-osd apply-profile anime4k_b'';
- "CTRL+7" = ''show-text "Profile: ${scalers.anime4k_c.name}"; no-osd apply-profile anime4k_c'';
- };
- # using profiles for scalers
- profiles = {
- generic = scalers.generic.settings;
- super = scalers.super.settings;
- fsrcnnx = scalers.fsrcnnx.settings;
- art = scalers.art.settings;
- artde = scalers.artde.settings;
- anime4k_a = scalers.anime4k_a.settings;
- anime4k_b = scalers.anime4k_b.settings;
- anime4k_c = scalers.anime4k_c.settings;
- };
- };
- xdg.mimeApps = {
- enable = true;
- #associations.added = { "inode/directory" = [ "mpv.desktop" ]; };
- defaultApplications = utility.repeatValueForKeys "mpv.desktop" [
- "application/mxf"
- "application/sdp"
- "application/smil"
- "application/streamingmedia"
- "application/vnd.apple.mpegurl"
- "application/vnd.ms-asf"
- "application/vnd.rn-realmedia"
- "application/vnd.rn-realmedia-vbr"
- "application/x-cue"
- "application/x-extension-m4a"
- "application/x-extension-mp4"
- "application/x-matroska"
- "application/x-mpegurl"
- "application/x-ogm"
- "application/x-ogm-video"
- "application/x-shorten"
- "application/x-smil"
- "application/x-streamingmedia"
- "video/3gp"
- "video/3gpp"
- "video/3gpp2"
- "video/avi"
- "video/divx"
- "video/dv"
- "video/fli"
- "video/flv"
- "video/mkv"
- "video/mp2t"
- "video/mp4"
- "video/mp4v-es"
- "video/mpeg"
- "video/msvideo"
- "video/ogg"
- "video/quicktime"
- "video/vnd.divx"
- "video/vnd.mpegurl"
- "video/vnd.rn-realvideo"
- "video/webm"
- "video/x-avi"
- "video/x-flc"
- "video/x-flic"
- "video/x-flv"
- "video/x-m4v"
- "video/x-matroska"
- "video/x-mpeg2"
- "video/x-mpeg3"
- "video/x-ms-afs"
- "video/x-ms-asf"
- "video/x-ms-wmv"
- "video/x-ms-wmx"
- "video/x-ms-wvxvideo"
- "video/x-msvideo"
- "video/x-ogm"
- "video/x-ogm+ogg"
- "video/x-theora"
- "video/x-theora+ogg"
- ];
- };
- # ???
- # firejail = {
- # enable = true;
- # wrappedBinaries.mpv = {
- # executable = "${pkgs.mpv}/bin/mpv";
- # profile = "${pkgs.firejail}/etc/firejail/mpv.profile";
- # };
- # };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement