Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ def do_interpolation(frame1, frame2, interpolation):
|
|
| 38 |
mediapy.write_video(f"{frame1}_to_{frame2}_out.mp4", frames, fps=25)
|
| 39 |
return f"{frame1}_to_{frame2}_out.mp4"
|
| 40 |
|
| 41 |
-
def get_frames(video_in, step, name):
|
| 42 |
frames = []
|
| 43 |
cap = cv2.VideoCapture(video_in)
|
| 44 |
cframes = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
@@ -70,6 +70,7 @@ def get_frames(video_in, step, name):
|
|
| 70 |
ret, frame = cap.read()
|
| 71 |
if ret == False:
|
| 72 |
break
|
|
|
|
| 73 |
cv2.imwrite(f"{name}_{step}{str(i)}.jpg",frame)
|
| 74 |
frames.append(f"{name}_{step}{str(i)}.jpg")
|
| 75 |
i+=1
|
|
@@ -89,11 +90,11 @@ def create_video(frames, fps, type):
|
|
| 89 |
return type + "_result.mp4"
|
| 90 |
|
| 91 |
|
| 92 |
-
def infer(url_in,interpolation,fps_output):
|
| 93 |
|
| 94 |
fps_output = logscale(fps_output)
|
| 95 |
# 1. break video into frames and get FPS
|
| 96 |
-
break_vid = get_frames(url_in, "vid_input_frame", "origin")
|
| 97 |
frames_list= break_vid[0]
|
| 98 |
fps = break_vid[1]
|
| 99 |
print(f"ORIGIN FPS: {fps}")
|
|
@@ -191,6 +192,7 @@ with gr.Blocks() as demo:
|
|
| 191 |
with gr.Row():
|
| 192 |
with gr.Column():
|
| 193 |
url_input = gr.Textbox(value="./examples/streetview.mp4", label="URL")
|
|
|
|
| 194 |
with gr.Row():
|
| 195 |
interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")
|
| 196 |
interpolation = gr.Label(value=2, show_label=False)
|
|
@@ -209,11 +211,11 @@ with gr.Blocks() as demo:
|
|
| 209 |
gr.Examples(
|
| 210 |
examples=[["./examples/streetview.mp4", 1, 1]],
|
| 211 |
fn=infer,
|
| 212 |
-
inputs=[url_input,interpolation_slider,fps_output_slider],
|
| 213 |
outputs=[video_output,file_output,depth_output],
|
| 214 |
cache_examples=True
|
| 215 |
)
|
| 216 |
|
| 217 |
-
submit_btn.click(fn=infer, inputs=[url_input,interpolation_slider,fps_output_slider], outputs=[video_output, file_output, depth_output])
|
| 218 |
|
| 219 |
demo.launch()
|
|
|
|
| 38 |
mediapy.write_video(f"{frame1}_to_{frame2}_out.mp4", frames, fps=25)
|
| 39 |
return f"{frame1}_to_{frame2}_out.mp4"
|
| 40 |
|
| 41 |
+
def get_frames(video_in, step, name, resize):
|
| 42 |
frames = []
|
| 43 |
cap = cv2.VideoCapture(video_in)
|
| 44 |
cframes = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
|
| 70 |
ret, frame = cap.read()
|
| 71 |
if ret == False:
|
| 72 |
break
|
| 73 |
+
frame = cv2.resize(frame, (int(resize), int(resize/2)))
|
| 74 |
cv2.imwrite(f"{name}_{step}{str(i)}.jpg",frame)
|
| 75 |
frames.append(f"{name}_{step}{str(i)}.jpg")
|
| 76 |
i+=1
|
|
|
|
| 90 |
return type + "_result.mp4"
|
| 91 |
|
| 92 |
|
| 93 |
+
def infer(url_in,interpolation,resize,fps_output):
|
| 94 |
|
| 95 |
fps_output = logscale(fps_output)
|
| 96 |
# 1. break video into frames and get FPS
|
| 97 |
+
break_vid = get_frames(url_in, "vid_input_frame", "origin", resize)
|
| 98 |
frames_list= break_vid[0]
|
| 99 |
fps = break_vid[1]
|
| 100 |
print(f"ORIGIN FPS: {fps}")
|
|
|
|
| 192 |
with gr.Row():
|
| 193 |
with gr.Column():
|
| 194 |
url_input = gr.Textbox(value="./examples/streetview.mp4", label="URL")
|
| 195 |
+
resize_num = gr.Number(value=256, label="Resize to width: ")
|
| 196 |
with gr.Row():
|
| 197 |
interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")
|
| 198 |
interpolation = gr.Label(value=2, show_label=False)
|
|
|
|
| 211 |
gr.Examples(
|
| 212 |
examples=[["./examples/streetview.mp4", 1, 1]],
|
| 213 |
fn=infer,
|
| 214 |
+
inputs=[url_input,interpolation_slider,resize_num,fps_output_slider],
|
| 215 |
outputs=[video_output,file_output,depth_output],
|
| 216 |
cache_examples=True
|
| 217 |
)
|
| 218 |
|
| 219 |
+
submit_btn.click(fn=infer, inputs=[url_input,interpolation_slider,resize_num,fps_output_slider], outputs=[video_output, file_output, depth_output])
|
| 220 |
|
| 221 |
demo.launch()
|