1

I've been reviewing the multitudes of similar questions for this issue, but I'm afraid I just cannot figure out why I cannot open a file in opencv

I have a file "small.avi", which is a reencoding of "small.mp4" that I got from the internet. I reencoded it with ffmpeg -i small.mp4 small.avi, and I did this because I couldn't open a mp4 file either and online it recommended trying an avi format first.

Here is my code (mostly copied from a tutorial, with a few lines to show some relevant info):

import cv2
import os

for _, __, files in os.walk("."):
    for file in files:
        print file
print ""

cap = cv2.VideoCapture("small.mp4")
print cap.isOpened()
print cap.open("small.avi")
i = 0
while cap.isOpened() and i < 10:
    i += 1
    ret, frame = cap.read()
    print "read a frame"
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame', gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

This produces the following output:

"A:\Program Files\AnacondaPY\Anaconda\python.exe" A:/Documents/Final/VideoProcessor.py
small.avi
small.mp4
VideoProcessor.py

False
False

Process finished with exit code 0

My program does not appear to properly open either file. Following the advice of

Can not Read or Play a Video in OpenCV+Python using VideoCapture

and

Cannot open ".mp4" video files using OpenCV 2.4.3, Python 2.7 in Windows 7 machine,

I found my cv2 version to be 3.0.0, went to

A:\Downloads\opencv\build\x86\vc12\bin

and copied the file opencv_ffmpeg300.dll to

A:\Program Files\AnacondaPY\Anaconda

Despite this, the code still does not successfully open the video file. I even tried the x64 versions, and tried naming the file opencv_ffmpeg.dll, opencv_ffmpeg300.dll, and opencv_ffmpeg300_64.dll (for the x64 version). Is there anything else I can try to fix this?

Thanks for any help

Community
  • 1
  • 1
user1938805
  • 81
  • 1
  • 1
  • 4
  • I would suggest you two things here: First try running your python script from Terminal instead of Anaconda. Secondly try using a full qualified path to your video file instead of `"small.mp4"` – ZdaR May 01 '17 at 06:27

1 Answers1

-1

If you downloaded opencv from menpo(or default conda) channel(using 'conda install --channel https://conda.anaconda.org/menpo opencv3' ), it might not work as some video processing dependencies such as ffmpeg are not present.

You need to download opencv from 'conda-forge' channel which contains latest and additional packages and dependencies for video processing. Try the following:

conda install -c conda-forge ffmpeg

conda install -c conda-forge opencv

Here -c tells the channel to use as 'conda-forge'.

Renil Joseph
  • 163
  • 3
  • 11