当前位置:   article > 正文

解决:OpenCV: FFMPEG: tag 0x44495658/‘XVID‘ is not supported with codec id 12 and format ‘mp4 / MP4_opencv: ffmpeg: tag 0x44495658/'xvid' is not suppo

opencv: ffmpeg: tag 0x44495658/'xvid' is not supported with codec id 12 and

解决:OpenCV: FFMPEG: tag 0x44495658/‘XVID’ is not supported with codec id 12 and format 'mp4 / MP4





背景

在使用之前的代码利用 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'
  • 1
  • 2


报错翻译

主要报错信息内容翻译如下所示:

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'
  • 1
  • 2

翻译:

OpenCV:FFMPEG:编解码器id 12和格式“mp4/mp4(MPEG-4第14部分)”不支持标记0x44495658/“XVID”
OpenCV:FFMPEG:回退以使用标记0x7634706d/'mp4v'
  • 1
  • 2


代码如下

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()
......

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

其中,VideoWriter()原为:

VideoWriter(filename, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
  • 1

各参数说明如下:

  1. filename 是要保存的文件的路径
  2. fourcc 指定编码器
  3. fps 要保存的视频的帧率
  4. frameSize 要保存的文件的画面尺寸
  5. isColor 指示是黑白画面还是彩色的画面

fourcc

fourcc 本身是一个 32 位的无符号数值,用 4 个字母表示采用的编码器。一般依据你的电脑环境安装了哪些编码器。 常用的有 “DIVX"、”MJPG"、“XVID”、“X264"。可用的列表在这里,点击Video Codecs by FOURCC



报错原因

经过查阅资料,发现主要是合成时采用的视频编码不对。

小伙伴们按下面的解决方法即可解决!!!



解决方法

合成时使用正确的视频编码。

修改前:

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

修改后:

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

代码总体结构大致如下:

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()
......

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13


今天的分享就到此结束了

欢迎点赞评论关注三连

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/484807
推荐阅读
相关标签
  

闽ICP备14008679号