2

I'd like to create a video from still images, but instead of using a static FPS, I have a specific timestamp for each image (the images are not exactly evenly spaced in time).

How could I go about doing this?

My current code, with a static FPS, is as follows

import cv2
import os

image_folder = '/Users/alex/Dropbox/Apps/CCTV-AE/rasp2/saved/movies/'
video_name = '/Users/alex/Dropbox/Apps/CCTV-AE/rasp2/saved/movies/video.avi'

images = sorted([img for img in os.listdir(image_folder) if img.endswith(".jpg")])

frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shapevideo = cv2.VideoWriter(video_name, 0, 9, (width,height))

for image in images:
    print(os.path.join(image_folder, image))
    video.write(cv2.imread(os.path.join(image_folder, image)))

cv2.destroyAllWindows()
video.release()
Alexis Eggermont
  • 7,665
  • 24
  • 60
  • 93
  • 1
    OpenCV does not provide the ability to create variable FPS videos as far as I know, unfortunately. You can achieve this by writing timestamps to a file separately from your video though, turning those timestamps into proper timecodes, and use a tool to combine the video and timecodes to produce a proper VFR video. There may be better ways to do it (maybe there's a library), but this way will work: https://stackoverflow.com/questions/28086775/can-i-create-a-vfr-video-from-timestamped-images/37893746#37893746 – alkasm Jun 23 '20 at 16:18

0 Answers0