2

I've been trying to open a video file using OpenCV and process its frames. I have both avi file and mp4 file, the mp4 file works well in Java but in Python (where I really need it...) it doesn't work (I keep getting None in videocapture.read()).

Any ideas what can this be? how can it be solved?

EDIT: Here's the code I have:

import cv2
video_capture = cv2.VideoCapture('myfile.mp4')
video_capture.set(propId=cv2.cv.CV_CAP_PROP_FRAME_WIDTH, value=1280.0)
video_capture.set(propId=cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, value=720.0)
ret, frame = self.video_capture.read()

if frame is not None:
    # processing code...never reaches here

Thanks.

DanielY
  • 1,141
  • 30
  • 58

2 Answers2

1

Check this question and the solution provided by this answer.

Maybe it could help.

Community
  • 1
  • 1
dazzieta
  • 662
  • 4
  • 20
  • I've done again what it's said in that thread....now I get "warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:537)" – DanielY Jul 10 '16 at 14:18
  • Eventually this was solved by your reference + I had a typo in the path. Thanks alot – DanielY Jul 11 '16 at 08:14
0

Try this

import cv2 cap = cv2.VideoCapture('myfile.mp4') ret = cap.set(3,1280) ret = cap.set(4,720) while True: ret,frame = cap.read() cv2.imshow('show',frame) key = cv2.waitKey(10) if key == 27: break