-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclip_cutter.lua
90 lines (79 loc) · 2.88 KB
/
clip_cutter.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
function descriptor()
return {
title = "Clip Cutter",
version = "1.1",
author = "dreamcatcher45",
capabilities = {"menu", "input-listener"}
}
end
function activate()
vlc.osd.message("Clip Cutter extension activated", vlc.osd.channel_register(), "center", 2000 * 1000)
end
function deactivate()
vlc.osd.message("Clip Cutter extension deactivated", vlc.osd.channel_register(), "center", 2000 * 1000)
end
function close()
deactivate()
end
clip_start=nil
clip_end=nil
function menu()
return {"Start Point", "End Point", "Save"}
end
function trigger_menu(id)
if id == 1 then
start_point()
elseif id == 2 then
end_point()
elseif id == 3 then
save_clip()
end
end
function millisecondsToTimestamp(milliseconds)
local seconds = milliseconds / 1000000
local hours = math.floor(seconds / 3600)
local minutes = math.floor((seconds % 3600) / 60)
local seconds = math.floor(seconds % 60)
local timestamp = string.format("%02d:%02d:%02d", hours, minutes, seconds)
return timestamp
end
function start_point()
local input_item = vlc.input.item()
if input_item then
local current_time = vlc.var.get(vlc.object.input(), "time")
local timestamp = millisecondsToTimestamp(current_time)
clip_start = timestamp
vlc.osd.message("Start point set", vlc.osd.channel_register(), "center", 2000 * 1000)
else
vlc.osd.message("No media found", vlc.osd.channel_register(), "center", 2000 * 1000)
end
end
function end_point()
local input_item = vlc.input.item()
if input_item then
local current_time = vlc.var.get(vlc.object.input(), "time")
local timestamp = millisecondsToTimestamp(current_time)
clip_end = timestamp
vlc.osd.message("End point set", vlc.osd.channel_register(), "center", 2000 * 1000)
else
vlc.osd.message("No media found", vlc.osd.channel_register(), "center", 2000 * 1000)
end
end
function save_clip()
local input_item = vlc.input.item()
if input_item then
local input_uri = input_item:uri()
local input_filename = vlc.strings.decode_uri(string.gsub(input_uri, "file:///", ""))
if clip_start and clip_end and clip_start < clip_end then
local output_filename = "output_" .. os.time() .. ".mkv"
local command = 'ffmpeg -i "' .. input_filename .. '" -ss ' .. clip_start .. ' -to ' .. clip_end .. ' -c copy "' .. output_filename .. '"'
os.execute(command)
vlc.osd.hide(ret)
vlc.osd.message("Video saved in current directory", vlc.osd.channel_register(), "center", 2000 * 1000)
else
vlc.osd.message("Please set valid start and end points", vlc.osd.channel_register(), "center", 2000 * 1000)
end
else
vlc.osd.message("No media found", vlc.osd.channel_register(), "center", 2000 * 1000)
end
end