opencv – OpenCV2/Python: FFMPEG: tag is not supported with codec id 12 and format ‘mp4 / MP4

I would like to use CV2 in Python to compile a video from a number of images. I got the error

OpenCV: FFMPEG: tag is not supported with codec id 12 and format 'mp4 / MP4

and searched here for an answer, how to fix it. I got an answer in this post, but it does not generate a video, the file is just 5.7kB, no matter which number of images I add.

Here is an example code (

import os
import numpy as np
from glob import glob
import cv2

path = "where to find some images"
fname_video="where the video should go"
os.chdir(path)

size=(1024,768)
fps=20

files = [y for x in os.walk(path) for y in glob(os.path.join(x[0], '*.JPG'))][0:10] # just 10 images

image_array = []
for file in files:
    frame = cv2.imread(os.path.join(path,file),0)
    frame = cv2.resize(frame,size)
    image_array.append(frame)

fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(fname_video, fourcc, fps, size)
for i in range(len(image_array)):
    out.write(image_array[i])
out.release()

Maybe somebode can give me a hint how to get a valid video file?

KR,
Ch.

Read more here: Source link