简体   繁体   中英

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()
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))

this is the right code

import cv2
import os
import numpy as np

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
fourcc = cv2.VideoWriter_fourcc(*'XVID')
video = cv2.VideoWriter(video_name, fourcc,15.0, (width,height))



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


cv2.destroyAllWindows()
video.release()


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM