Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pip install opencv-python
- import cv2
- import numpy as np
- def create_vertical_video(input_path, output_path):
- video_capture = cv2.VideoCapture(input_path)
- fps = int(video_capture.get(cv2.CAP_PROP_FPS))
- frame_width = int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH))
- frame_height = int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
- total_frames = int(video_capture.get(cv2.CAP_PROP_FRAME_COUNT))
- output_height = frame_height * 2
- output_video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (frame_width, output_height))
- middle_x = frame_width // 2
- while True:
- ret, frame = video_capture.read()
- if not ret:
- break
- left_half = frame[:, :middle_x, :]
- right_half = frame[:, middle_x:, :]
- stacked_frame = np.vstack((left_half, right_half))
- output_video.write(stacked_frame)
- video_capture.release()
- output_video.release()
- input_video_path = "input_video.mp4"
- output_video_path = "vertical_video_output.mp4"
- create_vertical_video(input_video_path, output_video_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement