-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_rag.lua
269 lines (181 loc) · 6.65 KB
/
video_rag.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
--[[
Copyright (C) 2024 Intel Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
SPDX-License-Identifier: MIT ]]
text = nil
uri = nil
function descriptor()
return {
title = "Video Retrieval",
version = "0.1",
author = "Your Name",
capabilities = {}
}
end
function activate()
vlc.msg.info("Video Retrieval")
dlg = vlc.dialog("Video Retrieval")
button_play = dlg:add_button("Search", click_play, 1, 8, 8, 1)
video_path_label = dlg:add_label("<b>Video Path</b>", 1, 1, 4, 1)
-- Optional: modify your videos path below. If not modify it from the VLC extension GUI
label = dlg:add_text_input("C:\\Users\\LNL\\Videos\\Source_Video", 1, 2, 10, 1)
input_label = dlg:add_label("<b>Prompt</b>",1, 3, 4, 1)
input = dlg:add_text_input(text,1, 4, 10, 1)
dlg:show()
end
function deactivate()
vlc.msg.info("Video Rag deactivated")
--stop_periodic_task()
-- Clean up resources here
end
function test_server(uri,message)
vlc.msg.info("In test server")
-- Modify this line to be the same as line 10 of client_RAG.py
local script_path = debug.getinfo(1, "S").source:sub(2)
local script_dir = string.match(script_path, "(.*\\)")
local python_script = script_dir .."client_RAG.py "
local final_path = string.gsub(python_script, '\\','/')
local user_data_dir = vlc.config.userdatadir()
local file = user_data_dir .. "\\cache_test.txt"
os.remove(file)
vlc.msg.info(file)
-- Modify this line to be the path to client_RAG.py
local command =string.format('pythonw "%s" "%s" "%s"',final_path, uri,message)
vlc.msg.info(command)
local handle = io.popen(command)
vlc.keep_alive()
while true do
vlc.keep_alive()
--vlc.msg.info("In keep alive")
local f = io.open(file, "rb")
if f then
vlc.msg.info("Got result")
f:close()
break
end
end
local result = handle:read("*a")
handle:close()
-- local result = os.execute(command)
if result then
vlc.msg.info("python script executed" .. result)
else
vlc.msg.err("python script Failed")
end
return result
end
function video_path()
local media = vlc.input.item()
--local player = vlc.object.input()
-- Check if media exists
if media then
-- Get the path of the media
local media_path = vlc.strings.decode_uri(media:uri())
vlc.msg.info("Playing item directly path: " .. media:uri())
uri = string.gsub(media_path, '^file:///','')
uri = string.gsub(uri, '/','\\')
-- Display the path
vlc.msg.info("Playing item path: " .. uri)
--local time = vlc.input.get_position()
vlc.msg.info("Playing item status 1" .. vlc.playlist.status())
if vlc.playlist.status() == "playing" then
vlc.playlist.pause()
end
vlc.msg.info("Playing item status 2" .. vlc.playlist.status())
end
return uri
end
function seek_by_frame(frame_number)
--local frame_number = 1950 --tonumber(frame_input:get_text())
if not frame_number then
vlc.msg.warn("Invalid time!")
return
end
local item = vlc.input.item()
if not item then
vlc.msg.warn("No video currently playing!")
return
end
local player = vlc.object.input()
--local time_in_seconds = frame_number / fps
local time_in_seconds = frame_number
vlc.msg.info("time_in_seconds" .. time_in_seconds .. " seconds)")
--local tms = 160
vlc.var.set(player,"time",tonumber(time_in_seconds)*1000000) --String2time(time_in_seconds))
vlc.playlist.play()
--end
vlc.msg.info("Seeking to frame " .. frame_number .. " (" .. time_in_seconds .. " seconds)")
end
function video_by_path(video_file)
if video_file and video_file ~= "" then
--vlc.strings.make_uri( video_file )
-- local url = "file:///d:/VisiualRag/vlc_video_rag/Happyness/video/Happyness_32_160_170.mp4"
video_file = string.gsub(video_file, "[\r\n]", "")
local v = {}
local i = 1
sep = "%s"
for str in string.gmatch(video_file, "([^"..sep.."]+)") do
v[i] = str
i = i + 1
end
frame_number = v[2]
vlc.msg.info("Timestamp: " .. frame_number)
vlc.playlist.clear()
vlc.playlist.add({{ path = v[1] }})
vlc.playlist.play()
vlc.msg.info("Playing video: " .. v[1])
local item = vlc.input.item()
while true do
local item = vlc.input.item()
if item then
break
end
end
local player = vlc.object.input()
local time_in_seconds = frame_number
--local tms = 160
vlc.var.set(player,"time",tonumber(time_in_seconds)*1000000) --String2time(time_in_seconds))
vlc.msg.info("time_in_seconds" .. time_in_seconds .. " seconds)")
--vlc.playlist.play()
--end
vlc.msg.info("Seeking to frame " .. frame_number .. " (" .. time_in_seconds .. " seconds)")
--seek_by_frame(v[2])
--vlc.playlist.play()
else
vlc.msg.warn("No path specified")
end
end
function click_play()
local media = vlc.input.item()
if media then
uri = video_path()
dlg:del_widget(label)
label = dlg:add_text_input(uri, 1, 2, 10, 1)
dlg:update()
else
local video_folder = label:get_text()
uri = video_folder
end
local message = input:get_text() --"Hello LUA"
local response = test_server(uri,message) --send_to_python_server(message)
vlc.msg.info("Python Server Response: " .. response)
if media then
seek_by_frame(response)
else
video_by_path(response)
end
end