Update inference_video.py
Browse files- inference_video.py +10 -25
inference_video.py
CHANGED
@@ -62,28 +62,13 @@ def inference_image(image, size):
|
|
62 |
return result
|
63 |
|
64 |
|
65 |
-
custom_name = "input.mp4"
|
66 |
-
|
67 |
-
def save_video_input(video, custom_name):
|
68 |
-
try:
|
69 |
-
# Specify the desired output file path with the custom name and ".mp4" extension
|
70 |
-
output_file_path = f"/tmp/videos/{custom_name}.mp4"
|
71 |
-
|
72 |
-
# Save the video input to the specified file path
|
73 |
-
with open(output_file_path, 'wb') as output_file:
|
74 |
-
output_file.write(video_input)
|
75 |
-
print(f"Video input saved as {output_file_path}")
|
76 |
-
except Exception as e:
|
77 |
-
print(f"Error saving video input: {str(e)}")
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
|
82 |
# assign directory
|
83 |
directory = 'videos' #PATH_WITH_INPUT_VIDEOS
|
84 |
zee = 0
|
85 |
|
86 |
def convert_frames_to_video(pathIn,pathOut,fps):
|
|
|
87 |
frame_array = []
|
88 |
files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
|
89 |
#for sorting the file names properly
|
@@ -123,8 +108,8 @@ for filename in os.listdir(directory):
|
|
123 |
try:
|
124 |
|
125 |
# PATH TO STORE VIDEO FRAMES
|
126 |
-
if not os.path.exists('/
|
127 |
-
os.makedirs('/
|
128 |
|
129 |
# if not created then raise error
|
130 |
except OSError:
|
@@ -141,7 +126,7 @@ for filename in os.listdir(directory):
|
|
141 |
|
142 |
if ret:
|
143 |
# if video is still left continue creating images
|
144 |
-
name = '/
|
145 |
|
146 |
# writing the extracted images
|
147 |
cv2.imwrite(name, frame)
|
@@ -165,31 +150,31 @@ for filename in os.listdir(directory):
|
|
165 |
#apply super-resolution on all frames of a video
|
166 |
|
167 |
# Specify the directory path
|
168 |
-
all_frames_path = "/
|
169 |
|
170 |
# Get a list of all files in the directory
|
171 |
file_names = os.listdir(all_frames_path)
|
172 |
|
173 |
# process the files
|
174 |
for file_name in file_names:
|
175 |
-
inference_image(f"/
|
176 |
|
177 |
|
178 |
#convert super res frames to .avi
|
179 |
-
pathIn = '/
|
180 |
|
181 |
zee = zee+1
|
182 |
fName = "video"+str(zee)
|
183 |
filenameVid = f"{fName}.avi"
|
184 |
|
185 |
-
pathOut = "/
|
186 |
|
187 |
convert_frames_to_video(pathIn, pathOut, fps)
|
188 |
|
189 |
|
190 |
#convert .avi to .mp4
|
191 |
-
src = '/
|
192 |
-
dst = '/
|
193 |
|
194 |
for root, dirs, filenames in os.walk(src, topdown=False):
|
195 |
#print(filenames)
|
|
|
62 |
return result
|
63 |
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
# assign directory
|
67 |
directory = 'videos' #PATH_WITH_INPUT_VIDEOS
|
68 |
zee = 0
|
69 |
|
70 |
def convert_frames_to_video(pathIn,pathOut,fps):
|
71 |
+
global INPUT_DIR
|
72 |
frame_array = []
|
73 |
files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
|
74 |
#for sorting the file names properly
|
|
|
108 |
try:
|
109 |
|
110 |
# PATH TO STORE VIDEO FRAMES
|
111 |
+
if not os.path.exists(f'/{INPUT_DIR}/upload/'):
|
112 |
+
os.makedirs(f'/{INPUT_DIR}/upload/')
|
113 |
|
114 |
# if not created then raise error
|
115 |
except OSError:
|
|
|
126 |
|
127 |
if ret:
|
128 |
# if video is still left continue creating images
|
129 |
+
name = f'/{INPUT_DIR}/upload/frame' + str(currentframe) + '.jpg'
|
130 |
|
131 |
# writing the extracted images
|
132 |
cv2.imwrite(name, frame)
|
|
|
150 |
#apply super-resolution on all frames of a video
|
151 |
|
152 |
# Specify the directory path
|
153 |
+
all_frames_path = f"/{INPUT_DIR}/upload/"
|
154 |
|
155 |
# Get a list of all files in the directory
|
156 |
file_names = os.listdir(all_frames_path)
|
157 |
|
158 |
# process the files
|
159 |
for file_name in file_names:
|
160 |
+
inference_image(f"/{INPUT_DIR}/upload/{file_name}")
|
161 |
|
162 |
|
163 |
#convert super res frames to .avi
|
164 |
+
pathIn = f'/{INPUT_DIR}/results/restored_imgs/'
|
165 |
|
166 |
zee = zee+1
|
167 |
fName = "video"+str(zee)
|
168 |
filenameVid = f"{fName}.avi"
|
169 |
|
170 |
+
pathOut = f"/{INPUT_DIR}/results_videos/"+filenameVid
|
171 |
|
172 |
convert_frames_to_video(pathIn, pathOut, fps)
|
173 |
|
174 |
|
175 |
#convert .avi to .mp4
|
176 |
+
src = f'/{INPUT_DIR}/results_videos/'
|
177 |
+
dst = f'/{INPUT_DIR}/results_mp4_videos/'
|
178 |
|
179 |
for root, dirs, filenames in os.walk(src, topdown=False):
|
180 |
#print(filenames)
|