[bugfix] add copyCutCmd
This commit is contained in:
parent
bd40bc1725
commit
7ef32384a7
61
gui/mpv/scripts/cut.js
Normal file
61
gui/mpv/scripts/cut.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
var beginPos, endPos
|
||||
|
||||
function markBegin() {
|
||||
beginPos = mp.get_property('time-pos')
|
||||
mp.osd_message('Begin Position Marked at ' + beginPos)
|
||||
}
|
||||
|
||||
function markEnd() {
|
||||
endPos = mp.get_property('time-pos')
|
||||
mp.osd_message('End Position Marked at ' + endPos)
|
||||
}
|
||||
|
||||
function getMarked() {
|
||||
if (!beginPos && !endPos) {
|
||||
mp.osd_message('Please set Begin Position with Ctrl-b, End Position with Ctrl-e')
|
||||
return
|
||||
}
|
||||
var ss = beginPos || 0
|
||||
var t = endPos || mp.get_property('duration')
|
||||
var path = mp.get_property('path')
|
||||
var dir_file = mp.utils.split_path(path)
|
||||
return {
|
||||
dir: dir_file[0],
|
||||
file: dir_file[1],
|
||||
path: path,
|
||||
ss: ss,
|
||||
t: t
|
||||
}
|
||||
}
|
||||
|
||||
function outputMarked() {
|
||||
var m = getMarked()
|
||||
var output_dir = mp.utils.join_path(m.dir, 'clips')
|
||||
mp.utils.subprocess({
|
||||
args: ['mkdir', '-p', output_dir],
|
||||
cancellable: false
|
||||
})
|
||||
output_file = mp.utils.join_path(output_dir, m.file)
|
||||
mp.utils.subprocess({
|
||||
args: ['ffmpeg', '-ss', ss, '-i', m.path, '-t', t, '-c', 'copy', output_file],
|
||||
cancellable: false
|
||||
})
|
||||
mp.osd_message('Clip save to ' + output_file)
|
||||
}
|
||||
|
||||
function copyCutCmd() {
|
||||
var m = getMarked()
|
||||
var cmd = 'ffmpeg -ss ' + m.ss + ' -i ' + "'" + m.file + "' -t " + m.t + " -c copy '"+m.file + "-" + (Math.floor(m.ss/60)) +"'"
|
||||
mp.utils.subprocess({
|
||||
args: ['powershell', '-NoProfile', '-Command', 'Set-Clipboard "'+cmd+'"'],
|
||||
cancellable: false
|
||||
})
|
||||
mp.osd_message("command has been copied to your clipboard")
|
||||
}
|
||||
|
||||
|
||||
|
||||
mp.add_key_binding("ctrl+b", "mark_begin", markBegin);
|
||||
mp.add_key_binding("ctrl+e", "mark_end", markEnd);
|
||||
mp.add_key_binding("ctrl+o", "output_marked", outputMarked);
|
||||
mp.add_key_binding("ctrl+shift+o", "copy_cut_cmd", copyCutCmd);
|
|
@ -1,38 +0,0 @@
|
|||
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', '-ss', tostring(ss), '-i', path, '-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);
|
Loading…
Reference in New Issue
Block a user