Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

av.open(timeout) is capped at 20 seconds #1155

Open
4 of 6 tasks
Pnaop opened this issue Aug 21, 2023 · 0 comments
Open
4 of 6 tasks

av.open(timeout) is capped at 20 seconds #1155

Pnaop opened this issue Aug 21, 2023 · 0 comments
Labels

Comments

@Pnaop
Copy link

Pnaop commented Aug 21, 2023

Overview

I am using an SDP file to stream RTP to pyav. I get the frames in a thread.

The timeout argument for av.open() seems to be capped at around 20 seconds. I need to be able to wait for a period longer than 20 seconds, but the container always times out.

EDIT: While writing this bug report, I did find a possible fix by using the FFmpeg arg listen_timeout.

Expected behavior

I would expect the open en read timeout to be configurable above 20s using the specified (float) values.

Actual behavior

When no stream is available, av.open times out after 20s when a higher time is specified.

Traceback:

Exception in thread Thread-1 (get_frame):
Traceback (most recent call last):
  File "threading.py", line 1016, in _bootstrap_inner
  File "threading.py", line 953, in run
  File "pyav_get_frames.py", line 71, in get_frame
  File "av\container\input.pyx", line 202, in decode
  File "av\container\input.pyx", line 162, in demux
  File "av\container\core.pyx", line 292, in av.container.core.Container.err_check
  File "av\error.pyx", line 336, in av.error.err_check
av.error.UndefinedError: [Errno 138] Error number -138 occurred: 'C:\\dir\\rtpstream.sdp'; last error log: [h264] error while decoding MB 79 36

Investigation

I've tried a selection of values, 3, 5 and 10 all work as expected.
When using a value above 20 (30, 60, etc.), the timeout is still at around 20 seconds.

I have tried to specify the timeout with the ffmpeg args as well: options={"protocol_whitelist": "file,udp,rtp", "timeout":"30000"}

I found that the default value is 20, which I can indeed confirm.

Possible cause/fix:
After reading the commit diff, I tried to use listen_timeout;

# Open the RTP stream.
self.input_video = av.open(sdp_path, options={"protocol_whitelist": "file,udp,rtp", "listen_timeout": "30000"})

And that did work! Note, this is value is probably in seconds for RTP...

Reproduction

rtpstream.sdp:

v=0
c=IN IP4 127.0.0.1
m=video 5000 RTP/AVP 96
a=rtpmap:96 H264/90000

pyav_get_frames.py:

import av
from collections import deque
from threading import Thread

class GetFrames:
    def __init__(self):
        # Setup thread to read frames from the video stream.
        self.thread = None
        self.input_video = None
        self.deque = deque(maxlen=2)

    def start_streaming(self, sdp_path):
        # Open the RTP stream.
        self.input_video = av.open(sdp_path, options={"protocol_whitelist": "file,udp,rtp"}, timeout=30.0)

        stream = self.input_video.streams.video[0]
        stream.codec_context.skip_frame = "NONKEY"

        # Get one frame to initialize the buffer.
        self.get_frame(once=True)

        # Setup thread to read frames from the video stream.
        self.thread = Thread(target=self.get_frame, args=(), daemon=True)
        self.thread.start()
   
    def get_frame(self, once=False):
        for frame in self.input_video.decode():
            self.deque.append(frame)  # Circular buffer
            if once:
                return

I handle the frames in the buffer elsewhere.

Versions

  • OS: Windows 10 22H2
  • PyAV runtime:
PyAV v10.0.0
library configuration: --disable-static --enable-shared --libdir=/c/cibw/vendor/lib --prefix=/c/cibw/vendor --disable-alsa --disable-doc --disable-mediafoundation --enable-fontconfig --enable-gmp --disable-gnutls --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --disable-libxcb --enable-libxml2 --enable-libxvid --enable-lzma --enable-version3 --enable-zlib
library license: GPL version 3 or later
libavcodec     59. 37.100
libavdevice    59.  7.100
libavfilter     8. 44.100
libavformat    59. 27.100
libavutil      57. 28.100
libswresample   4.  7.100
libswscale      6.  7.100
  • FFmpeg:
ffmpeg version N-109165-g9f5a9a7499-20221122 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 12.2.0 (crosstool-NG 1.25.0.90_cf9beb1)
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --disable-avisynth --enable-chromaprint --enable-libdav1d --disable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --disable-frei0r --enable-libgme --enable-libkvazaar --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --disable-libmfx --enable-libvpl --enable-openal --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --disable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --disable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --disable-libx264 --disable-libx265 --disable-libxavs2 --disable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20221122
libavutil      57. 43.100 / 57. 43.100
libavcodec     59. 54.100 / 59. 54.100
libavformat    59. 34.101 / 59. 34.101
libavdevice    59.  8.101 / 59.  8.101
libavfilter     8. 50.101 /  8. 50.101
libswscale      6.  8.112 /  6.  8.112
libswresample   4.  9.100 /  4.  9.100

Research

I have done the following:

Additional context

@Pnaop Pnaop added the bug label Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant