Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,9 @@ import json
|
|
5 |
from rembg import remove as rm
|
6 |
import cv2
|
7 |
import uuid
|
|
|
|
|
|
|
8 |
uid=uuid.uuid4()
|
9 |
if not os.path.exists(f'{uid}-frames'): os.makedirs(f'{uid}-frames')
|
10 |
if not os.path.exists(f'{uid}-rembg'): os.makedirs(f'{uid}-rembg')
|
@@ -133,13 +136,34 @@ def dl(inp):
|
|
133 |
print (e)
|
134 |
out = None
|
135 |
return out,out,out,out
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
new_video_in = str(vid)
|
138 |
capture = cv2.VideoCapture(new_video_in)
|
139 |
frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
140 |
fps = capture.get(cv2.CAP_PROP_FPS)
|
141 |
fbox3=[]
|
142 |
frame_count1= int(frame_count)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
for i in range(int(frame_count1)):
|
144 |
capture.set(cv2.CAP_PROP_POS_FRAMES, i)
|
145 |
ret, frame_f = capture.read(i)
|
@@ -169,8 +193,8 @@ with gr.Blocks() as app:
|
|
169 |
outp_file=gr.Files()
|
170 |
with gr.Tab("Trim"):
|
171 |
with gr.Row():
|
172 |
-
start_f=gr.
|
173 |
-
end_f=gr.
|
174 |
trim_btn=gr.Button("Trim")
|
175 |
with gr.Row():
|
176 |
in_trim = gr.Video()
|
@@ -196,8 +220,13 @@ with gr.Blocks() as app:
|
|
196 |
text_input=gr.Textbox()
|
197 |
text_output=gr.Textbox()
|
198 |
url_params=gr.JSON()
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
201 |
outp_vid.change(load_video,outp_vid,[frame_count,fps])
|
202 |
frame_btn.click(capture_function,[outp_vid],[frame_gal,frame_file])
|
203 |
rem_btn.click(rem_bg,[outp_vid],[rem_vid,frame_num])
|
|
|
5 |
from rembg import remove as rm
|
6 |
import cv2
|
7 |
import uuid
|
8 |
+
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
|
9 |
+
|
10 |
+
|
11 |
uid=uuid.uuid4()
|
12 |
if not os.path.exists(f'{uid}-frames'): os.makedirs(f'{uid}-frames')
|
13 |
if not os.path.exists(f'{uid}-rembg'): os.makedirs(f'{uid}-rembg')
|
|
|
136 |
print (e)
|
137 |
out = None
|
138 |
return out,out,out,out
|
139 |
+
|
140 |
+
def trim_vid(vid,start_time,end_time):
|
141 |
+
start_hr=int(start_time.split(":",2)[0])*360
|
142 |
+
start_min=int(start_time.split(":",2)[1])*60
|
143 |
+
start_sec=int(start_time.split(":",2)[2])
|
144 |
+
end_hr=int(end_time.split(":",2)[0])*360
|
145 |
+
end_min=int(end_time.split(":",2)[1])*60
|
146 |
+
end_sec=int(end_time.split(":",2)[2])
|
147 |
+
start=start_hr+start_min+start_sec
|
148 |
+
end=end_hr+end_min+end_sec
|
149 |
+
#vid = f"{uid}-tmp.mp4"
|
150 |
+
ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
|
151 |
+
return f"{uid}-clip.mp4"
|
152 |
+
|
153 |
+
def other():
|
154 |
new_video_in = str(vid)
|
155 |
capture = cv2.VideoCapture(new_video_in)
|
156 |
frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
157 |
fps = capture.get(cv2.CAP_PROP_FPS)
|
158 |
fbox3=[]
|
159 |
frame_count1= int(frame_count)
|
160 |
+
|
161 |
+
start = (int(fps*int(start_f)))
|
162 |
+
|
163 |
+
capture.set(cv2.CAP_PROP_POS_FRAMES, i-1)
|
164 |
+
|
165 |
+
|
166 |
+
|
167 |
for i in range(int(frame_count1)):
|
168 |
capture.set(cv2.CAP_PROP_POS_FRAMES, i)
|
169 |
ret, frame_f = capture.read(i)
|
|
|
193 |
outp_file=gr.Files()
|
194 |
with gr.Tab("Trim"):
|
195 |
with gr.Row():
|
196 |
+
start_f = gr.Textbox(label = "Start", value = "0:00:00", placeholder = "0:00:23")
|
197 |
+
end_f = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54")
|
198 |
trim_btn=gr.Button("Trim")
|
199 |
with gr.Row():
|
200 |
in_trim = gr.Video()
|
|
|
220 |
text_input=gr.Textbox()
|
221 |
text_output=gr.Textbox()
|
222 |
url_params=gr.JSON()
|
223 |
+
|
224 |
+
def echo_fn(inp):
|
225 |
+
return inp
|
226 |
+
|
227 |
+
in_trim.change(echo_fn,in_trim,out_trim)
|
228 |
+
trim_btn.click(trim_vid,[in_trim,start_f,end_f],out_trim)
|
229 |
+
|
230 |
outp_vid.change(load_video,outp_vid,[frame_count,fps])
|
231 |
frame_btn.click(capture_function,[outp_vid],[frame_gal,frame_file])
|
232 |
rem_btn.click(rem_bg,[outp_vid],[rem_vid,frame_num])
|