OpenCV: FFMPEG: tag 0x5634504d/'MP4V' is not supported with codec id 12 and format 'mp4 / MP4 (MP...

今天在进行openCV写入视频的时候出现了如下报错(虽然不是什么大问题,代码照样能运行,但是依旧想改掉这个bug):

错误内容:
OpenCV: FFMPEG: tag 0x5634504d/'MP4V' is not supported with codec id 12 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'

代码内容:

def q_11():
    path = "./1.mp4"
    cap = cv2.VideoCapture(path)
    width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
    output = cv2.VideoWriter('./2.mp4', cv2.VideoWriter_fourcc('M', 'P', '4', 'V'), 30, (width, height))
    x, y =50, 50
    step = 1
    while True:
        ret, img = cap.read()
        if ret:
            x += step*2
            y += step
            if y>height and x>width: step = -10
            if y<0 and x<0: step = 10
            cv2.putText(img,"HMX",(x,y),cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,1,(255,255,255),2)
            output.write(img)
            cv2.imshow("video", img)
            if cv2.waitKey(30) == ord(" "):
                break  
        else:
            break

解决方案:
只需要将大写的MP4V,改为小写的mp4v即可。

这里的关于MP4v除了写成"m", "p","4","v"这样,还可以简写为*"mp4v"

你可能感兴趣的:(OpenCV: FFMPEG: tag 0x5634504d/'MP4V' is not supported with codec id 12 and format 'mp4 / MP4 (MP...)