Last active
November 6, 2022 09:39
-
-
Save Fitzy1293/3066f3176acfdd89c7365c87971fab92 to your computer and use it in GitHub Desktop.
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, sys | |
# Each video has a frame per second which is number of frames in every second | |
frame_per_second = 60 # smooth as shit bo | |
image_folder = sys.argv[1] | |
tempvid = 'output.mp4' | |
video_output = sys.argv[2] | |
# go back and change this to accept any sat as an arg | |
files_and_duration = [(os.path.join(image_folder, img), 1) for img in sorted(os.listdir(image_folder)) if img.endswith(".png")] | |
w, h = None, None | |
for file, duration in files_and_duration: | |
print(f'writing {file} to the video') | |
frame = cv2.imread(file) | |
if w is None: | |
# Setting up the video writer | |
h, w, _ = frame.shape | |
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') | |
writer = cv2.VideoWriter(tempvid, fourcc, frame_per_second, (w, h)) | |
# Repating the frame to fill the duration | |
# fps cannot be a float, that's why you run the ffmpeg command afte, massively reduces file size | |
for repeat in range(duration * frame_per_second): | |
writer.write(frame) | |
writer.release() | |
os.system(f'ffmpeg -y -i {tempvid} -vf "setpts=0.10*PTS" {video_output}') | |
#ffmpeg -y -i output.mp4 -vf "setpts=0.20*PTS" meteosat-9.mp4 | |
print(f'video written: {video_output}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment