why my saved video cannot play?

asked 2019-06-14 19:30:26 -0600

Nbb gravatar image

I read video, do operation, then save. But why cant my video open? I am using windows 10.

 import numpy as np
import cv2

vid = cv2.VideoCapture("./results/videos/0.avi")
out = cv2.VideoWriter("./results/videos/0_processed.avi", cv2.VideoWriter_fourcc(*'MJPG'), 10, (960,378))
while(vid.isOpened()):
    ret, im = vid.read()
    if(ret==False):
        break

    im = im.astype(np.float)
    im_median = np.median(im)
    im = im + (155-im_median)
    im[im > 255] = 255
    im = im.astype(np.uint8)    
    out.write(im)

# When everything done, release the capture
vid.release()
out.release()
edit retag flag offensive close merge delete

Comments

What if you rename it from out to something else, like vid_out?

sjhalayka gravatar imagesjhalayka ( 2019-06-14 20:42:39 -0600 )edit

how did you come up with (960,378) ? it must be the size of the input stream

berak gravatar imageberak ( 2019-06-15 00:08:33 -0600 )edit