python-opencv写入视频

python-opencv写入视频:

def save_video(frame_data, video_path, output_path='output/'):
    print('save video ..')
    # video_path = cfg.DEMO.DATA_SOURCE
    cap = cv2.VideoCapture(video_path)

    size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
            int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
    fps = cap.get(cv2.CAP_PROP_FPS)
    video_name = video_path.split('/')[-1].split('.')[0] + '.mp4'
    print(output_path + video_name)
    if not os.path.exists(output_path):
        os.makedirs(output_path)
    # fourcc = cv2.VideoWriter_fourcc(*'XVID')    # avi格式用
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')      # mp4格式用
    video_writer = cv2.VideoWriter(output_path + video_name, fourcc, fps,
                                   size)  # (cfg.DEMO.DISPLAY_WIDTH, cfg.DEMO.DISPLAY_HEIGHT))
    for i, frame in enumerate(frame_data):
        # if i > 2:
        video_writer.write(frame)
    video_writer.release()

 

你可能感兴趣的:(opencv,python,图像处理,深度学习)