-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimecode.lua
More file actions
174 lines (131 loc) · 4.09 KB
/
Copy pathtimecode.lua
File metadata and controls
174 lines (131 loc) · 4.09 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
local mp = require 'mp'
local fps_string = os.getenv("VIDEO_FPS") or "30/1"
local n, d = fps_string:match("(%d+)/(%d+)")
local fps
if n then
fps = tonumber(n) / tonumber(d)
else
fps = tonumber(fps_string)
end
if not fps then
fps = 30
end
local last_terminal = ""
local current_tc = ""
local current_frame = 0
local copy_message = nil
local copy_until = 0
------------------------------------------------------------
-- Sekunden -> HH:MM:SS:FF
------------------------------------------------------------
local function tc(sec)
local h = math.floor(sec / 3600)
local m = math.floor((sec % 3600) / 60)
local s = math.floor(sec % 60)
local f = math.floor((sec - math.floor(sec)) * fps + 0.5)
if f >= fps then
f = 0
end
return string.format("%02d:%02d:%02d:%02d", h, m, s, f)
end
------------------------------------------------------------
-- Timecode kopieren
------------------------------------------------------------
local function copy_to_clipboard(text)
local cmd
if os.getenv("WAYLAND_DISPLAY") then
cmd = "wl-copy"
elseif os.getenv("DISPLAY") then
cmd = "xclip -selection clipboard"
elseif os.getenv("OSTYPE") == "darwin" or package.config:sub(1,1) == "/" then
cmd = "pbcopy"
else
cmd = "pbcopy"
end
local pipe = io.popen(cmd, "w")
if pipe then
pipe:write(text)
pipe:close()
end
end
local function copy_timecode()
local text = current_tc
copy_to_clipboard(text)
copy_message = "✓ Copied: " .. text
copy_until = mp.get_time() + 2.5
end
mp.add_key_binding("c", "copy-timecode", copy_timecode)
------------------------------------------------------------
-- Anzeige aktualisieren
------------------------------------------------------------
local function update()
local pos = mp.get_property_number("time-pos", 0)
local dur = mp.get_property_number("duration", 0)
local frame = math.floor(pos * fps + 0.5)
local total = math.floor(dur * fps + 0.5)
current_tc = tc(pos)
current_frame = frame
local paused = mp.get_property_native("pause")
local state = paused and "Stop" or "Play"
--------------------------------------------------------
-- Hauptanzeige
--------------------------------------------------------
local display = string.format(
"%s / %s",
tc(pos),
tc(dur)
)
--------------------------------------------------------
-- Kopiert-Meldung
--------------------------------------------------------
if copy_message and mp.get_time() < copy_until then
display = display ..
"\\N\\N{\\fs42}{\\1c&H00FF00&}" ..
copy_message ..
"{\\fs56}{\\1c&HFFFFFF&}"
else
copy_message = nil
end
--------------------------------------------------------
-- Fenstergröße
--------------------------------------------------------
local w = mp.get_property_number("osd-width", 1920)
local h = mp.get_property_number("osd-height", 1080)
--------------------------------------------------------
-- OSD oben mittig
--------------------------------------------------------
local ass = string.format(
"{\\an8}" ..
"{\\pos(%d,70)}" ..
"{\\fs56}" ..
"{\\bord3}" ..
"{\\1c&HFFFFFF&}" ..
"{\\3c&H000000&}" ..
"%s",
math.floor(w / 2),
display
)
mp.set_osd_ass(w, h, ass)
--------------------------------------------------------
-- Terminal
--------------------------------------------------------
local terminal = string.format(
"Time: %s / %s\nFrame: %d / %d\nFPS: %.3f\n%s",
tc(pos),
tc(dur),
frame,
total,
fps,
state
)
if terminal ~= last_terminal then
io.write("\27[H\27[2J")
io.write(terminal)
io.flush()
last_terminal = terminal
end
end
------------------------------------------------------------
-- 60 Aktualisierungen pro Sekunde
------------------------------------------------------------
mp.add_periodic_timer(1/60, update)