0

I cant figure out what the problem is.

I am using

  • Ubuntu 17.04
  • Python 2.7.13
  • OpenCV Version: 3.3.0

I have gone through all the related problems on internet but have not got the solution for the problem yet. 'v.mp4' file is in the same directory in which my python file is present.

CODE

import cv2 vidcap = cv2.VideoCapture('v.mp4') success,image = vidcap.read() count = 0; print success while success: success,image = vidcap.read() cv2.imwrite("frame%d.jpg" % count, image) # save frame as JPEG file if cv2.waitKey(10) == 27: # exit if Escape is hit break count += 1 
11
  • Please provide a minimal reproducible example Commented Oct 4, 2017 at 15:01
  • can you try to change your file so it is while vidcap.isOpened() ? Can you ensure the file is being read? Also try displaying the frame first using cv2.imshow() before writing it? Commented Oct 4, 2017 at 15:09
  • How did you install OpenCV? Commented Oct 4, 2017 at 18:38
  • @SamerTufail I have already tried while vidcap.isOpened(), but it never enters the while loop. I am not sure that my code is able to read the file on the first place. Since success value always remains false, there is no point of doing cv2.imshow() for now. Commented Oct 5, 2017 at 8:06
  • @AlexanderReynolds i have installed opencv using $pip install opencv-python Commented Oct 5, 2017 at 8:11

2 Answers 2

1

The opencv-python package does not have VideoCapture() support outside of Windows. See my answer here or the PyPI opencv-python documentation, which states:

IMPORTANT NOTE

MacOS and Linux packages do not support video related functionality (not compiled with FFmpeg).

Sign up to request clarification or add additional context in comments.

3 Comments

So, should I compile OpenCV from source if I don't want these type of problems as explained by you in your other answer?
@arjungupta yep! If you aren't familiar with compiling stuff from source it can be a bit of a headache, but you'll get comfortable with it after a few tries :). If this answered your question, could you select it as accepted? Thanks!
Thanks for your advice, that really helped. I found how to compile open cv from source from https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/ , but that was tutorial was supported for Ubuntu 16.04, so I downgraded my OS from Ubuntu 17.04 to Ubuntu 16.04 as many of the libraries were not available for Ubuntu 17.04 that were very necessary for my project.
0

For me, I used pycharm as my ide. Every isopened() and read() showed up false. All I had to do to was change the python version that pycharm used to python 2.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.