lia*_*ong 5 python opencv video-capture
我想使用以下代码创建 VideoWriter:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter('out.mp4',fourcc,fps,(frame_width,frame_height))
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
TypeError: VideoWriter() missing required argument 'frameSize' (pos 5)
Run Code Online (Sandbox Code Playgroud)
当我将代码更改为:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
Run Code Online (Sandbox Code Playgroud)
我收到另一个错误:
TypeError: VideoWriter() missing required argument 'apiPreference' (pos 2)
Run Code Online (Sandbox Code Playgroud)
所以我将代码更改为:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',apiPreference=0,fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
Run Code Online (Sandbox Code Playgroud)
我收到错误:
TypeError: VideoWriter() missing required argument 'params' (pos 6)
Run Code Online (Sandbox Code Playgroud)
我该如何解决它?谁能告诉我如何使用 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))
Run Code Online (Sandbox Code Playgroud)
Cap.get(cv2.*) 的类型是 float,所以我将其更改为整数
| 归档时间: |
|
| 查看次数: |
9599 次 |
| 最近记录: |