简体   繁体   中英

How to smoothen and slow down a video

Im using this code to convert a batch of images to video :-

import cv2
import numpy as np
import glob

img_array = []
for filename in glob.glob('C:/New folder/Images/*.jpg'):
    img = cv2.imread(filename)
    height, width, layers = img.shape
    size = (width,height)
    img_array.append(img)


out = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 15, size)

for i in range(len(img_array)):
    out.write(img_array[i])
out.release()

The problem now is that since images are not continuously snipped but have gaps, hence the output video is very very fast. I want a option in opencv to create the video in slow motion.

It looks like you are setting the video FPS to 15 but you aren't getting that result for some reason. You could try lowering 15 down to say 5 like this:

out = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 5, size)

I imagine you've tried that though, so another alternative would be to write each image to the video multiple times. For example:

num_repeats = 5 

for img in img_array:
    for _ in range(num_repeats): 
        out.write(img)

Just change the value of num_repeats until it results in a speed you like.

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