about summary refs log tree commit diff
path: root/pkgs/applications/video/mpv
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2016-03-19 02:32:29 +0100
committerFranz Pletz <fpletz@fnordicwalking.de>2016-05-28 15:16:12 +0200
commitc7d288fd569cbd38df1cfdff91a757393475fd42 (patch)
tree51ac06f72c5e1b036e9d616d57571cb4629be5ec /pkgs/applications/video/mpv
parentee547881d6931c636c17f91ca066efe8f6b1ccbf (diff)
downloadnixlib-c7d288fd569cbd38df1cfdff91a757393475fd42.tar
nixlib-c7d288fd569cbd38df1cfdff91a757393475fd42.tar.gz
nixlib-c7d288fd569cbd38df1cfdff91a757393475fd42.tar.bz2
nixlib-c7d288fd569cbd38df1cfdff91a757393475fd42.tar.lz
nixlib-c7d288fd569cbd38df1cfdff91a757393475fd42.tar.xz
nixlib-c7d288fd569cbd38df1cfdff91a757393475fd42.tar.zst
nixlib-c7d288fd569cbd38df1cfdff91a757393475fd42.zip
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.
Diffstat (limited to 'pkgs/applications/video/mpv')
-rw-r--r--pkgs/applications/video/mpv/default.nix8
-rw-r--r--pkgs/applications/video/mpv/scripts/convert.nix40
-rw-r--r--pkgs/applications/video/mpv/scripts/convert.patch52
3 files changed, 98 insertions, 2 deletions
diff --git a/pkgs/applications/video/mpv/default.nix b/pkgs/applications/video/mpv/default.nix
index dd5f25d3a6c6..bd1af2ce29a0 100644
--- a/pkgs/applications/video/mpv/default.nix
+++ b/pkgs/applications/video/mpv/default.nix
@@ -23,6 +23,8 @@
 , cacaSupport ? true, libcaca ? null
 , vaapiSupport ? false, libva ? null
 , waylandSupport ? false, wayland ? null, libxkbcommon ? null
+# scripts you want to be loaded by default
+, scripts ? []
 }:
 
 assert x11Support -> (libX11 != null && libXext != null && mesa != null && libXxf86vm != null);
@@ -46,7 +48,7 @@ assert cacaSupport -> libcaca != null;
 assert waylandSupport -> (wayland != null && libxkbcommon != null);
 
 let
-  inherit (stdenv.lib) optional optionals optionalString;
+  inherit (stdenv.lib) optional optionals optionalString concatStringsSep;
 
   # Purity: Waf is normally downloaded by bootstrap.py, but
   # for purity reasons this behavior should be avoided.
