TypeError: VideoWriter() missing required argument 'frameSize' (pos 5) with opencv-python ==4.4.0.42

Viewed 6313

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

2 Answers

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

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.

Related