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

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to use OpenCV 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)
    out.release()


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

    KR, Ch.

    Continue reading...

Compartilhe esta Página