Ask Your Question
0

cv2.VideoCapture : can not read saved videos

asked 2018-03-09 09:28:28 -0600

Joshitha gravatar image

updated 2018-03-11 09:17:37 -0600

My problem is the same as mentioned in

http://answers.opencv.org/question/1965/cv2videocapture-cannot-read-from-file/

and

https://stackoverflow.com/questions/11699298/opencv-2-4-videocapture-not-working-on-windows

Im using OpenCV 3.4.0 on Windows 10, able to capture live videos from Webcam using cv2.VideoCapture(0) but can not read my pre-existing .mp4/.avi/.3gp videos.

Yes, I have given the entire path correctly, even changed to '/' , copied the 'opencv_ffmpeg340_64.dll' file into C:\Python27 and yet no results.

I read a suggestion to use the OpenCV binaries from http://www.lfd.uci.edu/~gohlke/python... , but do not know exactly how to proceed.

The same question was asked in 2012 (http://answers.opencv.org/question/19...) and no body seems to have benefitted from any solution, hence beginning a new thread.

edit

heres my code:

import cv2

import numpy as np

cap = cv2.VideoCapture('C:\Users\DELL PC\Desktop\IMG_PROC\python\VID-20140623-WA0000.avi') # cap = cv2.VideoCapture('C:/Users/DELL PC/Desktop/IMG_PROC/python/VID-20140623-WA0000.avi')

Check if camera opened successfully

if (cap.isOpened()== False):

print("Error opening video stream or file")

while(cap.isOpened()):

ret, frame = cap.read()

if ret == True:

cv2.imshow('Frame',frame)

if cv2.waitKey(25) & 0xFF == ord('q'):

 break

else:

break

cap.release()

cv2.destroyAllWindows()

edit retag flag offensive close merge delete

Comments

"copied opencv_ffmpeg340_64.dll' file into C:\Python27" -- no, put it on the PATH, instead of copying dlls around

berak gravatar imageberak ( 2018-03-09 09:30:22 -0600 )edit

@berak , i have placed the dll file in the same folder as the video, yet no results

Joshitha gravatar imageJoshitha ( 2018-03-11 09:17:55 -0600 )edit

with opencv 340 you will need openh264-1.7.0-win64.dll too

LBerger gravatar imageLBerger ( 2018-03-11 09:26:28 -0600 )edit

hey @LBerger, still no luck. I copied openh264-1.7.0-win64.dll into C:\Python27 and the file containing video to be read.

Joshitha gravatar imageJoshitha ( 2018-03-11 09:38:45 -0600 )edit
1

"i have placed the dll file in the same folder as the video" : no you can copy in same folder that python.exe or in folder python2_7/scripts (check if this two folders are in path : use cmd and in console type set, you will see all system variables and check path variable)

LBerger gravatar imageLBerger ( 2018-03-11 10:14:55 -0600 )edit

Yes i have put them in C:\Python27(where python.exe exists) and C:\Python27\Scripts. Still nothing. can you please elaborate on what you mean by 'check if this two folders are in path' ?

Joshitha gravatar imageJoshitha ( 2018-03-11 12:16:49 -0600 )edit

@LBerger, I have checked the pat variables and both opencv and python do exist

Joshitha gravatar imageJoshitha ( 2018-03-12 01:41:55 -0600 )edit

I got exactly the same problem. Do not know what to do with it.

ouyangivan gravatar imageouyangivan ( 2018-06-13 09:25:51 -0600 )edit

@ouyangivan , please do NOT post answers here, if you have a question or comment, thank you.

berak gravatar imageberak ( 2018-06-13 09:47:01 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-03-11 11:52:07 -0600

supra56 gravatar image

I tested it and I removed else break condition.

#/usr/bin/env python35
#OpenCV 3.4.1

import cv2
import numpy as np

cap = cv2.VideoCapture('../video/road.avi')  
if (cap.isOpened()== False):
    print("Error opening video stream or file")

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
        cv2.imshow('Frame',frame)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        break     

cap.release()
cv2.destroyAllWindows()
edit flag offensive delete link more

Comments

Just wondering that if you are using python2 or python 3.

supra56 gravatar imagesupra56 ( 2018-03-11 11:55:37 -0600 )edit

python 2.7.14 only

Joshitha gravatar imageJoshitha ( 2018-03-11 12:23:12 -0600 )edit

tried your code @supra56 , still getting isOpened= False

Joshitha gravatar imageJoshitha ( 2018-03-11 12:27:35 -0600 )edit

I remembered this seen this I tried this before, but i haver no problem. But your problem is filename. @LBerger was telling you that u can't put in that folder.

supra56 gravatar imagesupra56 ( 2018-03-11 15:37:27 -0600 )edit

@supra56 , yes my video exists in the same folder and i have also tried giving in the path. The dll files have been placed and path variables have been checked. The problem still persists

Joshitha gravatar imageJoshitha ( 2018-03-12 01:45:05 -0600 )edit

Can you try this? cap = cv2.VideoCapture( 'VID-20140623-WA0000.avi')

supra56 gravatar imagesupra56 ( 2018-03-12 04:34:28 -0600 )edit

yes, tried that, still throwing the error :(

Joshitha gravatar imageJoshitha ( 2018-03-12 10:24:52 -0600 )edit
1

The problem is because the bug in OpenCV version 3.4.1. Please refer https://github.com/opencv/opencv/issu...

NehaN gravatar imageNehaN ( 2018-11-28 06:37:28 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-09 09:28:28 -0600

Seen: 11,696 times

Last updated: Mar 11 '18