赞
踩
在使用之前的代码利用 python 的 opencv 包把图片合并为视频(mp4格式)的时候,报错:
OpenCV: FFMPEG: tag 0x44495658/‘XVID’ is not supported with codec id 12 and format ‘mp4 / MP4 (MPEG-4 Part 14)’
OpenCV: FFMPEG: tag 0x44495658/'XVID' is not supported with codec id 12 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'
主要报错信息内容翻译如下所示:
OpenCV: FFMPEG: tag 0x44495658/'XVID' is not supported with codec id 12 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'
翻译:
OpenCV:FFMPEG:编解码器id 12和格式“mp4/mp4(MPEG-4第14部分)”不支持标记0x44495658/“XVID”
OpenCV:FFMPEG:回退以使用标记0x7634706d/'mp4v'
import cv2
......
fourcc = cv2.VideoWriter_fourcc('M','J','P','G') # MJPG
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()
......
其中,VideoWriter()
原为:
VideoWriter(filename, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
各参数说明如下:
fourcc 本身是一个 32 位的无符号数值,用 4 个字母表示采用的编码器。一般依据你的电脑环境安装了哪些编码器。 常用的有 “DIVX"、”MJPG"、“XVID”、“X264"。可用的列表在这里,点击Video Codecs by FOURCC。
经过查阅资料,发现主要是合成时采用的视频编码不对。
小伙伴们按下面的解决方法即可解决!!!
合成时使用正确的视频编码。
修改前:
fourcc = cv2.VideoWriter_fourcc('M','J','P','G')
修改后:
fourcc = cv2.VideoWriter_fourcc('M', 'P', '4', 'V')
代码总体结构大致如下:
import cv2
......
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()
......
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。