Advertisement
sourav8256

Untitled

Aug 18th, 2023 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. pip install opencv-python
  2.  
  3.  
  4. import cv2
  5. import numpy as np
  6.  
  7. def create_vertical_video(input_path, output_path):
  8. video_capture = cv2.VideoCapture(input_path)
  9. fps = int(video_capture.get(cv2.CAP_PROP_FPS))
  10. frame_width = int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH))
  11. frame_height = int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
  12. total_frames = int(video_capture.get(cv2.CAP_PROP_FRAME_COUNT))
  13.  
  14. output_height = frame_height * 2
  15. output_video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (frame_width, output_height))
  16.  
  17. middle_x = frame_width // 2
  18.  
  19. while True:
  20. ret, frame = video_capture.read()
  21. if not ret:
  22. break
  23.  
  24. left_half = frame[:, :middle_x, :]
  25. right_half = frame[:, middle_x:, :]
  26.  
  27. stacked_frame = np.vstack((left_half, right_half))
  28. output_video.write(stacked_frame)
  29.  
  30. video_capture.release()
  31. output_video.release()
  32.  
  33. input_video_path = "input_video.mp4"
  34. output_video_path = "vertical_video_output.mp4"
  35. create_vertical_video(input_video_path, output_video_path)
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement