From 8a137f239042394fbc25ccda54e231df558dd0e9 Mon Sep 17 00:00:00 2001 From: karoldob <51451383+karoldob@users.noreply.github.com> Date: Tue, 26 Apr 2022 20:39:45 +0200 Subject: [PATCH 1/2] Allow to read start_time_realtime from AVFormat in input stream. --- av/container/input.pyx | 12 ++++++++++++ include/libavformat/avformat.pxd | 1 + tests/test_rtspstarttimerealtime.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/test_rtspstarttimerealtime.py diff --git a/av/container/input.pyx b/av/container/input.pyx index e508f16f4..55c4cb9b3 100644 --- a/av/container/input.pyx +++ b/av/container/input.pyx @@ -93,6 +93,18 @@ cdef class InputContainer(Container): if self.ptr.start_time != lib.AV_NOPTS_VALUE: return self.ptr.start_time + property start_time_realtime: + """ + Start time of the RTSP stream, expressed as microseconds since the UNIX epoch. + + This property might not be set by FFmpeg for the first packets. + + :type: int + """ + def __get__(self): + if self.ptr.start_time_realtime != lib.AV_NOPTS_VALUE: + return self.ptr.start_time_realtime + property duration: def __get__(self): if self.ptr.duration != lib.AV_NOPTS_VALUE: diff --git a/include/libavformat/avformat.pxd b/include/libavformat/avformat.pxd index ed3e503f5..ba01ce9bc 100644 --- a/include/libavformat/avformat.pxd +++ b/include/libavformat/avformat.pxd @@ -184,6 +184,7 @@ cdef extern from "libavformat/avformat.h" nogil: int flags int64_t max_analyze_duration + int64_t start_time_realtime void *opaque diff --git a/tests/test_rtspstarttimerealtime.py b/tests/test_rtspstarttimerealtime.py new file mode 100644 index 000000000..7af421938 --- /dev/null +++ b/tests/test_rtspstarttimerealtime.py @@ -0,0 +1,28 @@ +import av + +from .common import TestCase + + +# RTSP stream server, thanks https://github.com/rtspstream +RTSP_STREAM = "rtsp://rtsp.stream/pattern" +UNIX_TIMESTAMP_2022_01_01_00_00 = 1640995200000000 # microseconds + + +class TestRTSPStartTimeRealtime(TestCase): + def test_rtsp_start_time_realtime(self): + stream_options = { + 'rtsp_transport': 'tcp', # preferred stable connection + 'stimeout': '5000000' # socket timeout to 5s (default is unlimited) + } + with av.open(RTSP_STREAM, mode="r", options=stream_options) as container: + # wait for proper value set by RTSP in libavformat + while container.demux(container.streams.video[0]): + # it is okay to have None type at first dozens packets + if container.start_time_realtime is None: + continue + # Now value is ready, check this and go outside loop + else: + self.assertIsInstance(container.start_time_realtime, int) + break + + self.assertGreater(container.start_time_realtime, UNIX_TIMESTAMP_2022_01_01_00_00) From 32e7a8d39641bdcc8ea2d724f957489355e0bd8e Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Sat, 25 Nov 2023 03:04:28 -0500 Subject: [PATCH 2/2] Dummy commit --- av/__main__.py | 2 -- av/datasets.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/av/__main__.py b/av/__main__.py index 8c57e2dd9..b5718ba8b 100644 --- a/av/__main__.py +++ b/av/__main__.py @@ -2,7 +2,6 @@ def main(): - parser = argparse.ArgumentParser() parser.add_argument("--codecs", action="store_true") parser.add_argument("--version", action="store_true") @@ -11,7 +10,6 @@ def main(): # --- if args.version: - import av import av._core diff --git a/av/datasets.py b/av/datasets.py index 3324ce0bc..b3a5eed85 100644 --- a/av/datasets.py +++ b/av/datasets.py @@ -9,7 +9,6 @@ def iter_data_dirs(check_writable=False): - try: yield os.environ["PYAV_TESTDATA_DIR"] except KeyError: @@ -45,7 +44,6 @@ def iter_data_dirs(check_writable=False): def cached_download(url, name): - """Download the data at a URL, and cache it under the given name. The file is stored under `pyav/test` with the given name in the directory