How to compile OpenCV with Gstreamer [Ubuntu&Windows]

Galaktyk 01
Mar 16 · 4 min read

## Ubuntu

Ubuntu 16.04
Python 3.7
OpenCV 4.1.0
Gstreamer 1.8.3
Cmake 3.5.1

1. install gstreamer1.0

sudo apt-get install gstreamer1.0*
sudo apt install ubuntu-restricted-extras

2. install lib, dev package

sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

3. install numpy

I recommend to use conda or virtualenv over the native one, in case we mess things up.

source activate <your_env>
pip install numpy

4. Clone OpenCV repo

git clone
cd opencv/
git checkout 4.1.0

5. Building

mkdir build
cd build
-D PYTHON_EXECUTABLE=$(which python3) \
-D BUILD_opencv_python2=OFF \
-D CMAKE_INSTALL_PREFIX=$(python3 -c “import sys; print(sys.prefix)”) \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D PYTHON3_INCLUDE_DIR=$(python3 -c “from distutils.sysconfig import get_python_inc; print(get_python_inc())”) \
-D PYTHON3_PACKAGES_PATH=$(python3 -c “from distutils.sysconfig import get_python_lib; print(get_python_lib())”) \
After finished the configuration, Go check GStreamer and Python section

6. Check your log

✔ check if it has Python 3: section and all interpreter and path are right.
(If they aren’t there, check the numpy package)

✔ check the GStreamer section.
(If they aren’t say YES, go check GStreamer lib package)

if something went wrong just remove build folder and try again.

7. Building

sudo make -j$(nproc)
It will take a long time, Go grab some coffee. ☕

◾ Install package

sudo make install
sudo ldconfig


Windows 10 1903
python 3.7
OpenCV 4.1.0
Gstreamer 1.16.4
Cmake 3.14.5
Visual Studio 2019

1. Have python3 and numpy installed

I recommend to use conda or virtualenv over the native one, in case we mess things up.

pip install numpy

2. Download gstreamer and opencv

◾ Install both gstreamer-runtime and gstreamer-development package in the same location

◾ Download opencv release sources (.zip file) and extract.

3. Set Path Variable

◾ Add “your” Python Environment to Path.

example: this is my python in conda

◾ Add “your” gstreamer to Path


◾ Add system variable “GSTREAMER_DIR” “C:\gstreamer\1.0\x86_64”

5. CmakeGUI & Visual Studio

◾ install CmakeGUI 3.14.5
CmakeGUI >>

Visual Studio 2019(Community version is fine)

◾ Open CmakeGUI.
◾ Select opencv source and build folder .

◾ Hit Configure, select your Visual Studio version then click Finish

Check the GStreamer and Python 3 section. ✔

◾ Click Configure again, The red value will change to white.

◾ Click Generate

◾ click “Open Project”

◾ in Visual Studio:
switch from DEBUG to RELEASE and x64

◾ Right click on INSTALL and select Build


◾ Finally, add bin & lib folder to PATH, located in C:\opencv-4.1.0\build\install\x64\vc16


import cv2
cap = cv2.VideoCapture('autovideosrc ! videoconvert ! appsink')
while True:
ret,frame =
if cv2.waitKey(1) & 0xFF == ord('q'):
Enjoy 🐔

Galaktyk 01

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade