<BUGFIX>: fix app.py (#47)
Browse files
app.py
CHANGED
|
@@ -343,15 +343,28 @@ def check_video(video):
|
|
| 343 |
# # Run the ffmpeg command to change the frame rate to 25fps
|
| 344 |
# command = f"ffmpeg -i {video} -r 25 -vcodec libx264 -vtag hvc1 -pix_fmt yuv420p crf 18 {output_video} -y"
|
| 345 |
|
| 346 |
-
#
|
| 347 |
reader = imageio.get_reader(video)
|
| 348 |
-
fps = reader.get_meta_data()['fps'] #
|
| 349 |
|
| 350 |
-
#
|
| 351 |
frames = [im for im in reader]
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
return output_video
|
| 356 |
|
| 357 |
|
|
|
|
| 343 |
# # Run the ffmpeg command to change the frame rate to 25fps
|
| 344 |
# command = f"ffmpeg -i {video} -r 25 -vcodec libx264 -vtag hvc1 -pix_fmt yuv420p crf 18 {output_video} -y"
|
| 345 |
|
| 346 |
+
# read video
|
| 347 |
reader = imageio.get_reader(video)
|
| 348 |
+
fps = reader.get_meta_data()['fps'] # get fps from original video
|
| 349 |
|
| 350 |
+
# conver fps to 25
|
| 351 |
frames = [im for im in reader]
|
| 352 |
+
target_fps = 25
|
| 353 |
+
|
| 354 |
+
L = len(frames)
|
| 355 |
+
L_target = int(L / fps * target_fps)
|
| 356 |
+
original_t = [x / fps for x in range(1, L+1)]
|
| 357 |
+
t_idx = 0
|
| 358 |
+
target_frames = []
|
| 359 |
+
for target_t in range(1, L_target+1):
|
| 360 |
+
while target_t / target_fps > original_t[t_idx]:
|
| 361 |
+
t_idx += 1 # find the first t_idx so that target_t / target_fps <= original_t[t_idx]
|
| 362 |
+
if t_idx >= L:
|
| 363 |
+
break
|
| 364 |
+
target_frames.append(frames[t_idx])
|
| 365 |
+
|
| 366 |
+
# save video
|
| 367 |
+
imageio.mimwrite(output_video, target_frames, 'FFMPEG', fps=25, codec='libx264', quality=9, pixelformat='yuv420p')
|
| 368 |
return output_video
|
| 369 |
|
| 370 |
|