Video not saving on Mac OS X when using opencv's VideoWriter

37 Views Asked by At

I am trying to create a video Style-transfer tool using this Google hub. Once it does the style-transfer for all frames, I pass it to a function for writing the new frames and saving them to a video.

I was working on this with Google colab but, seeing at it takes a long time and I don't want to constantly interact with it, I decided to download it and run it locally on my MacMini with macOS Catalina (10.15.7). The problem is, it was saving the files to my drive with colab but on my Mac it is not saving the files to my computer.

Here's the code.

def exportVideo(frames, path, fps):

    if fps==0:
        fps=12
    
    out = cv2.VideoWriter(path,cv2.VideoWriter_fourcc('m','p','4','v'), 10, (frames[0].shape[1], frames[0].shape[0]), True)
    for img in tqdm(frames):
        array=img.numpy()
        normalized_array = (array - np.min(array))/(np.max(array) - np.min(array))
        img_array = (normalized_array * 255).astype(np.uint8)
        img_array = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR)
        out.write(img_array)
    out.release()
    
    print('Video was saved to'+path)

No errors appear when running the code but the video does not show up on the specified path.

0

There are 0 best solutions below