Reputation: 147
I want to create VideoWriter with the following code:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter('out.mp4',fourcc,fps,(frame_width,frame_height))
but i get the error:
TypeError: VideoWriter() missing required argument 'frameSize' (pos 5)
when i change my code to:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
i get another error:
TypeError: VideoWriter() missing required argument 'apiPreference' (pos 2)
so i change my code to :
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',apiPreference=0,fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
i get error:
TypeError: VideoWriter() missing required argument 'params' (pos 6)
How could i solve it? Could anyone tell me how to use the api:VideoWriter()?Thanks a lot
Upvotes: 6
Views: 10709
Reputation: 45
I had the same problem. Turns out I was passing a pathlib.Path
instead of a string for the filename. Converting to string helped. Seems openCV is not very good with reporting that it received the wrong types. So make sure you check all types of the arguments you are passing.
Upvotes: 0
Reputation: 135
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter(path,apiPreference = 0,fourcc = fourcc, fps = 30,frameSize = (256,256) )
for i in range(len(predictions)):
out.write((img_as_ubyte(predictions[i])))
out.release()
it did worked for me used skimage's image_as_ubyte to convert float to int.
Upvotes: 1
Reputation: 147
ok, the following code works for me :
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))
the type of Cap.get(cv2.*) is float, so i change it to integer
Upvotes: 5