Update app_new.py
Browse files- app_new.py +6 -17
app_new.py
CHANGED
|
@@ -343,26 +343,15 @@ 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 |
-
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 |
-
target_frames.append(frames[t_idx])
|
| 363 |
-
|
| 364 |
-
# save video
|
| 365 |
-
imageio.mimwrite(output_video, target_frames, 'FFMPEG', fps=25, codec='libx264', quality=9, pixelformat='yuv420p')
|
| 366 |
return output_video
|
| 367 |
|
| 368 |
|
|
|
|
| 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 |
+
imageio.mimwrite(output_video, frames, 'FFMPEG', fps=25, codec='libx264', quality=9, pixelformat='yuv420p')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
return output_video
|
| 356 |
|
| 357 |
|