I am pretty new (only two days old) in the whole streaming and capture world. What I am trying to do is to capture a video stream from a UDP port using OpenCV and Python. I want my script to run inside a Docker container. I have created a docker container based on Fedora and installed Python3.6.5, OpenCV in it. The OpenCV has been compiled from source with the following options -
cmake -DBUILD_TIFF=ON \
-DBUILD_WEBP=ON \
-DBUILD_opencv_java=OFF \
-DWITH_CUDA=OFF \
-DENABLE_AVX=ON \
-DWITH_OPENGL=ON \
-DWITH_OPENCL=ON \
-DWITH_IPP=ON \
-DWITH_TBB=ON \
-DWITH_GSTREAMER=ON \
-DWITH_EIGEN=ON \
-DWITH_V4L=ON \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") \
-DPYTHON_EXECUTABLE=$(which python) \
-DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-DPYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-DWITH_FFMPEG=ON \
-DWITH_GTK_2_X=ON \
-DBUILD_PNG=ON \
-DBUILD_JASPER=ON \
-DBUILD_JPEG=ON \
-DWITH_V4L=ON .. \
I have checked the UDP port using the following command -
tcpdump -i lo -n udp port <port_number>
It seems that it is receiving packets properly. No problem in that.
I have the following script inside my container to read frames from the udpsrc
import cv2
gst_string = "udpsrc port=<port_number> caps=\"application/x-rtp, media=(string)video, clock-rate=(int)90000\" ! rtpvp8depay ! vp8dec ! videoconvert ! appsink"
video_capture = cv2.VideoCapture(gst_string)
while video_capture.isOpened():
ret, frame = video_capture.read()
print("Frame received {}".format(ret))
And I am starting my docker container using the following command -
docker run -it -p <port_number>:<port_number>/udp myworker /bin/bash
And finally when from the bash prompt I am starting the script using python worker.py
it is not going into the loop as the video_capture.isOpened()
is returning False.
I have very little experience to all the things involved here (apart from Python and to some extent Docker) so I am unable to find out what I am doing wrong. Please help me.
Thanks in advance
EDIT ----------------
For further info, I had installed the following plugings to gstreamer -
yum install -y libnice-gstreamer1 \
gstreamer-plugins-good \
gstreamer1-plugins-ugly \
gstreamer1-plugins-good \
gstreamer-plugins-bad-free-extras \
gstreamer-plugins-espeak gstreamer \
gstreamer1 \
gstreamer1-plugins-base-tools \
gstreamer1-plugins-bad-free-extras \
gstreamer1-plugins-bad-freeworld \
gstreamer-plugins-bad-free \
gstreamer1-plugins-base \
gstreamer1-plugins-good-extras \
gstreamer-plugins-base gstreamer-tools \
PackageKit-gstreamer-plugin \
gstreamer1-plugins-bad-free
EDIT -2 ---------------------------------
As mentioned in the comments, the OpenCV i was using did not have Gstreamer compiled inside it. So I was not able to open the Videocapture. So the yum
command from above eventually becomes -
RUN yum install -y libnice-gstreamer1 \
gstreamer1-plugins-ugly \
gstreamer1-plugins-good \
gstreamer1 \
gstreamer1-plugins-base-devel \
gstreamer-plugins-base-tools \
gstreamer1-plugins-bad-free-extras \
gstreamer1-plugins-bad-freeworld \
gstreamer1-plugins-base \
gstreamer1-plugins-good-extras \
gstreamer1-plugins-base \
gstreamer1-plugins-bad-free \
gstreamer-plugins-base-devel
Et voila! This did the trick.