Search code examples
python-3.ximageopencvvideosteganography

How do I increase speed of playback of images using python3 using cv2


I have used cv2 to combine a folder of images into a video using cv2 but the speed in which the video plays is too slow is there a way to increase the speed?


import cv2
import os

image_folder = 'd:/deep/data'
video_name = 'video.avi'

images = [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.shape

video = cv2.VideoWriter(video_name, 0, 1, (width,height))

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

cv2.destroyAllWindows()
video.release()

to set fps i tried this peice of code and it still dint work

import cv2
import os
import numpy as np

image_folder = 'd:/deep/data'
video_name = 'video.avi'
fps=100
images = [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.shape

video = cv2.VideoWriter(video_name, 0, 1, (width,height),fps)



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


cv2.destroyAllWindows()
video.release()

Solution

  • cv2.VideoWriter([filename, fourcc, fps, frameSize[, isColor]]) → <VideoWriter object>
    

    Check documentation and set fps. your current framerate is 1 fps .

    Edit :

    Should be something like this :

    fourcc = cv2.VideoWriter_fourcc(*'DIVX')  # codec for windows (supported by your device?)
    fps = 25.0   # adjust the framerate here
    cv2.ViewoWriter(video_name, fourcc, fps , (width,height))