-
Notifications
You must be signed in to change notification settings - Fork 2
/
export_clip.lua
103 lines (93 loc) · 2.67 KB
/
export_clip.lua
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
utils = require "mp.utils"
-- test available filename
function slow_start()
local basename = mp.get_property("filename"):gsub("%.([^%.]+)$", "")
local screenshot_folder = mp.get_property("screenshot-directory") or ""
function filename(idx)
return utils.join_path(
screenshot_folder,
basename .. '-' .. string.format("%04d",idx) .. '.mp4'
)
end
-- multiply
local inc = 1
while utils.file_info(filename(inc)) do
inc = inc * 2
end
-- narrowing
local lower_bound = math.floor(inc / 2)
while inc - lower_bound > 1 do
local mid = math.floor((inc + lower_bound) / 2)
local is_file = utils.file_info(filename(mid))
if is_file then
lower_bound = mid
else
inc = mid
end
end
return filename(inc)
end
function export_loop_clip()
local a = mp.get_property_number("ab-loop-a")
local b = mp.get_property_number("ab-loop-b")
local path = mp.get_property("path")
if a and b then
local outfile = slow_start()
local cmd = {
"run",
"ffmpeg",
"-ss", tostring(a),
"-i", path,
"-t", tostring(b-a),
"-c:v", "libx264",
"-crf", "21",
"-preset:v", "placebo",
"-pix_fmt", "yuva420p",
"-filter_complex", "scale=iw*min(1\\,min(1280/iw\\,720/ih)):-2",
"-an", "-sn",
"-map_metadata", "-1",
"-v", "error",
"-n",
outfile
}
local args = { args = cmd }
function cb(success, result, error)
if success then
mp.msg.info("save clip " .. outfile)
mp.osd_message("save clip " .. outfile)
else
mp.msg.info(error)
mp.osd_message("export loop clip error: " .. error)
end
end
mp.command_native_async(cmd, cb)
end
end
mp.register_script_message("export-loop-clip", export_loop_clip)
function set_ab_loop_a()
local pos = mp.get_property_number("time-pos")
local a = mp.get_property_number("ab-loop-a")
mp.set_property_number("ab-loop-a", pos)
mp.osd_message('set A-B loop A: ' .. tostring(pos))
end
mp.register_script_message("set-ab-loop-a", set_ab_loop_a)
function set_ab_loop_b()
local pos = mp.get_property_number("time-pos")
mp.set_property_number("ab-loop-b", pos)
mp.osd_message('set A-B loop B: ' .. tostring(pos))
end
mp.register_script_message("set-ab-loop-b", set_ab_loop_b)
function seek_ab_loop_a()
local pos = mp.get_property_number("ab-loop-a")
if pos then
mp.set_property_number("time-pos", pos)
end
end
mp.register_script_message("seek-ab-loop-a", seek_ab_loop_a)
function seek_ab_loop_b()
local pos = mp.get_property_number("ab-loop-b")
if pos then
mp.set_property_number("time-pos", pos)
end
end
mp.register_script_message("seek-ab-loop-b", seek_ab_loop_b)