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

fix: only use the first line of ffprobe's output #120

Merged
merged 2 commits into from
Mar 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions streamer/autodetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -167,4 +170,4 @@ def get_channel_layout(input: Input) -> Optional[AudioChannelLayoutName]:
if channel_count <= bucket.max_channels:
return bucket.get_key()

return None
return None