Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -133,19 +133,18 @@ def dl(inp):
|
|
| 133 |
out = None
|
| 134 |
return out,out,out,out,out
|
| 135 |
|
| 136 |
-
def trim_vid(vid,start_time,end_time
|
| 137 |
print (vid)
|
| 138 |
start_hr=int(start_time.split(":",2)[0])*360
|
| 139 |
start_min=int(start_time.split(":",2)[1])*60
|
| 140 |
-
start_sec=
|
| 141 |
end_hr=int(end_time.split(":",2)[0])*360
|
| 142 |
end_min=int(end_time.split(":",2)[1])*60
|
| 143 |
-
end_sec=
|
| 144 |
start=start_hr+start_min+start_sec
|
| 145 |
end=end_hr+end_min+end_sec
|
| 146 |
#vid = f"{inp_out}.mp4"
|
| 147 |
ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
|
| 148 |
-
final = clip.fx( vfx.speedx, float(clip_speed))
|
| 149 |
out= f"{uid}-clip.mp4"
|
| 150 |
capture = cv2.VideoCapture(out)
|
| 151 |
frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
@@ -176,8 +175,13 @@ def make_gif():
|
|
| 176 |
clip = VideoFileClip(f"{uid}-clip.mp4")
|
| 177 |
clip.write_gif(f"{uid}/clip_gif.gif")
|
| 178 |
out = f"{uid}/clip_gif.gif"
|
| 179 |
-
return out,out
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
with gr.Blocks() as app:
|
| 182 |
with gr.Tab("Load"):
|
| 183 |
with gr.Row():
|
|
@@ -190,11 +194,12 @@ with gr.Blocks() as app:
|
|
| 190 |
frame_count=gr.Textbox(label="Frame Count",interactive = False)
|
| 191 |
fps=gr.Textbox(label="FPS",interactive = False)
|
| 192 |
outp_file=gr.Files()
|
|
|
|
|
|
|
| 193 |
with gr.Row():
|
| 194 |
start_f = gr.Textbox(label = "Start", value = "0:00:00", placeholder = "0:00:23",interactive = True)
|
| 195 |
end_f = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54",interactive = True)
|
| 196 |
trim_count = gr.Textbox(label="Trimmed Frames")
|
| 197 |
-
clip_speed = gr.Slider(label="Speed", min=0.1, max=2, value=1, step=0.1)
|
| 198 |
trim_btn=gr.Button("Trim")
|
| 199 |
out_trim=gr.Video(format="mp4")
|
| 200 |
hid_box = gr.Textbox(visible=True)
|
|
@@ -239,8 +244,9 @@ with gr.Blocks() as app:
|
|
| 239 |
def echo_fn(inp):
|
| 240 |
return inp
|
| 241 |
#outp_vid.change(echo_fn,outp_vid,[out_trim])
|
|
|
|
| 242 |
gif_btn.click(make_gif,None,[gif_show,gif_file])
|
| 243 |
-
trim_btn.click(trim_vid,[hid_box,start_f,end_f
|
| 244 |
outp_vid.change(load_video,outp_vid,[frame_count,fps,end_f]).then(trim_vid,[hid_box,start_f,end_f],[out_trim,in_vid,trim_count])
|
| 245 |
frame_btn.click(capture_function,[out_trim],[frame_gal,frame_file,frame_stat])
|
| 246 |
rem_btn.click(rem_bg,[out_trim],[rem_vid,frame_num,rem_bg_vid])
|
|
|
|
| 133 |
out = None
|
| 134 |
return out,out,out,out,out
|
| 135 |
|
| 136 |
+
def trim_vid(vid,start_time,end_time):
|
| 137 |
print (vid)
|
| 138 |
start_hr=int(start_time.split(":",2)[0])*360
|
| 139 |
start_min=int(start_time.split(":",2)[1])*60
|
| 140 |
+
start_sec=int(start_time.split(":",2)[2])
|
| 141 |
end_hr=int(end_time.split(":",2)[0])*360
|
| 142 |
end_min=int(end_time.split(":",2)[1])*60
|
| 143 |
+
end_sec=int(end_time.split(":",2)[2])
|
| 144 |
start=start_hr+start_min+start_sec
|
| 145 |
end=end_hr+end_min+end_sec
|
| 146 |
#vid = f"{inp_out}.mp4"
|
| 147 |
ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
|
|
|
|
| 148 |
out= f"{uid}-clip.mp4"
|
| 149 |
capture = cv2.VideoCapture(out)
|
| 150 |
frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
|
| 175 |
clip = VideoFileClip(f"{uid}-clip.mp4")
|
| 176 |
clip.write_gif(f"{uid}/clip_gif.gif")
|
| 177 |
out = f"{uid}/clip_gif.gif"
|
|
|
|
| 178 |
|
| 179 |
+
return out,out
|
| 180 |
+
def update_speed(inp,clip_speed):
|
| 181 |
+
clip = VideoFileClip(inp)
|
| 182 |
+
final = clip.fx( vfx.speedx, float(clip_speed))
|
| 183 |
+
final.write_videofile(f'{inp}')
|
| 184 |
+
return f'{inp}'
|
| 185 |
with gr.Blocks() as app:
|
| 186 |
with gr.Tab("Load"):
|
| 187 |
with gr.Row():
|
|
|
|
| 194 |
frame_count=gr.Textbox(label="Frame Count",interactive = False)
|
| 195 |
fps=gr.Textbox(label="FPS",interactive = False)
|
| 196 |
outp_file=gr.Files()
|
| 197 |
+
clip_speed = gr.Slider(label="Speed", min=0.01, max=2, value=1, step=0.01)
|
| 198 |
+
speed_btn = gr.Button("Update Speed")
|
| 199 |
with gr.Row():
|
| 200 |
start_f = gr.Textbox(label = "Start", value = "0:00:00", placeholder = "0:00:23",interactive = True)
|
| 201 |
end_f = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54",interactive = True)
|
| 202 |
trim_count = gr.Textbox(label="Trimmed Frames")
|
|
|
|
| 203 |
trim_btn=gr.Button("Trim")
|
| 204 |
out_trim=gr.Video(format="mp4")
|
| 205 |
hid_box = gr.Textbox(visible=True)
|
|
|
|
| 244 |
def echo_fn(inp):
|
| 245 |
return inp
|
| 246 |
#outp_vid.change(echo_fn,outp_vid,[out_trim])
|
| 247 |
+
speed_btn.click(update_speed,[hid_box,clip_speed],outp_vid)
|
| 248 |
gif_btn.click(make_gif,None,[gif_show,gif_file])
|
| 249 |
+
trim_btn.click(trim_vid,[hid_box,start_f,end_f],[out_trim,in_vid,trim_count])
|
| 250 |
outp_vid.change(load_video,outp_vid,[frame_count,fps,end_f]).then(trim_vid,[hid_box,start_f,end_f],[out_trim,in_vid,trim_count])
|
| 251 |
frame_btn.click(capture_function,[out_trim],[frame_gal,frame_file,frame_stat])
|
| 252 |
rem_btn.click(rem_bg,[out_trim],[rem_vid,frame_num,rem_bg_vid])
|