Created
October 5, 2022 03:48
-
-
Save bpradana/ebf1454ceb4214a3bd68f8c182f30784 to your computer and use it in GitHub Desktop.
Save video using OpenCV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
# do something with the frame | |
def process_frame(frame): | |
return frame | |
if __name__ == '__main__': | |
# input and output file name | |
INPUT_FILE = 'input_video.mp4' | |
OUTPUT_FILE = 'output_video.mp4' | |
# output video configuration | |
FPS = 30 | |
WIDTH = 1280 | |
HEIGHT = 720 | |
# define video reader | |
reader = cv2.VideoCapture(INPUT_FILE) | |
# define video writer | |
fourcc = cv2.VideoWriter_fourcc(*'MP4V') | |
writer = cv2.VideoWriter(OUTPUT_FILE, fourcc, FPS, (WIDTH, HEIGHT)) | |
# read video | |
while reader.isOpened(): | |
res, frame = reader.read() | |
# do something with the frame | |
processed_frame = process_frame(frame) | |
# write the frame | |
writer.write(processed_frame) | |
reader.release() | |
writer.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment