build opencv with ffmpeg support

asked 2017-12-21 02:10:34 -0600

selingok gravatar image

I read nearly all of the questions about this subject but I didn't solve it. I am working on Linux/Mint. I installed OpenCV in the virtual environment a lot of times when trying to solve this problem. Problem is that: "cv2.videoCapture() return always false".

I built the OpenCV with -D WITH_FFMPEG=ON option and it would finish successfully and the result that about FFmpeg was seemed to be OK.

Also, when I run "make -j8" command, it finished with no problem. So I thought everything will be OK. When I tried to check FFmpeg support with this command:

python -c "import cv2; print(cv2.getBuildInformation())" | grep -i FFmpeg

it gave me NO result.

I installed OpenCV with following these steps. I also tried to find if FFMPEG supports codec for decoding AVC encoded files. ffmpeg -codecs | grep -i avc and, the output is :

DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_cuvid ) (encoders: h264_nvenc nvenc nvenc_h264 ) D.A.L. avc On2 Audio for Video Codec (decoders: on2avc )

I didn't understand why FFmpeg has seemed "YES" when I have building OpenCV at that time has given "NO" result with cv2.getBuildInformation().

(cv_env)➜ cv_env pkg-config --modversion opencv 3.2.0 (cv_env)➜ cv_env python Python 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import cv2 cv2.__version__ '3.3.0'

(cv_env)➜ cv_env python -c "import cv2; print(cv2.getBuildInformation())" | grep -i ffmpeg FFMPEG: NO (cv_env)➜ cv_env python Python 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import cv2 cv2.__file__ '/opt/cv_env/local/lib/python2.7/site-packages/cv2/cv2.so'

(cv_env)➜ cv_env python3 Python 3.4.3 (default, Nov 28 2017, 16:41:13) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information.

import cv2 cv2.__version__ '3.3.0' cv2.__file__ '/usr/local/lib/python3.4/dist-packages/cv2/cv2.cpython-34m.so'

Also, I didn't remember which steps I applied (for python2 or python3). For that reason, I added cv2 versions and paths. I checked cv2.version after import cv2, and it seems '3.3.0' also pip freeze result like that. I cloned OpenCV from github like these steps which I gave the url to my question. After following these steps, version should be 3.3.1 but it still seems 3.3.0. If I imported prebuilt opencv, how can I fix it? In my virtual env has just one OpenCV directory and I think it is the last one which I installed.

It sounds like I am launching Python2, which has the other version of OpenCV installed, not 3.3.1. How can I fix it?

edit retag flag offensive close merge delete

Comments

Did you installed both python and python3?

supra56 gravatar imagesupra56 ( 2017-12-21 05:23:32 -0600 )edit

It should be like this: python -c "import cv2; print(cv2.getBuildInformation())"

supra56 gravatar imagesupra56 ( 2017-12-21 05:45:49 -0600 )edit