From 4d7d077e270474f99a2c6851133e8b97b738e990 Mon Sep 17 00:00:00 2001 From: mariocynicys Date: Wed, 9 Mar 2022 21:23:16 +0200 Subject: [PATCH] fix: only use the first line of ffprobe's output (#120) With some container formats (such as `ts`), ffprobe reports the output twice with newline characters in between. This fix is to take into consideration only the first line of ffprobe's output. Closes #119 --- streamer/autodetect.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/streamer/autodetect.py b/streamer/autodetect.py index f774f98..0b3af44 100644 --- a/streamer/autodetect.py +++ b/streamer/autodetect.py @@ -68,17 +68,20 @@ def _probe(input: Input, field: str) -> Optional[str]: print('+ ' + ' '.join([shlex.quote(arg) for arg in args])) output_bytes: bytes = subprocess.check_output(args, stderr=subprocess.DEVNULL) - # The output is either the language code or just a blank line. - output_string: Optional[str] = output_bytes.decode('utf-8').strip() + # The output is either some probe information or just a blank line. + output_string: str = output_bytes.decode('utf-8').strip() + # With certain container formats, ffprobe returns a duplicate + # output and some empty lines in between. Issue #119 + output_string = output_string.split('\n')[0] # After stripping the newline, we can fall back to None if it's empty. - output_string = output_string or None + probe_output: Optional[str] = output_string or None # Webcams on Linux seem to behave badly if the device is rapidly opened and # closed. Therefore, sleep for 1 second after a webcam probe. if input.input_type == InputType.WEBCAM: time.sleep(1) - return output_string + return probe_output def is_present(input: Input) -> bool: """Returns true if the stream for this input is indeed found. @@ -167,4 +170,4 @@ def get_channel_layout(input: Input) -> Optional[AudioChannelLayoutName]: if channel_count <= bucket.max_channels: return bucket.get_key() - return None \ No newline at end of file + return None