1

cap.isOpened() is returning false . I am using ubuntu but when I am using the same code in windows, I am able to execute

import numpy as np
import cv2
cap = cv2.VideoCapture('jitender.mp4')
count=0
print(cap.isOpened())
while(cap.isOpened()):
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',gray)
    count=count+1
    print(count)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()
cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
  • maybe related? https://github.com/skvark/opencv-python/issues/14 at least in these bindings there is no FFmpeg support for Linux and MacOS yet. – Piglet Nov 21 '17 at 15:31

1 Answers1

0

isOpened returns False when it cannot open the file or when it cannot understand the file it opened. Make sure:

  • The file is in the same directory
  • Your user has read permissions to the file
  • The file is, in fact, the video file.

Try ls -l jitender.mp4. You should see something like:

-rw-r--r--  1 <username>  <group>  1234567 Nov 20 19:30 jitender.mp4

You might get -rw-rw-rw-, the important part is that you have the r's there. You also need to make sure the number after your group name is sufficiently large. Sometimes files are corrupted in transit. If you can do some sort of checksum, that would let you know for sure. Instructions for a checksum can be found here.

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
  • below is the ls -l output -rw-rw-r-- 1 jitender jitender 1055736 Nov 21 21:34 abc.mp4 -rwxrwxrwx 1 jitender jitender 44213366 Nov 9 16:29 jitender.mp4 So I dont think read mode will be an issue – Jitendarpal Singn Nov 21 '17 at 16:08