@@ -126,7 +128,9 @@ stdenv.mkDerivation rec {
     ln -s ${freefont_ttf}/share/fonts/truetype/FreeSans.ttf $out/share/mpv/subfont.ttf
   '' + optionalString youtubeSupport ''
     # Ensure youtube-dl is available in $PATH for MPV
-    wrapProgram $out/bin/mpv --prefix PATH : "${youtube-dl}/bin"
+    wrapProgram $out/bin/mpv \
+      --prefix PATH : "${youtube-dl}/bin" \
+      --add-flags "--script=${concatStringsSep "," scripts}"
   '';
 
   meta = with stdenv.lib; {
diff --git a/pkgs/applications/video/mpv/scripts/convert.nix b/pkgs/applications/video/mpv/scripts/convert.nix
new file mode 100644
index 000000000000..8dc2fc037e6d
--- /dev/null
+++ b/pkgs/applications/video/mpv/scripts/convert.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchgit, lib
+, yad, mkvtoolnix, libnotify }:
+
+stdenv.mkDerivation {
+  name = "mpv-convert-script-2016-03-18.lua";
+  src = fetchgit {
+    url = "https://gist.github.com/Zehkul/25ea7ae77b30af959be0";
+    rev = "f95cee43e390e843a47e8ec9d1711a12a8cd343d";
+    sha256 = "13m7l4sy2r8jv2sfrb3vvqvnim4a9ilnv28q5drlg09v298z3mck";
+  };
+
+  patches = [ ./convert.patch ];
+
+  postPatch =
+    let
+      t = k: v: '' 'local ${k} = "${v}"' '';
+      subs = var: orig: repl: "--replace " + t var orig + t var repl;
+    in ''
+      substituteInPlace convert_script.lua \
+        ${subs "NOTIFY_CMD" "notify-send" "${libnotify}/bin/notify-send"} \
+        ${subs "YAD_CMD" "yad" "${yad}/bin/yad"} \
+        ${subs "MKVMERGE_CMD" "mkvmerge" "${mkvtoolnix}/bin/mkvmerge"}
+  '';
+
+  dontBuild = true;
+  installPhase = ''
+    cp convert_script.lua $out
+  '';
+
+  meta = {
+    description = "Convert parts of a video while you are watching it in mpv";
+    homepage = "https://gist.github.com/Zehkul/25ea7ae77b30af959be0";
+    maintainers = lib.maintainers.profpatsch;
+    longDescription = ''
+      When this script is loaded into mpv, you can hit Alt+W to mark the beginning
+      and Alt+W again to mark the end of the clip. Then a settings window opens.
+    '';
+  };
+}
+
diff --git a/pkgs/applications/video/mpv/scripts/convert.patch b/pkgs/applications/video/mpv/scripts/convert.patch
new file mode 100644
index 000000000000..92d0fae1d503
--- /dev/null
+++ b/pkgs/applications/video/mpv/scripts/convert.patch
@@ -0,0 +1,52 @@
+--- convert/convert_script.lua	2016-03-18 19:30:49.675401969 +0100
++++ convert_script.lua	2016-03-19 01:18:00.801897043 +0100
+@@ -3,6 +3,10 @@
+ local opt = require 'mp.options'
+ local utils = require 'mp.utils'
+ 
++local NOTIFY_CMD = "notify-send"
++local YAD_CMD = "yad"
++local MKVMERGE_CMD = "mkvmerge"
++
+ -- default options, convert_script.conf is read
+ local options = {
+     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
+@@ -354,9 +358,9 @@
+     if ovc == "gif" then
+         full_command = full_command .. ' --vf-add=lavfi=graph=\\"framestep=' .. framestep .. '\\" && convert ' 
+         .. tmpfolder .. '/*.png -set delay ' .. delay .. ' -loop 0 -fuzz ' .. fuzz .. '% ' .. dither .. ' -layers optimize '
+-        .. full_output_path .. ' && rm -rf ' .. tmpfolder .. ' && notify-send "Gif done") & disown'
++        .. full_output_path .. ' && rm -rf ' .. tmpfolder .. ' && ' .. NOTIFY_CMD .. ' "Gif done") & disown'
+     else
+-        full_command = full_command .. ' && notify-send "Encoding done"; mkvpropedit '
++        full_command = full_command .. ' && ' .. NOTIFY_CMD .. ' "Encoding done"; mkvpropedit '
+         .. full_output_path .. ' -s title="' .. metadata_title .. '") & disown'
+     end
+     
+@@ -409,7 +413,7 @@
+     sep = ",+"
+     
+     if enc then
+-        local command = "mkvmerge '" .. video .. "' " .. mkvmerge_parts .. " -o " .. full_output_path
++        local command = MKVMERGE_CMD .. " '" .. video .. "' " .. mkvmerge_parts .. " -o " .. full_output_path
+         msg.info(command)
+         os.execute(command)
+         clear()
+@@ -508,7 +512,7 @@
+     end
+     
+     
+-    local yad_command = [[LC_NUMERIC=C yad --title="Convert Script" --center --form --fixed --always-print-result \
++    local yad_command = [[LC_NUMERIC=C ]] .. YAD_CMD .. [[ --title="Convert Script" --center --form --fixed --always-print-result \
+     --name "convert script" --class "Convert Script" --field="Resize to height:NUM" "]] .. scale_sav		--yad_table 1
+     .. [[" --field="Resize to width instead:CHK" ]] .. resize_to_width_instead .. " "				--yad_table 2
+     if options.legacy_yad then
+@@ -543,7 +547,7 @@
+     yad_command = yad_command .. [[ --button="Crop:1" --button="gtk-cancel:2" --button="gtk-ok:0"; ret=$? && echo $ret]]
+     
+     if gif_dialog then
+-        yad_command = [[echo $(LC_NUMERIC=C yad --title="Gif settings" --name "convert script" --class "Convert Script" \
++        yad_command = [[echo $(LC_NUMERIC=C ]] .. YAD_CMD .. [[ --title="Gif settings" --name "convert script" --class "Convert Script" \
+         --center --form --always-print-result --separator="…" \
+         --field="Fuzz Factor:NUM" '1!0..100!0.5!1' \
+         --field="Framestep:NUM" '3!1..3!1' \