Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem's with video output, newbi here~

Hello guys. Studying openCV now, for part time job and met problem, with what i can't deal. This is simply code, as at tutorial, but i am trying to have at output black&white video. Problem in codec, i think, because i tryed to use really a lot of them - DIVX, MP4V, M4S2 and etc., at output i have 1 kb video file just with name. I am using windows, 3.5Python. With image all great~ Will be happy in help, i tryed google about this problem and all advices couldn't help me. Sorry for English, not a native speaker, but trying to do my best~

import numpy as np
import cv2

cap = cv2.VideoCapture('VideoEX.mp4')

fourcc = cv2.VideoWriter_fourcc(*"MP4V")
out = cv2.VideoWriter('output1.mp4', fourcc , 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
       gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
       out.write(gray)

       cv2.imshow('frame',frame)
       if cv2.waitKey(1) & 0xFF == ord('q'):
           break
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()