Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- def split_video(input_path, output_folder, clip_duration=30):
- video_capture = cv2.VideoCapture(input_path)
- fps = int(video_capture.get(cv2.CAP_PROP_FPS))
- total_frames = int(video_capture.get(cv2.CAP_PROP_FRAME_COUNT))
- clip_frame_count = clip_duration * fps
- clip_number = 1
- frame_number = 0
- while frame_number < total_frames:
- clip_output_path = f"{output_folder}/clip_{clip_number}.mp4"
- out = cv2.VideoWriter(clip_output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (640, 480))
- while frame_number < min(frame_number + clip_frame_count, total_frames):
- ret, frame = video_capture.read()
- out.write(frame)
- frame_number += 1
- out.release()
- clip_number += 1
- video_capture.release()
- input_video_path = "input_video.mp4"
- output_folder_path = "output_clips"
- split_video(input_video_path, output_folder_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement