kevinwang676 commited on
Commit
c9bda61
1 Parent(s): bfed652

Update app_new.py

Browse files
Files changed (1) hide show
  1. app_new.py +20 -7
app_new.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
- imageio.mimwrite(output_video, frames, 'FFMPEG', fps=25, codec='libx264', quality=9, pixelformat='yuv420p')
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  return output_video
356
 
357
 
@@ -408,6 +421,6 @@ ip_address = "0.0.0.0" # Replace with your desired IP address
408
  port_number = 7860 # Replace with your desired port number
409
 
410
 
411
- demo.queue().launch(
412
  share=True, debug=True, show_error=True #server_name=ip_address, server_port=port_number
413
  )
 
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
 
 
421
  port_number = 7860 # Replace with your desired port number
422
 
423
 
424
+ demo.launch(
425
  share=True, debug=True, show_error=True #server_name=ip_address, server_port=port_number
426
  )