Created
December 7, 2020 13:06
-
-
Save prasadwrites/67708a30d60502ae5620a75b8250a6a2 to your computer and use it in GitHub Desktop.
concat.py
This file contains hidden or 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 | |
| import os | |
| from moviepy.editor import VideoFileClip, concatenate_videoclips,CompositeVideoClip | |
| from PIL import Image | |
| list_of_candidates = [] | |
| for (dirpath, dirnames, filenames) in os.walk("."): | |
| for filename in filenames: | |
| if (filename.endswith('.png') or filename.endswith('.jpg')): | |
| list_of_candidates.append(os.sep.join([dirpath, filename])) | |
| print(list_of_candidates) | |
| video_path = "base_final.MP4" | |
| for image_path in list_of_candidates: | |
| print(image_path) | |
| video_image_path = image_path+ ".mp4" | |
| frame = cv2.imread(image_path) | |
| frame_resized = cv2.resize(frame , (1080,1920)) | |
| height, width, layers = frame_resized.shape | |
| print(height) | |
| print(width) | |
| video = cv2.VideoWriter(video_image_path, 0x00000021, 1, (width, height)) | |
| for i in range(15): | |
| video.write(frame_resized) | |
| video.release() | |
| image_clip = VideoFileClip(video_image_path) | |
| orig_video_clip = VideoFileClip(video_path, target_resolution= (height,width)) | |
| final_clip= concatenate_videoclips([orig_video_clip, image_clip], method='compose') | |
| final_clip.write_videofile(image_path + '_final.mp4') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment