video-capture - 类型错误 : VideoWriter() missing required argument 'frameSize' (pos 5) with opencv-python ==4. 4.0.42

标签 video-capture opencv-python

我想使用以下代码创建 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/

相关文章:

gstreamer - 从 gstreamer 录制相机流

python - openCV 中的图像分割

c++ - Python OpenCv 构建未在命令行中检测到 visual studio 2019

c# - 如何使用C#创建视频缩略图

objective-c - 运行多个 AVCaptureSession 或添加多个输入

python-3.x - 为什么 NMSboxes 没有消除多个边界框?

python - 为什么HoughCircles检测到虚假圆圈?

python - 通过 OpenCV 在原始图像上标记 Blob 检测

audio - 制作 “Babbelbox”,您可以在其中与聚会进行交谈

c++ - OpenCV 在 VideoCapture grab() 上挂起