1. Problem code
A few months ago, a piece of code could be executed normally. Some of the codes are as follows:
def buildVideoByCV():
videoMake = cv2.VideoWriter()
fourcc = cv2.VideoWriter_fourcc(*'MP4V') #https://blog.csdn.net/whudee/article/details/108689420
fps = 12
videoMake.open(r"g:\video\lightShowCV.MP4", fourcc, fps, (800,600))
for t in range(65*fps):
img = makeframe(t*1.0/fps)
videoMake.write(img)
if t%20==0:print(f'\r视频制作进度:{(t*100.0)/(66*fps):4.2f}%',end='')
videoMake.release()
2. Error message
Error in execution today:
Video production progress: 95.96%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'
3. Solution
Set FourCC = cv2.videowriter_FourCC (*'mp4v')
is changed to: FourCC = CV2.Videowriter_FourCC (*'mp4v')
, just change the encoded uppercase mp4v to lowercase.
4. Summary
This paper introduces the solution to the error reported by opencv videowriter: ffmpeg: tag ‘mp4v’ is not supported. You only need to replace the code ‘mp4v’ with ‘mp4v’.