write a video file opencv pycharm mp4

asked 2020-04-29 16:36:52 -0600

i'm trying to save my video to an mp4 file but at the moment to see the properties of the file saved it has only a few bytes. I proved to save in format .avi and in the folder always has 5.55 Kb. In the directory of pyCharm it shows an interrogation sign (?) I'm working with opencv-python 4.2. Sorry, i'm new in opencv.

import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.VideoCapture('SofiPepsi.mp4')
out = cv2.VideoWriter('output.avi', cv2.VideoWriter_fourcc(*'XVID'), 25, (320,240))

while(1):
    ret, frame = img.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    out.write(frame)
    cv2.imshow('gray', gray)
    cv2.imshow('frame', frame)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        break


img.release()
out.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete