2

i'm trying to capture a video using opencv 3.1. I'm using the following code, but when I run it on pycharm, a small window opens (according to task Manager it has something to do with video compression - i can't really see what's in it) and when I close it I get the video preview. However, when I break the loop and finish the program I still get an empty video file. Any suggestions? Thank you

import numpy as np
import cv2


cap = cv2.VideoCapture(0)
height = int(cap.get(4))
width = int(cap.get(3)) 
#fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('C:\Users\Ba\Desktop\output2.avi', -1, 20.0, (width,      height))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)
        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    else:
        break
cap.release()
out.release()
cv2.destroyAllWindows()
1
  • so i guess the probalm is the fact that the video compression window doesn't open
    – Bar Beker
    May 3, 2016 at 12:35

1 Answer 1

1

Having experience only with OpenCV+Python on Linux it appears odd that you use -1 as encoding format instead of commented out fourcc variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.