Read rtmp stream of localhost, with cv2.VideoCapture, inside docker container

  docker, opencv, python, streaming

How to read a rtmp stream being streamed by ffmpeg (through nginx acting as the server) to rtmp://localhost/live/test inside a docker container?

In the host machine we have nginx running with

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            record off;
            allow publish;
            deny publish all;

ffmpeg is then able to stream to rtmp://localhost/live/test with ffmpeg -stream_loop -1 -i /mnt/home/dario/0470_2020-02-01.mp4 -f flv rtmp://localhost/live/test

In the host machine import cv2; cv2.VideoCapture(rtmp://localhost/live/test) opens fine

In docker container, it does not, giving error

[ERROR:0] global /tmp/pip-build-owknk7mx/opencv-python/opencv/modules/videoio/src/cap.cpp (142) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.4.0) /tmp/pip-build-owknk7mx/opencv-python/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): rtmp://localhost/live/test in function 'icvExtractPattern'

Docker container started with sudo docker run --net="host" --name adrun4 --gpus=all -t -i ad_running bash

--net="host" makes netstat -tap show all the open ports, namely the

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name                                                                                                               
tcp        0      0  *               LISTEN      -           

Source: Docker Questions