Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create render_video #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions render_video
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#python render_video.py path_to_image_folder


import cv2
import os
from glob import glob
import sys
from tqdm import tqdm # Progress bar library

def images_to_video(image_folder, fps=30):
# Check if the folder exists
if not os.path.exists(image_folder):
print(f"Error: Folder '{image_folder}' does not exist.")
return

# Get all image files in the folder, sorted by filename
images = sorted(glob(os.path.join(image_folder, '*.jpg'))) # Change extension if needed
if not images:
print("No images found in the folder.")
return

# Extract folder name and define the output video file
folder_name = os.path.basename(os.path.normpath(image_folder))
os.makedirs("output_video", exist_ok=True)
output_video = os.path.join("output_video", f"{folder_name}-01.mp4")


# Ensure the output file doesn't overwrite existing files
counter = 1
while os.path.exists(output_video):
counter += 1
output_video = f"{folder_name}-{counter:02d}.mp4"

# Read the first image to get dimensions
frame = cv2.imread(images[0])
height, width, channels = frame.shape

# Define the video codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # For .mp4 format
video_writer = cv2.VideoWriter(output_video, fourcc, fps, (width, height))

# Process images with a progress bar
print(f"Rendering video: {output_video}")
for image_file in tqdm(images, desc="Processing frames", unit="frame"):
frame = cv2.imread(image_file)
video_writer.write(frame) # Write the frame to the video

video_writer.release()
print(f"Video successfully created: {output_video}")

if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python script.py <image_folder>")
sys.exit(1)

image_folder = sys.argv[1]
images_to_video(image_folder, fps=30)