The timeout setting on av.open() doesn't work as expected (for RTSP streams)
Created by: CarlosRDomin
Overview
When I connect to my rtsp camera with a given timeout (e.g. 3s), the call to av.open()
blocks indefinitely if the camera accepts the connection but doesn't start streaming
Expected behavior
After the timeout expires (e.g. 3s) the function call should return with an error/exception
Actual behavior
The call to av.open()
hangs indefinitely and I have to kill -s 9 python
to stop the process.
Investigation
My RTSP camera only accepts 3 simultaneous clients receiving the stream. If (by accident) a 4th client attempts to connect, it will successfully communicate with the camera, but no stream is sent, which (after adding some logs on av/container/core.pyx
) causes line 234 (self.set_timeout(None)
) to clear the timeout and therefore the call to av.open
hangs forever.
By commenting out line 234 (not sure why the timeout is cleared anyway or where the execution hangs after line 234 to cause that infinite block), av.open
successfully returns after the specified timeout if it wasn't able to open. In my case, it actually outputs some nice error messages:
Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Versions
- OS: Ubuntu 18.04 (on docker image)
- PyAV runtime:
PyAV v7.0.0.dev0
git origin: git@github.com:mikeboers/PyAV
git commit: v6.2.0-117-g5d192a1
library configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
library license: GPL version 2 or later
libavcodec 57.107.100
libavdevice 57. 10.100
libavfilter 6.107.100
libavformat 57. 83.100
libavutil 55. 78.100
libswresample 2. 9.100
libswscale 4. 8.100
- PyAV build:
PyAV: 7.0.0.dev0 v6.2.0-117-g5d192a1
Python: 3.6.7 (default, Oct 22 2018, 11:32:17) \n[GCC 8.2.0]
platform: Linux-4.9.184-linuxkit-x86_64-with-Ubuntu-18.04-bionic
extension_extra:
include_dirs: [b'include', b'/usr/include/x86_64-linux-gnu']
libraries: [b'avformat', b'avcodec', b'avdevice', b'avutil', b'avfilter', b'swscale', b'swresample']
library_dirs: []
define_macros: []
runtime_library_dirs: []
config_macros:
PYAV_COMMIT_STR="v6.2.0-117-g5d192a1"
PYAV_VERSION=7.0.0.dev0
PYAV_VERSION_STR="7.0.0.dev0"
- FFmpeg:
bash: ffmpeg: command not found
Research
I have done the following:
-
Checked the PyAV documentation -
Searched on Google -
Searched on Stack Overflow -
Looked through old GitHub issues -
Asked on PyAV Gitter -
... and waited 72 hours for a response.
Additional context
See above as to when the timeout doesn't work as expected (when the camera reaches the maximum number of simultaneous streams)