From b38c5144fe75c860fd899d9cf5ba296767cee909 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Mon, 7 Dec 2020 12:15:52 +0800 Subject: [PATCH 1/5] [feature] cut video with ffmpeg --- gui/mpv/scripts/cut.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 gui/mpv/scripts/cut.lua diff --git a/gui/mpv/scripts/cut.lua b/gui/mpv/scripts/cut.lua new file mode 100644 index 0000000..9aa5896 --- /dev/null +++ b/gui/mpv/scripts/cut.lua @@ -0,0 +1,38 @@ +local utils = require "mp.utils" + +function mark_begin() + begin_pos = mp.get_property('time-pos') + mp.osd_message('Begin Position Marked at ' .. begin_pos) +end + +function mark_end() + end_pos = mp.get_property('time-pos') + mp.osd_message('End Position Marked at ' .. end_pos) +end + +function output_marked() + --if not begin_pos and not end_pos then + --mp.osd_message('Please set Begin Position with Ctrl-b, End Position with Ctrl-e') + --return + --end + ss = begin_pos or 0 + t = end_pos or mp.get_property('duration') + path = mp.get_property('path') + dir, file = utils.split_path(path) + output_dir = utils.join_path(dir, 'clips') + utils.subprocess({ + args={'mkdir', '-p', output_dir}, + cancellable=false + }) + output_file = utils.join_path(output_dir, file) + utils.subprocess({ + args={'ffmpeg', '-i', path, '-ss', tostring(ss), '-t', tostring(t), '-c', 'copy', output_file}, + cancellable=false + }) + mp.osd_message('Clip save to ' .. output_file) +end + + +mp.add_key_binding("ctrl+b", "mark_begin", mark_begin); +mp.add_key_binding("ctrl+e", "mark_end", mark_end); +mp.add_key_binding("ctrl+o", "output_marked", output_marked); From 84f7f50ea1355d827199b822f3cc143a37ef82b3 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Mon, 7 Dec 2020 14:22:29 +0800 Subject: [PATCH 2/5] [bugfix] fix keyframe --- gui/mpv/scripts/cut.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/mpv/scripts/cut.lua b/gui/mpv/scripts/cut.lua index 9aa5896..e6ec77c 100644 --- a/gui/mpv/scripts/cut.lua +++ b/gui/mpv/scripts/cut.lua @@ -26,7 +26,7 @@ function output_marked() }) output_file = utils.join_path(output_dir, file) utils.subprocess({ - args={'ffmpeg', '-i', path, '-ss', tostring(ss), '-t', tostring(t), '-c', 'copy', output_file}, + args={'ffmpeg', '-ss', tostring(ss), '-i', path, '-t', tostring(t), '-c', 'copy', output_file}, cancellable=false }) mp.osd_message('Clip save to ' .. output_file) From d99be97751ad1af4d5424583156aa614a0a0ffd1 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Mon, 7 Dec 2020 16:54:35 +0800 Subject: [PATCH 3/5] [misc] C-p for displaying playlist --- gui/mpv/input.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 gui/mpv/input.conf diff --git a/gui/mpv/input.conf b/gui/mpv/input.conf new file mode 100644 index 0000000..917b40a --- /dev/null +++ b/gui/mpv/input.conf @@ -0,0 +1 @@ +CTRL+p script-message osc-playlist \ No newline at end of file From 531e02be1ed01772ee1f28543c06c62b636aba00 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Mon, 7 Dec 2020 16:55:12 +0800 Subject: [PATCH 4/5] [misc] ln cut.lua and input.conf --- gui/player.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gui/player.sh b/gui/player.sh index 87b5131..d57b087 100755 --- a/gui/player.sh +++ b/gui/player.sh @@ -19,7 +19,9 @@ esac # symlink configuration lnsf "$DIR/mpd/mpd.conf" "$XDG_CONFIG_HOME/mpd/mpd.conf" lnsf "$DIR/mpv/mpv.conf" "$XDG_CONFIG_HOME/mpv/mpv.conf" +lnsf "$DIR/mpv/input.conf" "$XDG_CONFIG_HOME/mpv/input.conf" lnsf "$DIR/mpv/scripts/organize.lua" "$XDG_CONFIG_HOME/mpv/scripts/organize.lua" +lnsf "$DIR/mpv/scripts/cut.lua" "$XDG_CONFIG_HOME/mpv/scripts/cut.lua" lnsf "$DIR/ncmpcpp/bindings" "$XDG_CONFIG_HOME/ncmpcpp/bindings" lnsf "$DIR/ncmpcpp/config" "$XDG_CONFIG_HOME/ncmpcpp/config" From 114e18180d33c1b7b32151f2a4c48fcf0d3c1170 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Mon, 7 Dec 2020 17:12:36 +0800 Subject: [PATCH 5/5] [feature] open with mpv for media cutting --- cli/ranger/commands.py | 23 +++++++++++++++++++++++ cli/ranger/rc.conf | 1 + 2 files changed, 24 insertions(+) diff --git a/cli/ranger/commands.py b/cli/ranger/commands.py index 7246315..199c42e 100644 --- a/cli/ranger/commands.py +++ b/cli/ranger/commands.py @@ -170,3 +170,26 @@ class fzf_edit(Command): if fzf.returncode == 0: fzf_file = os.path.abspath(stdout.rstrip('\n')) self.fm.edit_file(fzf_file) + + +class mediacut_open(Command): + def execute(self): + """ play all files in current dir """ + thisfile = self.fm.thisfile + if thisfile.filetype.startswith('inode/directory'): + files = [file.path for file in thisfile.files if file.filetype.startswith('video')] + else: + files = [thisfile.path] + descr = "mediacut open" + obj = CommandLoader( + args=[ + 'mpv', + '--no-resume-playback', + '--start=0', + '--osd-fractions', + '--osd-level=3' + ] + files, + descr=descr, + read=False, + ) + self.fm.loader.add(obj) diff --git a/cli/ranger/rc.conf b/cli/ranger/rc.conf index 5e63213..c43876d 100644 --- a/cli/ranger/rc.conf +++ b/cli/ranger/rc.conf @@ -8,3 +8,4 @@ set vcs_aware true map \cg eval import subprocess;fm.cd(subprocess.getoutput('git rev-parse --show-toplevel')) map fzf_select map fzf_edit +map oo mediacut_open