Created
September 23, 2023 06:27
-
-
Save graeme-winter/2caf572e026be8634b74e581f5eede6a to your computer and use it in GitHub Desktop.
JPG sequence conversion to MP4 - N.B. set up for monochrome, includes overlay with time
This file contains 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 sys | |
import os | |
import numpy as np | |
from PIL import Image, ImageFont, ImageDraw | |
import cv2 | |
def main(file_template, start, end): | |
font = ImageFont.truetype("FreeMono.ttf", 32) | |
capture = cv2.VideoCapture(0) | |
out = cv2.VideoWriter("out.mp4", cv2.VideoWriter_fourcc(*"mp4v"), 10.0, (1640, 820)) | |
print(f"Processing images {start} to {end} inclusive") | |
for j in range(start, end + 1): | |
filename = file_template % j | |
print(filename) | |
if not os.path.exists(filename): | |
continue | |
image = Image.open(filename) | |
time = image._getexif()[0x9003].split()[1] | |
draw = ImageDraw.Draw(image) | |
draw.text((16, 16), f"{time[:5]} {j}", (0xFF, 0xFF, 0xFF), font=font) | |
# this inverts RGB but we don't care because monochrome | |
out.write(np.asarray(image)) | |
out.release() | |
capture.release() | |
if __name__ == "__main__": | |
main(sys.argv[1], int(sys.argv[2]), int(sys.argv[3])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment