Skip to content

Commit 8b596d0

Browse files
authored
Linux FFmpeg + libjpeg-turbo builds (opencv#59)
* try new images, make sure that ffmpeg is built as LGPL library * prepend ~/bin to PATH * enable linux video test * add ffmpeg pkg config location * cherry-pick FFmpeg fix from OpenCV upstream * add FFmpeg lib path to linker flags * add also libjepg-turbo * add additional flags * add missing $ * update READMEs * enable all video tests
1 parent 731e0d4 commit 8b596d0

File tree

4 files changed

+48
-34
lines changed

4 files changed

+48
-34
lines changed

README.rst

+2-12
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ This enables super fast (usually < 10 seconds) OpenCV installation for Python.
1111

1212
If you need only OpenCV Python bindings, no separate OpenCV installation is required.
1313

14-
**IMPORTANT NOTE**
15-
16-
MacOS and Linux packages do not support video related functionality (not compiled with FFmpeg).
17-
1814
Installation and Usage
1915
----------------------
2016

@@ -49,7 +45,7 @@ A: The wheel package format and manylinux builds are pretty new things. Most lik
4945

5046
**Q: I need contrib modules?**
5147

52-
A: Please install `opencv-contrib-python <https://pypi.python.org/pypi/opencv-contrib-python>`__ instead. However, note that commercial usage might be restricted in some countries since the contrib modules contain some non-free/patented algorithms.
48+
A: Please install `opencv-contrib-python <https://pypi.python.org/pypi/opencv-contrib-python>`__ instead. However, note that commercial usage might be restricted in some countries since the contrib modules might contain some non-free/patented algorithms.
5349

5450
**Q: Import fails on Windows to some DLL load error?**
5551

@@ -61,12 +57,6 @@ See also `this issue <https://github.com/skvark/opencv-python/issues/36>`__ if y
6157

6258
A: Make sure you have removed old manual installations of OpenCV Python bindings (cv2.so or cv2.pyd in site-packages).
6359

64-
**Q: Why I can't open video files on GNU/Linux distribution X or on macOS?**
65-
66-
A: OpenCV video I/O depends heavily on FFmpeg. Manylinux and macOS OpenCV binaries are not compiled against it.
67-
The purpose of these packages is to provide as easy as possible installation experience for OpenCV Python bindings and they should work directly out-of-the-box.
68-
Adding FFmpeg as an additional dependency without a "universal" FFmpeg build (e.g. LGPL licensed build like in the Windows wheels) the goal is considerably harder to achieve. This might change in the future.
69-
7060
Documentation for opencv-python
7161
-------------------------------
7262

@@ -139,7 +129,7 @@ OpenCV itself is available under `3-clause BSD
139129
License <https://github.com/opencv/opencv/blob/master/LICENSE>`__
140130
(`LICENSE-3RD-PARTY.txt <https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt>`__).
141131

142-
Windows wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
132+
All wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
143133

144134
Linux and MacOS wheels ship with `Qt 4.8.7 <http://doc.qt.io/qt-4.8/lgpl.html>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
145135

README_CONTRIB.rst

+2-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ OpenCV on Wheels
33

44
**Unofficial** OpenCV packages for Python with contrib modules.
55

6-
**Note: the usage of opencv-contrib-python might be restricted in some countries since the contrib package contains some patented algorithms/non-free modules.**
6+
**Note: the (commercial) usage of opencv-contrib-python might be restricted in some countries since the contrib package might contain some patented algorithms/non-free modules.**
77

88
If you are looking for a version without the contrib modules, please install `opencv-python <https://pypi.python.org/pypi/opencv-python>`__ instead.
99

@@ -12,10 +12,6 @@ This enables super fast (usually < 10 seconds) OpenCV installation for Python.
1212

1313
If you need only OpenCV Python bindings, no separate OpenCV installation is required.
1414

15-
**IMPORTANT NOTE**
16-
17-
MacOS and Linux wheels do not support video related functionality (not compiled with FFmpeg).
18-
1915
Installation and Usage
2016
----------------------
2117

@@ -57,12 +53,6 @@ See also `this issue <https://github.com/skvark/opencv-python/issues/36>`__ if y
5753

5854
A: Make sure you have removed old manual installations of OpenCV Python bindings (cv2.so or cv2.pyd in site-packages).
5955

60-
**Q: Why I can't open video files on GNU/Linux distribution X or on macOS?**
61-
62-
A: OpenCV video I/O depends heavily on FFmpeg. Manylinux and macOS OpenCV binaries provided withing these packages are not compiled against it.
63-
The purpose of these packages is to provide as easy as possible installation experience for OpenCV Python bindings and they should work directly out-of-the-box.
64-
Adding FFmpeg as an additional dependency without a "universal" FFmpeg build (e.g. LGPL licensed build like in the Windows wheels) the goal is considerably harder to achieve. This might change in the future.
65-
6656
Documentation for opencv-python
6757
-------------------------------
6858

@@ -135,7 +125,7 @@ OpenCV itself is available under `3-clause BSD
135125
License <https://github.com/opencv/opencv/blob/master/LICENSE>`__
136126
(`LICENSE-3RD-PARTY.txt <https://github.com/skvark/opencv-python/blob/master/LICENSE-3RD-PARTY.txt>`__).
137127

138-
Windows wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
128+
All wheels ship with `FFmpeg <http://ffmpeg.org>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
139129

140130
Linux and MacOS wheels ship with `Qt 4.8.7 <http://doc.qt.io/qt-4.8/lgpl.html>`__ licensed under the `LGPLv2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__.
141131

tests/test.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
2-
import os
2+
import sys
3+
34

45
class OpenCVTest(unittest.TestCase):
56
""" Simple functionality tests. """
@@ -10,8 +11,6 @@ def test_import(self):
1011

1112
def test_video_capture(self):
1213

13-
if os.name != 'posix':
14-
import cv2
15-
16-
cap = cv2.VideoCapture("SampleVideo_1280x720_1mb.mp4")
17-
self.assertTrue(cap.isOpened())
14+
import cv2
15+
cap = cv2.VideoCapture("SampleVideo_1280x720_1mb.mp4")
16+
self.assertTrue(cap.isOpened())

travis/build-wheels.sh

+39-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,27 @@ echo "Python numpy version: $PYTHON_NUMPY_VERSION"
2626
# Begin build
2727
echo 'Begin build'
2828
cd opencv
29+
30+
# FFmpeg version is too new.
31+
# This is a temporary fix from upstream until we have a new OpenCV release.
32+
git cherry-pick b1d208891b9f
33+
2934
mkdir build
3035

36+
export JPEG_INCLUDE_DIR="/opt/libjpeg-turbo/include"
37+
export JPEG_LIBRARY="/opt/libjpeg-turbo/lib32/libjpeg.a"
38+
39+
MACHINE_TYPE=$(uname -m)
40+
if [[ ${MACHINE_TYPE} == 'x86_64' ]]; then
41+
JPEG_LIBRARY="/opt/libjpeg-turbo/lib64/libjpeg.a"
42+
fi
43+
44+
export LDFLAGS=-L/root/ffmpeg_build/lib
45+
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/root/ffmpeg_build/lib/pkgconfig
46+
export PATH=~/bin:$PATH
47+
48+
ffmpeg -L
49+
3150
export QTDIR=/opt/Qt4.8.7
3251
export PATH=$QTDIR/bin:$PATH
3352

@@ -45,7 +64,11 @@ if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
4564
-DPYTHON2_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
4665
-DPYTHON2_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
4766
-DPYTHON2_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
48-
-DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION"
67+
-DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
68+
-DWITH_JPEG=ON \
69+
-DBUILD_JPEG=OFF \
70+
-DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
71+
-DJPEG_LIBRARY="$JPEG_LIBRARY"
4972

5073
fi
5174

@@ -61,7 +84,11 @@ if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 0 ]]; then
6184
-DPYTHON3_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
6285
-DPYTHON3_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
6386
-DPYTHON3_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
64-
-DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION"
87+
-DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
88+
-DWITH_JPEG=ON \
89+
-DBUILD_JPEG=OFF \
90+
-DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
91+
-DJPEG_LIBRARY="$JPEG_LIBRARY"
6592

6693
fi
6794

@@ -77,7 +104,11 @@ if [[ $PYTHON_VERSION == 2* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
77104
-DPYTHON2_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
78105
-DPYTHON2_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
79106
-DPYTHON2_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
80-
-DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION"
107+
-DPYTHON2_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
108+
-DWITH_JPEG=ON \
109+
-DBUILD_JPEG=OFF \
110+
-DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
111+
-DJPEG_LIBRARY="$JPEG_LIBRARY"
81112

82113
fi
83114

@@ -93,7 +124,11 @@ if [[ $PYTHON_VERSION == 3* ]] && [[ $ENABLE_CONTRIB == 1 ]]; then
93124
-DPYTHON3_INCLUDE_PATH="$PYTHON_INCLUDE_PATH" \
94125
-DPYTHON3_PACKAGES_PATH="$PYTHON_PACKAGES_PATH" \
95126
-DPYTHON3_NUMPY_INCLUDE_DIRS="$PYTHON_NUMPY_INCLUDE_DIRS" \
96-
-DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION"
127+
-DPYTHON3_NUMPY_VERSION="$PYTHON_NUMPY_VERSION" \
128+
-DWITH_JPEG=ON \
129+
-DBUILD_JPEG=OFF \
130+
-DJPEG_INCLUDE_DIR="$JPEG_INCLUDE_DIR" \
131+
-DJPEG_LIBRARY="$JPEG_LIBRARY"
97132

98133
fi
99134

0 commit comments

Comments
 (0)