Skip to content

Instantly share code, notes, and snippets.

@sayakpaul
Created January 30, 2025 10:42
Show Gist options
  • Save sayakpaul/f70c994e975fb61310e855d5c0121a5c to your computer and use it in GitHub Desktop.
Save sayakpaul/f70c994e975fb61310e855d5c0121a5c to your computer and use it in GitHub Desktop.
Create nice collage videos from videos.
from moviepy.editor import VideoFileClip, clips_array
import glob
def create_video_collage(video_paths, output_path="collage.mp4"):
"""
Combine four videos of the same resolution into a 2×2 collage.
Args:
video_paths (list[str]): List of paths to the four video files.
output_path (str): Filename for the output collage video.
"""
# Load clips
clips = [VideoFileClip(path) for path in video_paths]
print(clips)
# Arrange clips in a 2×2 grid
final_clip = clips_array([
[clips[0], clips[1]],
[clips[2], clips[3]]
])
# Write output video
final_clip.write_videofile(
output_path,
codec="libx264", # Common H.264 codec
fps=24 # You can adjust FPS if needed
)
if __name__ == "__main__":
# Example usage:
video_files = glob.glob("clips/*.mp4")
print(video_files)
create_video_collage(video_files, "collage_output.mp4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment