解决:OpenCV: FFMPEG: tag 0x5634504d/‘MP4V‘ is not supported with codec id 12 and f

论坛 期权论坛 期权     
匿名技术用户   2021-1-9 12:08   13142   0

问题描述:

利用python 的opencv包把图片合并为视频(mp4格式)的时候发现错误。

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'

原因,主要是合成时采用的视频编码不对,

还是使用的是

fourcc = cv2.VideoWriter_fourcc('M','J','P','G')

来生成mp4文件,发现生成的时候无法播放。这种格式需要视频格式为 avi。

为了支持mp4格式,改为如下即可

fourcc = cv2.VideoWriter_fourcc('M', 'P', '4', 'V') 

总的代码结构大致如下:

fourcc = cv2.VideoWriter_fourcc('M', 'P', '4', 'V') # mp4
img_size = (image_w, image_h)
videoWriter = cv2.VideoWriter(save_video_path, fourcc, fps, img_size, isColor=True)

for  image_path in xxx:
    image = cv2.imread(image_path)
    videoWriter.write(image)
videoWriter.release()

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP