Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to write first N images of video frames

Hi, I want to write a video from a frame file. Frames folder is this: image description

This is my result:

And this my codes. Where is the problem?

import cv2
import numpy as np
import glob

img_array = []
for filename in glob.glob('C:/Users/mustafa/Downloads/highway/highway/input/*.jpg'):
    img = cv2.imread(filename)
    height, width, layers = img.shape
    size = (width,height)
    img_array.append(img)


out = cv2.VideoWriter('hw.mp4',cv2.VideoWriter_fourcc(*'MP4V'), 24, size)

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

How to write first N images of video frames

Hi, I want to write a video from a frame file. Frames folder is this: image description

This is my result:

And this my codes. Where is the problem?

import cv2
import numpy as np
import glob
 j=0
img_array = []
for filename in glob.glob('C:/Users/mustafa/Downloads/highway/highway/input/*.jpg'):
glob.glob('/content/drive/My Drive/M-30-HD/M-30-HD/*.jpg'): #I work on Google Colab
    img = cv2.imread(filename)
    height, width, layers = img.shape
    size = (width,height)

    print(j)
    j=j+1

    img_array.append(img)
    if(j==3000):
      break


out = cv2.VideoWriter('hw.mp4',cv2.VideoWriter_fourcc(*'MP4V'), cv2.VideoWriter('m30hd.mp4',cv2.VideoWriter_fourcc(*'MP4V'), 24, size)

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