lol

mpv: add script infrastructure & convert script

mpv’s functionality can be modified with lua scripts, by specifying them
on the command line.
`scripts` is a list of lua files that are appended to the default mpv
invocation. We also provide a `mpvScripts` attrset with the available
scripts in the top namespace.

`convert` is one such script, that extends mpv with a simple but very
convenient on-the-fly cropping and converting feature.

Closes #14040.

authored by

Profpatsch and committed by
Franz Pletz
c7d288fd ee547881

+102 -2
+6 -2
pkgs/applications/video/mpv/default.nix
··· 23 23 , cacaSupport ? true, libcaca ? null 24 24 , vaapiSupport ? false, libva ? null 25 25 , waylandSupport ? false, wayland ? null, libxkbcommon ? null 26 + # scripts you want to be loaded by default 27 + , scripts ? [] 26 28 }: 27 29 28 30 assert x11Support -> (libX11 != null && libXext != null && mesa != null && libXxf86vm != null); ··· 46 48 assert waylandSupport -> (wayland != null && libxkbcommon != null); 47 49 48 50 let 49 - inherit (stdenv.lib) optional optionals optionalString; 51 + inherit (stdenv.lib) optional optionals optionalString concatStringsSep; 50 52 51 53 # Purity: Waf is normally downloaded by bootstrap.py, but 52 54 # for purity reasons this behavior should be avoided. ··· 126 128 ln -s ${freefont_ttf}/share/fonts/truetype/FreeSans.ttf $out/share/mpv/subfont.ttf 127 129 '' + optionalString youtubeSupport '' 128 130 # Ensure youtube-dl is available in $PATH for MPV 129 - wrapProgram $out/bin/mpv --prefix PATH : "${youtube-dl}/bin" 131 + wrapProgram $out/bin/mpv \ 132 + --prefix PATH : "${youtube-dl}/bin" \ 133 + --add-flags "--script=${concatStringsSep "," scripts}" 130 134 ''; 131 135 132 136 meta = with stdenv.lib; {
+40
pkgs/applications/video/mpv/scripts/convert.nix
··· 1 + { stdenv, fetchgit, lib 2 + , yad, mkvtoolnix, libnotify }: 3 + 4 + stdenv.mkDerivation { 5 + name = "mpv-convert-script-2016-03-18.lua"; 6 + src = fetchgit { 7 + url = "https://gist.github.com/Zehkul/25ea7ae77b30af959be0"; 8 + rev = "f95cee43e390e843a47e8ec9d1711a12a8cd343d"; 9 + sha256 = "13m7l4sy2r8jv2sfrb3vvqvnim4a9ilnv28q5drlg09v298z3mck"; 10 + }; 11 + 12 + patches = [ ./convert.patch ]; 13 + 14 + postPatch = 15 + let 16 + t = k: v: '' 'local ${k} = "${v}"' ''; 17 + subs = var: orig: repl: "--replace " + t var orig + t var repl; 18 + in '' 19 + substituteInPlace convert_script.lua \ 20 + ${subs "NOTIFY_CMD" "notify-send" "${libnotify}/bin/notify-send"} \ 21 + ${subs "YAD_CMD" "yad" "${yad}/bin/yad"} \ 22 + ${subs "MKVMERGE_CMD" "mkvmerge" "${mkvtoolnix}/bin/mkvmerge"} 23 + ''; 24 + 25 + dontBuild = true; 26 + installPhase = '' 27 + cp convert_script.lua $out 28 + ''; 29 + 30 + meta = { 31 + description = "Convert parts of a video while you are watching it in mpv"; 32 + homepage = "https://gist.github.com/Zehkul/25ea7ae77b30af959be0"; 33 + maintainers = lib.maintainers.profpatsch; 34 + longDescription = '' 35 + When this script is loaded into mpv, you can hit Alt+W to mark the beginning 36 + and Alt+W again to mark the end of the clip. Then a settings window opens. 37 + ''; 38 + }; 39 + } 40 +
+52
pkgs/applications/video/mpv/scripts/convert.patch
··· 1 + --- convert/convert_script.lua 2016-03-18 19:30:49.675401969 +0100 2 + +++ convert_script.lua 2016-03-19 01:18:00.801897043 +0100 3 + @@ -3,6 +3,10 @@ 4 + local opt = require 'mp.options' 5 + local utils = require 'mp.utils' 6 + 7 + +local NOTIFY_CMD = "notify-send" 8 + +local YAD_CMD = "yad" 9 + +local MKVMERGE_CMD = "mkvmerge" 10 + + 11 + -- default options, convert_script.conf is read 12 + local options = { 13 + bitrate_multiplier = 0.975, -- to make sure the file won’t go over the target file size, set it to 1 if you don’t care 14 + @@ -354,9 +358,9 @@ 15 + if ovc == "gif" then 16 + full_command = full_command .. ' --vf-add=lavfi=graph=\\"framestep=' .. framestep .. '\\" && convert ' 17 + .. tmpfolder .. '/*.png -set delay ' .. delay .. ' -loop 0 -fuzz ' .. fuzz .. '% ' .. dither .. ' -layers optimize ' 18 + - .. full_output_path .. ' && rm -rf ' .. tmpfolder .. ' && notify-send "Gif done") & disown' 19 + + .. full_output_path .. ' && rm -rf ' .. tmpfolder .. ' && ' .. NOTIFY_CMD .. ' "Gif done") & disown' 20 + else 21 + - full_command = full_command .. ' && notify-send "Encoding done"; mkvpropedit ' 22 + + full_command = full_command .. ' && ' .. NOTIFY_CMD .. ' "Encoding done"; mkvpropedit ' 23 + .. full_output_path .. ' -s title="' .. metadata_title .. '") & disown' 24 + end 25 + 26 + @@ -409,7 +413,7 @@ 27 + sep = ",+" 28 + 29 + if enc then 30 + - local command = "mkvmerge '" .. video .. "' " .. mkvmerge_parts .. " -o " .. full_output_path 31 + + local command = MKVMERGE_CMD .. " '" .. video .. "' " .. mkvmerge_parts .. " -o " .. full_output_path 32 + msg.info(command) 33 + os.execute(command) 34 + clear() 35 + @@ -508,7 +512,7 @@ 36 + end 37 + 38 + 39 + - local yad_command = [[LC_NUMERIC=C yad --title="Convert Script" --center --form --fixed --always-print-result \ 40 + + local yad_command = [[LC_NUMERIC=C ]] .. YAD_CMD .. [[ --title="Convert Script" --center --form --fixed --always-print-result \ 41 + --name "convert script" --class "Convert Script" --field="Resize to height:NUM" "]] .. scale_sav --yad_table 1 42 + .. [[" --field="Resize to width instead:CHK" ]] .. resize_to_width_instead .. " " --yad_table 2 43 + if options.legacy_yad then 44 + @@ -543,7 +547,7 @@ 45 + yad_command = yad_command .. [[ --button="Crop:1" --button="gtk-cancel:2" --button="gtk-ok:0"; ret=$? && echo $ret]] 46 + 47 + if gif_dialog then 48 + - yad_command = [[echo $(LC_NUMERIC=C yad --title="Gif settings" --name "convert script" --class "Convert Script" \ 49 + + yad_command = [[echo $(LC_NUMERIC=C ]] .. YAD_CMD .. [[ --title="Gif settings" --name "convert script" --class "Convert Script" \ 50 + --center --form --always-print-result --separator="…" \ 51 + --field="Fuzz Factor:NUM" '1!0..100!0.5!1' \ 52 + --field="Framestep:NUM" '3!1..3!1' \
+4
pkgs/top-level/all-packages.nix
··· 13456 13456 vaapiSupport = config.mpv.vaapiSupport or false; 13457 13457 }; 13458 13458 13459 + mpvScripts = { 13460 + convert = callPackage ../applications/video/mpv/scripts/convert.nix {}; 13461 + }; 13462 + 13459 13463 mrpeach = callPackage ../applications/audio/pd-plugins/mrpeach { }; 13460 13464 13461 13465 mrxvt = callPackage ../applications/misc/mrxvt { };