fffiloni commited on
Commit
9f98966
·
1 Parent(s): 63939d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -57,20 +57,39 @@ def resize_video(input_file):
57
  print(f"OLD H: {new_height} | NEW H: {new_height_adjusted}")
58
  print(f"OLD W: 512 | NEW W: {new_width_adjusted}")
59
 
60
- # Resize the video clip
61
- resized_clip = clip.resize(width=512, height=512)
62
-
 
 
 
 
 
 
63
  # Check if the file already exists
64
  if os.path.exists('video_resized.mp4'):
65
  # Delete the existing file
66
  os.remove('video_resized.mp4')
67
 
68
- # Write the resized video to a file
69
- resized_clip.write_videofile('video_resized.mp4', codec="libx264")
70
 
71
- # Close the video clip
72
- clip.close()
 
 
 
 
 
 
 
 
 
73
 
 
 
 
 
 
74
 
75
  #final_video_resized = os.path.join(temp_output_path, 'video_resized.mp4')
76
  test_w, test_h, fps, frame_count = get_video_dimension('video_resized.mp4')
 
57
  print(f"OLD H: {new_height} | NEW H: {new_height_adjusted}")
58
  print(f"OLD W: 512 | NEW W: {new_width_adjusted}")
59
 
60
+ # Close the video clip
61
+ clip.close()
62
+
63
+ # Open the input video file
64
+ video = cv2.VideoCapture(input_file)
65
+
66
+ # Create a VideoWriter object to write the resized video
67
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for the output video
68
+
69
  # Check if the file already exists
70
  if os.path.exists('video_resized.mp4'):
71
  # Delete the existing file
72
  os.remove('video_resized.mp4')
73
 
74
+ output_video = cv2.VideoWriter('video_resized.mp4', fourcc, 30.0, (512, 512))
 
75
 
76
+ while True:
77
+ # Read a frame from the input video
78
+ ret, frame = video.read()
79
+ if not ret:
80
+ break
81
+
82
+ # Resize the frame to the desired dimensions
83
+ resized_frame = cv2.resize(frame, (width, height))
84
+
85
+ # Write the resized frame to the output video file
86
+ output_video.write(resized_frame)
87
 
88
+ # Release the video objects
89
+ video.release()
90
+ output_video.release()
91
+
92
+
93
 
94
  #final_video_resized = os.path.join(temp_output_path, 'video_resized.mp4')
95
  test_w, test_h, fps, frame_count = get_video_dimension('video_resized.mp4')