我想使用以下代码创建 VideoWriter:
Fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter('out.mp4',fourcc,fps,(frame_width,frame_height))
但我收到错误:
类型错误:VideoWriter() 缺少必需的参数“frameSize”(位置 5)
当我将代码更改为:
Fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
我收到另一个错误:
类型错误:VideoWriter() 缺少必需的参数“apiPreference”(位置 2)
所以我将代码更改为:
Fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',apiPreference=0,fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
我得到错误:
类型错误:VideoWriter() 缺少必需的参数“params”(位置 6)
我怎么能解决呢?谁能告诉我如何使用 api:VideoWriter()?非常感谢
最佳答案
好的,以下代码对我有用:
frame_num = int(Cap.get(cv2.CAP_PROP_FRAME_COUNT))
frame_width = int(Cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(Cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(result,fourcc,fps,(frame_width,frame_height))
Cap.get(cv2.*) 的类型是浮点数,所以我把它改成整数
关于video-capture - 类型错误 : VideoWriter() missing required argument 'frameSize' (pos 5) with opencv-python ==4. 4.0.42,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65712922/