Spaces:
Runtime error
Runtime error
ercanburak
commited on
Commit
•
b0547a1
1
Parent(s):
980d227
commit wip
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import subprocess
|
|
3 |
|
4 |
import streamlit as st
|
5 |
|
6 |
-
from utils import get_configs, get_display_names, get_path_for_viz, Layout
|
7 |
|
8 |
# st.header("EVREAL - Event-based Video Reconstruction Evaluation and Analysis Library")
|
9 |
#
|
@@ -78,7 +78,7 @@ model_only_viz = [viz for viz in selected_visualizations if viz['viz_type'] == '
|
|
78 |
both_viz = [viz for viz in selected_visualizations if viz['viz_type'] == 'both']
|
79 |
|
80 |
recon_viz = {"name": "recon", "display_name": "Reconstruction", "viz_type": "both", "gt_type": "frame"}
|
81 |
-
|
82 |
|
83 |
model_viz = [recon_viz] + both_viz + selected_metrics + model_only_viz
|
84 |
num_model_rows = len(model_viz)
|
@@ -99,45 +99,82 @@ gt_viz.extend([viz for viz in gt_only_viz if viz['gt_type'] == 'event'])
|
|
99 |
num_gt_rows = len(gt_viz)
|
100 |
num_rows = max(num_model_rows, num_gt_rows)
|
101 |
|
102 |
-
|
|
|
103 |
|
104 |
-
|
105 |
|
106 |
-
|
107 |
-
layout_str = layout.get_layout_str()
|
108 |
|
109 |
video_paths = []
|
|
|
110 |
for row_idx in range(num_rows):
|
111 |
-
for col_idx in range(
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
print(video_path)
|
115 |
video_paths.append(video_path)
|
116 |
-
# if os.path.isfile(video_path):
|
117 |
-
# video_paths.append(video_path)
|
118 |
-
# else:
|
119 |
-
# print("Video path does not exist: " + video_path)
|
120 |
-
#
|
121 |
-
# assert len(video_paths) == num_elements, "Number of video paths is not equal to expected number of elements"
|
122 |
|
123 |
-
inputs_str = " ".join(["-i " + video_path for video_path in video_paths])
|
|
|
124 |
|
125 |
crop_str = "crop=trunc(iw/2)*2:trunc(ih/2)*2"
|
126 |
pad_str = "pad=ceil(iw/2)*2+4:ceil(ih/2)*2+4:2:2"
|
127 |
|
|
|
|
|
128 |
w = selected_dataset["width"]
|
129 |
-
|
130 |
xstack_input_parts = []
|
|
|
131 |
for i in range(num_elements):
|
132 |
-
|
133 |
-
input_scaling_parts.append(input_scaling_part)
|
134 |
xstack_input_part = "[v{}]".format(i)
|
135 |
xstack_input_parts.append(xstack_input_part)
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
xstack_input_str = "".join(xstack_input_parts)
|
138 |
|
|
|
|
|
|
|
139 |
# opt = "-c:v libx264 -preset veryslow -crf 18 -c:a copy"
|
140 |
opt = ""
|
141 |
-
ffmpeg_command_str = "ffmpeg -y " + inputs_str + " -filter_complex \"" + input_scaling_str + ";" + xstack_input_str + "xstack=inputs=" + str(num_elements) + ":layout=" + layout_str + "\"" + opt + " output.mp4"
|
142 |
print(ffmpeg_command_str)
|
143 |
-
subprocess.call(ffmpeg_command_str, shell=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
import streamlit as st
|
5 |
|
6 |
+
from utils import get_configs, get_display_names, get_path_for_viz, Layout, get_video_height
|
7 |
|
8 |
# st.header("EVREAL - Event-based Video Reconstruction Evaluation and Analysis Library")
|
9 |
#
|
|
|
78 |
both_viz = [viz for viz in selected_visualizations if viz['viz_type'] == 'both']
|
79 |
|
80 |
recon_viz = {"name": "recon", "display_name": "Reconstruction", "viz_type": "both", "gt_type": "frame"}
|
81 |
+
ground_truth = {"name": "gt", "display_name": "Ground Truth", "model_id": "groundtruth"}
|
82 |
|
83 |
model_viz = [recon_viz] + both_viz + selected_metrics + model_only_viz
|
84 |
num_model_rows = len(model_viz)
|
|
|
99 |
num_gt_rows = len(gt_viz)
|
100 |
num_rows = max(num_model_rows, num_gt_rows)
|
101 |
|
102 |
+
if len(gt_viz) > 0:
|
103 |
+
selected_models.append(ground_truth)
|
104 |
|
105 |
+
num_cols = len(selected_models)
|
106 |
|
107 |
+
num_elements = num_rows * num_cols
|
|
|
108 |
|
109 |
video_paths = []
|
110 |
+
row_heights = [0]*num_rows
|
111 |
for row_idx in range(num_rows):
|
112 |
+
for col_idx in range(num_cols):
|
113 |
+
cur_model = selected_models[col_idx]
|
114 |
+
if cur_model['name'] == "gt":
|
115 |
+
if row_idx >= len(gt_viz):
|
116 |
+
video_path = ""
|
117 |
+
else:
|
118 |
+
video_path = get_path_for_viz(data_base_path, selected_dataset, selected_sequence, cur_model, gt_viz[row_idx])
|
119 |
+
# if not os.path.isfile(video_path):
|
120 |
+
# raise ValueError("Video path does not exist: " + video_path)
|
121 |
+
else:
|
122 |
+
if row_idx >= len(model_viz):
|
123 |
+
video_path = ""
|
124 |
+
else:
|
125 |
+
video_path = get_path_for_viz(data_base_path, selected_dataset, selected_sequence, cur_model, model_viz[row_idx])
|
126 |
+
# if not os.path.isfile(video_path):
|
127 |
+
# raise ValueError("Video path does not exist: " + video_path)
|
128 |
+
|
129 |
+
if video_path and row_heights[row_idx] == 0:
|
130 |
+
row_heights[row_idx] = get_video_height(video_path)
|
131 |
+
|
132 |
print(video_path)
|
133 |
video_paths.append(video_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
inputs_str = " ".join(["-i " + video_path for video_path in video_paths if video_path])
|
136 |
+
num_inputs = len(inputs_str.split("-i")) - 1
|
137 |
|
138 |
crop_str = "crop=trunc(iw/2)*2:trunc(ih/2)*2"
|
139 |
pad_str = "pad=ceil(iw/2)*2+4:ceil(ih/2)*2+4:2:2"
|
140 |
|
141 |
+
# empty_elem_str = "drawbox=t=fill:c=black,scale={}:{}[v{}]"
|
142 |
+
|
143 |
w = selected_dataset["width"]
|
144 |
+
input_filter_parts = []
|
145 |
xstack_input_parts = []
|
146 |
+
input_vid_no = 0
|
147 |
for i in range(num_elements):
|
148 |
+
row_idx = i // num_cols
|
|
|
149 |
xstack_input_part = "[v{}]".format(i)
|
150 |
xstack_input_parts.append(xstack_input_part)
|
151 |
+
if video_paths[i]:
|
152 |
+
input_filter_part = "[{}:v]".format(input_vid_no)
|
153 |
+
input_vid_no += 1
|
154 |
+
else:
|
155 |
+
input_filter_part = "color=c=black,"
|
156 |
+
input_filter_part = "[{}]drawbox=:w={}:h={}:color=black:t=fill,".format(num_inputs, w, row_heights[row_idx])
|
157 |
+
pass
|
158 |
+
input_filter_part = input_filter_part + "scale={}:-1,{}[v{}]".format(w, pad_str, i)
|
159 |
+
input_filter_parts.append(input_filter_part)
|
160 |
+
|
161 |
+
input_scaling_str = ";".join(input_filter_parts)
|
162 |
xstack_input_str = "".join(xstack_input_parts)
|
163 |
|
164 |
+
layout = Layout(num_rows, num_cols)
|
165 |
+
layout_str = layout.get_layout_str()
|
166 |
+
|
167 |
# opt = "-c:v libx264 -preset veryslow -crf 18 -c:a copy"
|
168 |
opt = ""
|
169 |
+
ffmpeg_command_str = "ffmpeg -y " + inputs_str + " -filter_complex \"" + input_scaling_str + ";" + xstack_input_str + "xstack=inputs=" + str(num_elements) + ":layout=" + layout_str + ":fill=black\"" + opt + " output.mp4"
|
170 |
print(ffmpeg_command_str)
|
171 |
+
ret = subprocess.call(ffmpeg_command_str, shell=True)
|
172 |
+
|
173 |
+
if ret != 0:
|
174 |
+
st.error("Error while generating video.")
|
175 |
+
st.stop()
|
176 |
+
|
177 |
+
video_file = open('output.mp4', 'rb')
|
178 |
+
video_bytes = video_file.read()
|
179 |
+
|
180 |
+
st.video(video_bytes)
|
utils.py
CHANGED
@@ -3,6 +3,7 @@ import glob
|
|
3 |
import json
|
4 |
from pathlib import Path
|
5 |
from collections import OrderedDict
|
|
|
6 |
|
7 |
|
8 |
def read_json(fname):
|
@@ -71,3 +72,9 @@ class Layout:
|
|
71 |
layout_parts.append(layout_part)
|
72 |
layout_string = "|".join(layout_parts)
|
73 |
return layout_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import json
|
4 |
from pathlib import Path
|
5 |
from collections import OrderedDict
|
6 |
+
import ffmpeg
|
7 |
|
8 |
|
9 |
def read_json(fname):
|
|
|
72 |
layout_parts.append(layout_part)
|
73 |
layout_string = "|".join(layout_parts)
|
74 |
return layout_string
|
75 |
+
|
76 |
+
|
77 |
+
def get_video_height(video_path):
|
78 |
+
probe = ffmpeg.probe(video_path)
|
79 |
+
video_streams = ffmpeg.probe(video_path, select_streams="v")
|
80 |
+
return video_streams['streams'][0]['height']
|