Skip to content

Instantly share code, notes, and snippets.

@jason19970210
Created May 26, 2023 07:06
Show Gist options
  • Save jason19970210/7d35bfa55103f1041c3e6dbffd1dd175 to your computer and use it in GitHub Desktop.
Save jason19970210/7d35bfa55103f1041c3e6dbffd1dd175 to your computer and use it in GitHub Desktop.
Output Video with Frames with cv2 & Numpy
import cv2
import numpy as np
# Set frame size
frame_width = 1920
frame_height = 1080
# Create a VideoWriter object
video_writer = cv2.VideoWriter('output_video.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 30, (frame_width, frame_height))
# Create a NumPy array of zeros with the specified parameters
frame_data = np.zeros((frame_height, frame_width, 4), dtype=np.uint8)
# Generate some sample frames (for demonstration purposes)
for i in range(300):
# Modify the frame_data array here if needed
# ...
# Write the frame to the video file
video_writer.write(frame_data)
# Display progress
print(f"Frame {i + 1} written.")
# Release the VideoWriter and close the file
video_writer.release()
print("Video saved successfully.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment