VideoWriter outputs corrupted video file

后端 未结 3 1720
逝去的感伤
逝去的感伤 2020-12-19 06:13

This is my code to save web_cam streaming. It is working but the problem with output video file.

import numpy as np
im         


        
3条回答
  •  余生分开走
    2020-12-19 06:54

    The output file is corrupted because of the wrong frame rate and frame resolution. Using this code :

    out = cv2.VideoWriter('output.avi', -1, 20.0, (640,480))
    

    We set the fps/frame rate per second 20. Which was not correct. Also, the frame width and height was wrong. I solved by getting fps, width, height from the captured web_cam profile.

    cap = cv2.VideoCapture(0)  #web-cam capture
    
    fps = cap.get(cv2.CAP_PROP_FPS)
    width  = cap.get(cv2.CAP_PROP_FRAME_WIDTH)   # float
    height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)  # float
    out = cv2.VideoWriter('output.avi', -1,fps, (int(width), int(height)))
    

提交回复
热议问题