Unable to open or export written video

asked 2020-11-24 10:44:25 -0500

System information OpenCV => Operating System / Platform => MacOS Catalina 10.15.4 Compiler => Jupyter Notebook via Anaconda 4.8.3 I'm doing a computer vision task, in which my current step is to create a video based on previously created images. To do so, I'm using OpenCV like this:

fps = 25
files = natsorted([f for f in glob.glob(os.getcwd()+'/tf_files/test/*.jpg')])[:125]
size = (1920,1080)

fourcc = int(cv2.VideoWriter_fourcc(*'mp4v'))
out = cv2.VideoWriter('test.mp4',fourcc,fps=fps,frameSize=size)

for file in files:
    img = cv2.imread(file)


The files list returns the paths of the images:


with the size of each file being:

>>> (1080, 1920, 3)

The code does not give any errors and does actually create a video called 'test.mp4'. Moreover, if the amount of images is changed, the video does change in size as well. I can also open the images with opencv without any problem. However, the video cannot be played, and when exported to another program, it is of length 0. I've tried many different variations of fourcc, but *'mp4' is the only one that actually outputs a .mp4 video. What can be a possible explanation for this?

edit retag flag offensive close merge delete