1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
local mp = require("mp")
local cut_ab = function()
local a = mp.get_property_number("ab-loop-a")
local b = mp.get_property_number("ab-loop-b")
if a == nil or b == nil then
mp.msg.error("ab loop not set")
return
end
if a > b then
a, b = b, a
end
--- @type string
local path = mp.get_property("path")
local i = 1
local last_dot_idx = nil
while i <= #path do
if path:sub(i, i) == "." then
last_dot_idx = i
end
i = i + 1
end
if last_dot_idx == nil then
mp.msg.error("could not parse path: " .. path)
return
end
local target_path = path:sub(1, last_dot_idx) .. a .. "-" .. b .. path:sub(last_dot_idx, nil)
mp.commandv(
"run", "ffmpeg",
"-ss", a,
"-to", b,
"-i", path,
"-c", "copy",
target_path)
end
mp.add_key_binding("c", cut_ab)
|