Update app.py
Browse files
app.py
CHANGED
@@ -37,7 +37,7 @@ def do_interpolation(frame1, frame2, interpolation, n):
|
|
37 |
mediapy.write_video(f"{n}_to_{n+1}_out.mp4", frames, fps=25)
|
38 |
return f"{n}_to_{n+1}_out.mp4"
|
39 |
|
40 |
-
def get_frames(video_in, step, name
|
41 |
frames = []
|
42 |
cap = cv2.VideoCapture(video_in)
|
43 |
cframes = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
@@ -69,9 +69,9 @@ def get_frames(video_in, step, name, resize_w):
|
|
69 |
ret, frame = cap.read()
|
70 |
if ret == False:
|
71 |
break
|
72 |
-
if resize_w > 0:
|
73 |
-
resize_h = resize_w / 2.0
|
74 |
-
frame = cv2.resize(frame, (int(resize_w), int(resize_h)))
|
75 |
|
76 |
cv2.imwrite(f"{name}_{step}{str(i)}.png",frame)
|
77 |
frames.append(f"{name}_{step}{str(i)}.png")
|
@@ -92,6 +92,15 @@ def create_video(frames, fps, type):
|
|
92 |
|
93 |
mediapy.write_video(type + "_result.mp4", imgs, fps=fps)
|
94 |
return type + "_result.mp4"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
|
97 |
def infer(f_in, interpolation, fps_output):
|
@@ -117,6 +126,11 @@ def infer(f_in, interpolation, fps_output):
|
|
117 |
if idx < len(frames_list) - 1:
|
118 |
next_frame = frames_list[idx+1]
|
119 |
|
|
|
|
|
|
|
|
|
|
|
120 |
interpolated_frames = do_interpolation(frame, next_frame, interpolation, idx) # should return a list of interpolated frames
|
121 |
break_interpolated_video = get_frames(interpolated_frames, "interpol", f"{idx}_", 0)
|
122 |
print(break_interpolated_video[0])
|
@@ -182,7 +196,7 @@ with gr.Blocks() as demo:
|
|
182 |
with gr.Row():
|
183 |
with gr.Column():
|
184 |
with gr.Accordion(label="Upload files here", open=True):
|
185 |
-
files_input = gr.File(file_count="multiple", file_types=['image'])
|
186 |
gallery_input = gr.Gallery(label="Slideshow", preview=True, columns=8192, interactive=False)
|
187 |
files_input.change(fn=loadf, inputs=[files_input], outputs=[files_input, gallery_input])
|
188 |
with gr.Row():
|
|
|
37 |
mediapy.write_video(f"{n}_to_{n+1}_out.mp4", frames, fps=25)
|
38 |
return f"{n}_to_{n+1}_out.mp4"
|
39 |
|
40 |
+
def get_frames(video_in, step, name):
|
41 |
frames = []
|
42 |
cap = cv2.VideoCapture(video_in)
|
43 |
cframes = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
69 |
ret, frame = cap.read()
|
70 |
if ret == False:
|
71 |
break
|
72 |
+
#if resize_w > 0:
|
73 |
+
#resize_h = resize_w / 2.0
|
74 |
+
#frame = cv2.resize(frame, (int(resize_w), int(resize_h)))
|
75 |
|
76 |
cv2.imwrite(f"{name}_{step}{str(i)}.png",frame)
|
77 |
frames.append(f"{name}_{step}{str(i)}.png")
|
|
|
92 |
|
93 |
mediapy.write_video(type + "_result.mp4", imgs, fps=fps)
|
94 |
return type + "_result.mp4"
|
95 |
+
|
96 |
+
|
97 |
+
def sharpest(f):
|
98 |
+
break_vid = get_frames(f, "vid_input_frame", "origin")
|
99 |
+
blur_s = []
|
100 |
+
for jdx, fr in enumerate(break_vid[0]):
|
101 |
+
blur_s.append(cv2.Laplacian(cv2.cvtColor(cv2.imread(fr).astype(np.uint8), cv2.COLOR_BGR2GRAY), cv2.CV_64F).var())
|
102 |
+
|
103 |
+
return break_vid[0][np.argmax(blur_s)]
|
104 |
|
105 |
|
106 |
def infer(f_in, interpolation, fps_output):
|
|
|
126 |
if idx < len(frames_list) - 1:
|
127 |
next_frame = frames_list[idx+1]
|
128 |
|
129 |
+
ftype = frame.split('/')
|
130 |
+
if ftype[len(ftype)-1].split('.')[1] == 'mp4':
|
131 |
+
frame = sharpest(frame)
|
132 |
+
next_frame = sharpest(next_frame)
|
133 |
+
|
134 |
interpolated_frames = do_interpolation(frame, next_frame, interpolation, idx) # should return a list of interpolated frames
|
135 |
break_interpolated_video = get_frames(interpolated_frames, "interpol", f"{idx}_", 0)
|
136 |
print(break_interpolated_video[0])
|
|
|
196 |
with gr.Row():
|
197 |
with gr.Column():
|
198 |
with gr.Accordion(label="Upload files here", open=True):
|
199 |
+
files_input = gr.File(file_count="multiple", file_types=['image', '.mp4'])
|
200 |
gallery_input = gr.Gallery(label="Slideshow", preview=True, columns=8192, interactive=False)
|
201 |
files_input.change(fn=loadf, inputs=[files_input], outputs=[files_input, gallery_input])
|
202 |
with gr.Row():
|