Repository: streamlink/streamlink

Issue:
Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']
### Checklist

- [X] This is a bug report and not a different kind of issue
- [X] [I have read the contribution guidelines](https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#contributing-to-streamlink)
- [X] [I have checked the list of open and recently closed bug reports](https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22bug%22)
- [X] [I have checked the commit log of the master branch](https://github.com/streamlink/streamlink/commits/master)

### Streamlink version

Latest stable release

### Description

FFmpeg binary not validated.
Streamlink version 6.0.0.0 Linux Appimage x86_64
Got this error message:

[stream.ffmpegmux][error] Could not validate FFmpeg!
[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']
[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.
[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!

ffmpeg output:
ffmpeg -version
ffmpeg version 6.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)

ffmpeg is in /usr/bin

### Debug log

```text
[utils.l10n][debug] Language code: en_US
[stream.ffmpegmux][error] Could not validate FFmpeg!
[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']
[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.
[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!
[cli][info] Available streams: 234p_alt (worst), 234p, 360p_alt2, 360p_alt, 360p, 540p, 720p_alt, 720p, 1080p (best)
[cli][info] Opening stream: 720p (hls)
[cli][info] Starting player: mpv
[stream.hls][debug] Reloading playlist
[cli][debug] Pre-buffering 8192 bytes
[stream.hls][debug] Segments in this playlist are encrypted
[stream.hls][debug] First Sequence: 22258880; Last Sequence: 22259722
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 22259720; End Sequence: None
[stream.hls][debug] Adding segment 22259720 to queue
[stream.hls][debug] Adding segment 22259721 to queue
[stream.hls][debug] Adding segment 22259722 to queue
[stream.hls][debug] Writing segment 22259720 to output
[stream.hls][debug] Segment 22259720 complete
```

Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']
### Checklist

- [X] This is a bug report and not a different kind of issue
- [X] [I have read the contribution guidelines](https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#contributing-to-streamlink)
- [X] [I have checked the list of open and recently closed bug reports](https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22bug%22)
- [X] [I have checked the commit log of the master branch](https://github.com/streamlink/streamlink/commits/master)

### Streamlink version

Latest stable release

### Description

FFmpeg binary not validated.
Streamlink version 6.0.0.0 Linux Appimage x86_64
Got this error message:

[stream.ffmpegmux][error] Could not validate FFmpeg!
[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']
[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.
[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!

ffmpeg output:
ffmpeg -version
ffmpeg version 6.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)

ffmpeg is in /usr/bin

### Debug log

```text
[utils.l10n][debug] Language code: en_US
[stream.ffmpegmux][error] Could not validate FFmpeg!
[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']
[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.
[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!
[cli][info] Available streams: 234p_alt (worst), 234p, 360p_alt2, 360p_alt, 360p, 540p, 720p_alt, 720p, 1080p (best)
[cli][info] Opening stream: 720p (hls)
[cli][info] Starting player: mpv
[stream.hls][debug] Reloading playlist
[cli][debug] Pre-buffering 8192 bytes
[stream.hls][debug] Segments in this playlist are encrypted
[stream.hls][debug] First Sequence: 22258880; Last Sequence: 22259722
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 22259720; End Sequence: None
[stream.hls][debug] Adding segment 22259720 to queue
[stream.hls][debug] Adding segment 22259721 to queue
[stream.hls][debug] Adding segment 22259722 to queue
[stream.hls][debug] Writing segment 22259720 to output
[stream.hls][debug] Segment 22259720 complete
```



Discussion:
You've removed parts of the debug log, so it's unclear which ffmpeg binary you've actually set.

Streamlink checks the first line of the stdout stream when running `ffmpeg -version`, as you can see here:
https://github.com/streamlink/streamlink/blob/6.0.0/src/streamlink/stream/ffmpegmux.py#L261-L267

The output of these custom-built ffmpeg binaries works just fine:

```
$ ./ffmpeg-6.0-amd64-static/ffmpeg -version 2>/dev/null | head -n1
ffmpeg version 6.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2023 the FFmpeg developers
```

Output from a temp docker container running the ffmpeg binary:

```
$ /opt/python/cp311-cp311/bin/python -m streamlink --loglevel=debug --output=/dev/null --ffmpeg-ffmpeg=/ffmpeg/ffmpeg-6.0-amd64-static/ffmpeg https://steamcommunity.com/broadcast/watch/76561199514732246 best
[cli][info] streamlink is running as root! Be careful!
[cli][debug] OS:         Linux-6.4.6-1-git-x86_64-with-glibc2.17
[cli][debug] Python:     3.11.4
[cli][debug] Streamlink: 6.0.0
[cli][debug] Dependencies:
[cli][debug]  certifi: 2023.7.22
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 4.9.3
[cli][debug]  pycountry: 22.3.5
[cli][debug]  pycryptodome: 3.18.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.31.0
[cli][debug]  trio: 0.22.2
[cli][debug]  trio-websocket: 0.10.3
[cli][debug]  typing-extensions: 4.7.1
[cli][debug]  urllib3: 2.0.4
[cli][debug]  websocket-client: 1.6.1
[cli][debug] Arguments:
[cli][debug]  url=https://steamcommunity.com/broadcast/watch/76561199514732246
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --output=/dev/null
[cli][debug]  --ffmpeg-ffmpeg=/ffmpeg/ffmpeg-6.0-amd64-static/ffmpeg
[cli][info] Found matching plugin steam for URL https://steamcommunity.com/broadcast/watch/76561199514732246
[plugins.steam][debug] Getting broadcast stream: sessionid=d3e4ef22f1a58e991fc13ab4
[utils.l10n][debug] Language code: en_US
[stream.dash][debug] Available languages for DASH audio streams: und (using: und)
[cli][info] Available streams: 360p (worst), 480p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (dash)
[cli][info] Writing output to
/dev/null
[cli][debug] Checking file output
[stream.dash][debug] Opening DASH reader for: ('1', 'video', '1') - video/mp4
[stream.dash][debug] Opening DASH reader for: ('1', 'audio', '1') - audio/mp4
[stream.dash][debug] video/mp4 segment initialization: downloading (2023-07-25T22:09:33.000000Z / 2023-07-27T17:25:15.525464Z)
[stream.dash_manifest][debug] Generating segment numbers for dynamic playlist: ('1', 'video', '1')
[stream.dash_manifest][debug] Stream start: 2023-07-25 22:09:33+00:00
[stream.dash_manifest][debug] Current time: 2023-07-27 17:25:15.523858+00:00
[stream.dash_manifest][debug] Availability: 2023-07-27 17:25:09+00:00
[stream.dash_manifest][debug] presentationTimeOffset: 0:00:00; suggestedPresentationDelay: 0:00:03; minBufferTime: 0:00:03
[stream.dash_manifest][debug] segmentDuration: 2.0; segmentStart: 1; segmentOffset: 77868 (155736.523858s)
[stream.dash][debug] audio/mp4 segment initialization: downloading (2023-07-25T22:09:33.000000Z / 2023-07-27T17:25:15.528351Z)
[stream.dash_manifest][debug] Generating segment numbers for dynamic playlist: ('1', 'audio', '1')
[stream.dash_manifest][debug] Stream start: 2023-07-25 22:09:33+00:00
[stream.dash_manifest][debug] Current time: 2023-07-27 17:25:15.523858+00:00
[stream.dash_manifest][debug] Availability: 2023-07-27 17:25:09+00:00
[stream.dash_manifest][debug] presentationTimeOffset: 0:00:00; suggestedPresentationDelay: 0:00:03; minBufferTime: 0:00:03
[stream.dash_manifest][debug] segmentDuration: 2.0; segmentStart: 1; segmentOffset: 77868 (155736.523858s)
[stream.ffmpegmux][debug] ffmpeg version 6.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2023 the FFmpeg developers
[stream.ffmpegmux][debug]  built with gcc 8 (Debian 8.3.0-6)
[stream.ffmpegmux][debug]  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
[stream.ffmpegmux][debug]  libavutil      58.  2.100 / 58.  2.100
[stream.ffmpegmux][debug]  libavcodec     60.  3.100 / 60.  3.100
[stream.ffmpegmux][debug]  libavformat    60.  3.100 / 60.  3.100
[stream.ffmpegmux][debug]  libavdevice    60.  1.100 / 60.  1.100
[stream.ffmpegmux][debug]  libavfilter     9.  3.100 /  9.  3.100
[stream.ffmpegmux][debug]  libswscale      7.  1.100 /  7.  1.100
[stream.ffmpegmux][debug]  libswresample   4. 10.100 /  4. 10.100
[stream.ffmpegmux][debug]  libpostproc    57.  1.100 / 57.  1.100
[utils.named_pipe][info] Creating pipe streamlinkpipe-53-1-9459
[utils.named_pipe][info] Creating pipe streamlinkpipe-53-2-4204
[stream.ffmpegmux][debug] ffmpeg command: /ffmpeg/ffmpeg-6.0-amd64-static/ffmpeg -nostats -y -i /tmp/streamlinkpipe-53-1-9459 -i /tmp/streamlinkpipe-53-2-4204 -c:v copy -c:a copy -copyts -f matroska pipe:1
[stream.ffmpegmux][debug] Starting copy to pipe: /tmp/streamlinkpipe-53-1-9459
[stream.ffmpegmux][debug] Starting copy to pipe: /tmp/streamlinkpipe-53-2-4204
[cli][debug] Pre-buffering 8192 bytes
[stream.dash][debug] audio/mp4 segment 77869: downloading (2023-07-27T17:25:09.000000Z / 2023-07-27T17:25:15.653844Z)
[stream.dash][debug] audio/mp4 segment initialization: completed
[stream.dash][debug] audio/mp4 segment 77870: downloading (2023-07-27T17:25:11.000000Z / 2023-07-27T17:25:15.695339Z)
[stream.dash][debug] audio/mp4 segment 77869: completed
[stream.dash][debug] audio/mp4 segment 77871: downloading (2023-07-27T17:25:13.000000Z / 2023-07-27T17:25:15.755956Z)
[stream.dash][debug] audio/mp4 segment 77870: completed
[stream.dash][debug] video/mp4 segment 77869: downloading (2023-07-27T17:25:09.000000Z / 2023-07-27T17:25:15.783191Z)
[stream.dash][debug] video/mp4 segment initialization: completed
[stream.dash][debug] audio/mp4 segment 77872: downloading (2023-07-27T17:25:15.000000Z / 2023-07-27T17:25:15.808912Z)
[stream.dash][debug] audio/mp4 segment 77871: completed
[stream.dash][debug] audio/mp4 segment 77873: waiting 1.1s (2023-07-27T17:25:17.000000Z / 2023-07-27T17:25:15.896141Z)
[stream.dash][debug] audio/mp4 segment 77872: completed
[stream.dash][debug] video/mp4 segment 77870: downloading (2023-07-27T17:25:11.000000Z / 2023-07-27T17:25:16.888916Z)
[stream.dash][debug] video/mp4 segment 77869: completed
[stream.dash][debug] audio/mp4 segment 77873: downloading (2023-07-27T17:25:17.000000Z / 2023-07-27T17:25:17.000241Z)
[cli][debug] Writing stream to output
[stream.dash][debug] audio/mp4 segment 77874: waiting 1.8s (2023-07-27T17:25:19.000000Z / 2023-07-27T17:25:17.200659Z)
[stream.dash][debug] audio/mp4 segment 77873: completed
[download] Written 592.00 KiB to /dev/null (0s)                                                                                                 [stream.dash][debug] video/mp4 segment 77871: downloading (2023-07-27T17:25:13.000000Z / 2023-07-27T17:25:17.302594Z)
[stream.dash][debug] video/mp4 segment 77870: completed
^C
[stream.ffmpegmux][debug] Closing ffmpeg thread
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[stream.ffmpegmux][debug] Pipe copy complete: /tmp/streamlinkpipe-53-1-9459
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[stream.ffmpegmux][debug] Pipe copy complete: /tmp/streamlinkpipe-53-2-4204
[stream.dash][debug] audio/mp4 segment 77874: cancelled
[stream.dash][warning] video/mp4 segment 77871: aborted
[stream.ffmpegmux][debug] Closed all the substreams
[cli][info] Stream ended
Interrupted! Exiting...
[cli][info] Closing currently open stream...
```
[cli][debug] OS:         Linux-3.10.0-1062.4.1.el7.x86_64-x86_64-with-glibc2.17
[cli][debug] Python:     3.11.4
[cli][debug] Streamlink: 6.0.0
[cli][debug] Dependencies:
[cli][debug]  certifi: 2023.5.7
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 4.9.2
[cli][debug]  pycountry: 22.3.5
[cli][debug]  pycryptodome: 3.18.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.31.0
[cli][debug]  trio: 0.22.2
[cli][debug]  trio-websocket: 0.10.3
[cli][debug]  typing-extensions: 4.7.1
[cli][debug]  urllib3: 2.0.3
[cli][debug]  websocket-client: 1.6.1
[cli][debug] Arguments:
[cli][debug]  url=XXX
[cli][debug]  --loglevel=debug
[cli][debug]  --player=mpv
[cli][debug]  --player-no-close=True
[cli][debug]  --output=/dev/null
[cli][debug]  --default-stream=['720p', 'best', 'vod']
[cli][debug]  --ringbuffer-size=33554432
[cli][debug]  --stream-segment-attempts=4
[cli][debug]  --stream-segment-timeout=30.0
[cli][debug]  --stream-timeout=60.0
[cli][debug]  --hls-playlist-reload-attempts=4
[cli][debug]  --hls-playlist-reload-time=segment
[cli][debug]  --ffmpeg-ffmpeg=/usr/bin/ffmpeg
[cli][debug]  --http-header=[('User-Agent', '"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36 OPR/62.0.3331.66"'), ('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; rv:114.0) Gecko/20100101 Firefox/114.0')]
[cli][debug]  --twitch-disable-ads=True
[cli][debug]  --twitch-disable-hosting=True
[cli][info] Found matching plugin hls for URL XXX
[plugins.hls][debug] URL=private
[utils.l10n][debug] Language code: en_US
[stream.ffmpegmux][error] Could not validate FFmpeg!
[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']
[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.
[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!
[cli][info] Available streams: 234p_alt (worst), 234p, 360p_alt2, 360p_alt, 360p, 540p, 720p_alt, 720p, 1080p (best)
[cli][info] Opening stream: 720p (hls)
[cli][info] Writing output to
/dev/null
[cli][debug] Checking file output
[stream.hls][debug] Reloading playlist
[cli][debug] Pre-buffering 8192 bytes
[stream.hls][debug] Segments in this playlist are encrypted
[stream.hls][debug] First Sequence: 4946541; Last Sequence: 4947172
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 4947170; End Sequence: None
[stream.hls][debug] Adding segment 4947170 to queue
[stream.hls][debug] Adding segment 4947171 to queue
[stream.hls][debug] Adding segment 4947172 to queue
[stream.hls][debug] Writing segment 4947170 to output
[stream.hls][debug] Segment 4947170 complete
[stream.hls][debug] Writing segment 4947171 to output
[stream.hls][debug] Segment 4947171 complete
[stream.hls][debug] Writing segment 4947172 to output
[stream.hls][debug] Segment 4947172 complete
[cli][debug] Writing stream to output
[download] Written 1.36 MiB to /dev/null (4s @ 303.87 KiB/s)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Segments in this playlist are encrypted
[stream.hls][debug] Adding segment 4947173 to queue
[stream.hls][debug] Writing segment 4947173 to output
[stream.hls][debug] Segment 4947173 complete
[download] Written 1.83 MiB to /dev/null (6s @ 292.90 KiB/s)
^C
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[cli][info] Stream ended
Interrupted! Exiting...
[cli][info] Closing currently open stream...

this is de info Url is a paid service with my personal info...
streamlink --loglevel=debug --output=/dev/null --ffmpeg-ffmpeg=/usr/bin/ffmpeg "XXX.m3u8"

ffmpeg -version 2>/dev/null | head -n1
ffmpeg version 5.1.1-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2022 the FFmpeg developers

This looks like an issue with your ffmpeg binary and not with Streamlink. As I've shown in the link above, Streamlink reads the first line of the stdout stream and tries to match it with the version string regex, which is `^ffmpeg version (\S+)`.

In order for the ffmpeg binary to be considered valid, it must exit with status code 0 and the version string must have matched.
https://github.com/streamlink/streamlink/blob/6.0.0/src/streamlink/stream/ffmpegmux.py#L274-L286

Post the full stdout and stderr output when running ffmpeg (using the absolute path)
```bash
/usr/bin/ffmpeg -version
```
and post its status/exit code
```bash
echo $?
```

----

There's also `--ffmpeg-no-validation` for skipping the validation step:
https://streamlink.github.io/cli.html#cmdoption-ffmpeg-no-validation
/usr/bin/ffmpeg -version
ffmpeg version 5.1.1-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2022 the FFmpeg developers

#echo $?
0
i tried --ffmpeg-no-validation and its now working.

Thank you for the help.
> /usr/bin/ffmpeg -version
> ffmpeg version 5.1.1-static [johnvansickle.com/ffmpeg](https://johnvansickle.com/ffmpeg/) Copyright (c) 2000-2022 the FFmpeg developers

There is no way that `-version` doesn't also output the ffmpeg build options. You're either leaving this out, or something else is going on here. I have checked the 5.1.1 build and 6.0 build from that site in my docker container and both behave as I'm expecting.

Please check the FFmpeg builds from here as well, because `--ffmpeg-no-validation` is not a solution:
https://github.com/BtbN/FFmpeg-Builds

----

It's possible that there is an async issue with the spawned child process in python where it processes the termination task first before processing the stdout task, hence why it doesn't validate an exit code of 0. If your ffmpeg binary only spits out one line, then this could explain the async timing issue.
https://github.com/streamlink/streamlink/blob/6.0.0/src/streamlink/utils/processoutput.py#L32

I will have a look at rewriting the `ProcessOutput` class using `trio` at some point though because the code would be much cleaner. This could fix a potential issue like this.
> Please check the FFmpeg builds from here as well, because `--ffmpeg-no-validation` is not a solution: https://github.com/BtbN/FFmpeg-Builds

I have checked the ffmpeg build.
I think my VPS is to old.
On my other local  (@ home) linux system it works fine. No --ffmpeg-no-validation. That system is newer. Unfortunately i  can at the moment not upgrade my VPS.
The nightly ffmpeg build works also fine on my local system.
Thank you.

i have met this issue too , don't ask me what static build I was using  I don't remember. 
You've removed parts of the debug log, so it's unclear which ffmpeg binary you've actually set.

Streamlink checks the first line of the stdout stream when running `ffmpeg -version`, as you can see here:
https://github.com/streamlink/streamlink/blob/6.0.0/src/streamlink/stream/ffmpegmux.py#L261-L267

The output of these custom-built ffmpeg binaries works just fine:

```
$ ./ffmpeg-6.0-amd64-static/ffmpeg -version 2>/dev/null | head -n1
ffmpeg version 6.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2023 the FFmpeg developers
```

Output from a temp docker container running the ffmpeg binary:

```
$ /opt/python/cp311-cp311/bin/python -m streamlink --loglevel=debug --output=/dev/null --ffmpeg-ffmpeg=/ffmpeg/ffmpeg-6.0-amd64-static/ffmpeg https://steamcommunity.com/broadcast/watch/76561199514732246 best
[cli][info] streamlink is running as root! Be careful!
[cli][debug] OS:         Linux-6.4.6-1-git-x86_64-with-glibc2.17
[cli][debug] Python:     3.11.4
[cli][debug] Streamlink: 6.0.0
[cli][debug] Dependencies:
[cli][debug]  certifi: 2023.7.22
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 4.9.3
[cli][debug]  pycountry: 22.3.5
[cli][debug]  pycryptodome: 3.18.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.31.0
[cli][debug]  trio: 0.22.2
[cli][debug]  trio-websocket: 0.10.3
[cli][debug]  typing-extensions: 4.7.1
[cli][debug]  urllib3: 2.0.4
[cli][debug]  websocket-client: 1.6.1
[cli][debug] Arguments:
[cli][debug]  url=https://steamcommunity.com/broadcast/watch/76561199514732246
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --output=/dev/null
[cli][debug]  --ffmpeg-ffmpeg=/ffmpeg/ffmpeg-6.0-amd64-static/ffmpeg
[cli][info] Found matching plugin steam for URL https://steamcommunity.com/broadcast/watch/76561199514732246
[plugins.steam][debug] Getting broadcast stream: sessionid=d3e4ef22f1a58e991fc13ab4
[utils.l10n][debug] Language code: en_US
[stream.dash][debug] Available languages for DASH audio streams: und (using: und)
[cli][info] Available streams: 360p (worst), 480p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (dash)
[cli][info] Writing output to
/dev/null
[cli][debug] Checking file output
[stream.dash][debug] Opening DASH reader for: ('1', 'video', '1') - video/mp4
[stream.dash][debug] Opening DASH reader for: ('1', 'audio', '1') - audio/mp4
[stream.dash][debug] video/mp4 segment initialization: downloading (2023-07-25T22:09:33.000000Z / 2023-07-27T17:25:15.525464Z)
[stream.dash_manifest][debug] Generating segment numbers for dynamic playlist: ('1', 'video', '1')
[stream.dash_manifest][debug] Stream start: 2023-07-25 22:09:33+00:00
[stream.dash_manifest][debug] Current time: 2023-07-27 17:25:15.523858+00:00
[stream.dash_manifest][debug] Availability: 2023-07-27 17:25:09+00:00
[stream.dash_manifest][debug] presentationTimeOffset: 0:00:00; suggestedPresentationDelay: 0:00:03; minBufferTime: 0:00:03
[stream.dash_manifest][debug] segmentDuration: 2.0; segmentStart: 1; segmentOffset: 77868 (155736.523858s)
[stream.dash][debug] audio/mp4 segment initialization: downloading (2023-07-25T22:09:33.000000Z / 2023-07-27T17:25:15.528351Z)
[stream.dash_manifest][debug] Generating segment numbers for dynamic playlist: ('1', 'audio', '1')
[stream.dash_manifest][debug] Stream start: 2023-07-25 22:09:33+00:00
[stream.dash_manifest][debug] Current time: 2023-07-27 17:25:15.523858+00:00
[stream.dash_manifest][debug] Availability: 2023-07-27 17:25:09+00:00
[stream.dash_manifest][debug] presentationTimeOffset: 0:00:00; suggestedPresentationDelay: 0:00:03; minBufferTime: 0:00:03
[stream.dash_manifest][debug] segmentDuration: 2.0; segmentStart: 1; segmentOffset: 77868 (155736.523858s)
[stream.ffmpegmux][debug] ffmpeg version 6.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2023 the FFmpeg developers
[stream.ffmpegmux][debug]  built with gcc 8 (Debian 8.3.0-6)
[stream.ffmpegmux][debug]  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
[stream.ffmpegmux][debug]  libavutil      58.  2.100 / 58.  2.100
[stream.ffmpegmux][debug]  libavcodec     60.  3.100 / 60.  3.100
[stream.ffmpegmux][debug]  libavformat    60.  3.100 / 60.  3.100
[stream.ffmpegmux][debug]  libavdevice    60.  1.100 / 60.  1.100
[stream.ffmpegmux][debug]  libavfilter     9.  3.100 /  9.  3.100
[stream.ffmpegmux][debug]  libswscale      7.  1.100 /  7.  1.100
[stream.ffmpegmux][debug]  libswresample   4. 10.100 /  4. 10.100
[stream.ffmpegmux][debug]  libpostproc    57.  1.100 / 57.  1.100
[utils.named_pipe][info] Creating pipe streamlinkpipe-53-1-9459
[utils.named_pipe][info] Creating pipe streamlinkpipe-53-2-4204
[stream.ffmpegmux][debug] ffmpeg command: /ffmpeg/ffmpeg-6.0-amd64-static/ffmpeg -nostats -y -i /tmp/streamlinkpipe-53-1-9459 -i /tmp/streamlinkpipe-53-2-4204 -c:v copy -c:a copy -copyts -f matroska pipe:1
[stream.ffmpegmux][debug] Starting copy to pipe: /tmp/streamlinkpipe-53-1-9459
[stream.ffmpegmux][debug] Starting copy to pipe: /tmp/streamlinkpipe-53-2-4204
[cli][debug] Pre-buffering 8192 bytes
[stream.dash][debug] audio/mp4 segment 77869: downloading (2023-07-27T17:25:09.000000Z / 2023-07-27T17:25:15.653844Z)
[stream.dash][debug] audio/mp4 segment initialization: completed
[stream.dash][debug] audio/mp4 segment 77870: downloading (2023-07-27T17:25:11.000000Z / 2023-07-27T17:25:15.695339Z)
[stream.dash][debug] audio/mp4 segment 77869: completed
[stream.dash][debug] audio/mp4 segment 77871: downloading (2023-07-27T17:25:13.000000Z / 2023-07-27T17:25:15.755956Z)
[stream.dash][debug] audio/mp4 segment 77870: completed
[stream.dash][debug] video/mp4 segment 77869: downloading (2023-07-27T17:25:09.000000Z / 2023-07-27T17:25:15.783191Z)
[stream.dash][debug] video/mp4 segment initialization: completed
[stream.dash][debug] audio/mp4 segment 77872: downloading (2023-07-27T17:25:15.000000Z / 2023-07-27T17:25:15.808912Z)
[stream.dash][debug] audio/mp4 segment 77871: completed
[stream.dash][debug] audio/mp4 segment 77873: waiting 1.1s (2023-07-27T17:25:17.000000Z / 2023-07-27T17:25:15.896141Z)
[stream.dash][debug] audio/mp4 segment 77872: completed
[stream.dash][debug] video/mp4 segment 77870: downloading (2023-07-27T17:25:11.000000Z / 2023-07-27T17:25:16.888916Z)
[stream.dash][debug] video/mp4 segment 77869: completed
[stream.dash][debug] audio/mp4 segment 77873: downloading (2023-07-27T17:25:17.000000Z / 2023-07-27T17:25:17.000241Z)
[cli][debug] Writing stream to output
[stream.dash][debug] audio/mp4 segment 77874: waiting 1.8s (2023-07-27T17:25:19.000000Z / 2023-07-27T17:25:17.200659Z)
[stream.dash][debug] audio/mp4 segment 77873: completed
[download] Written 592.00 KiB to /dev/null (0s)                                                                                                 [stream.dash][debug] video/mp4 segment 77871: downloading (2023-07-27T17:25:13.000000Z / 2023-07-27T17:25:17.302594Z)
[stream.dash][debug] video/mp4 segment 77870: completed
^C
[stream.ffmpegmux][debug] Closing ffmpeg thread
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[stream.ffmpegmux][debug] Pipe copy complete: /tmp/streamlinkpipe-53-1-9459
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[stream.ffmpegmux][debug] Pipe copy complete: /tmp/streamlinkpipe-53-2-4204
[stream.dash][debug] audio/mp4 segment 77874: cancelled
[stream.dash][warning] video/mp4 segment 77871: aborted
[stream.ffmpegmux][debug] Closed all the substreams
[cli][info] Stream ended
Interrupted! Exiting...
[cli][info] Closing currently open stream...
```
[cli][debug] OS:         Linux-3.10.0-1062.4.1.el7.x86_64-x86_64-with-glibc2.17
[cli][debug] Python:     3.11.4
[cli][debug] Streamlink: 6.0.0
[cli][debug] Dependencies:
[cli][debug]  certifi: 2023.5.7
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 4.9.2
[cli][debug]  pycountry: 22.3.5
[cli][debug]  pycryptodome: 3.18.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.31.0
[cli][debug]  trio: 0.22.2
[cli][debug]  trio-websocket: 0.10.3
[cli][debug]  typing-extensions: 4.7.1
[cli][debug]  urllib3: 2.0.3
[cli][debug]  websocket-client: 1.6.1
[cli][debug] Arguments:
[cli][debug]  url=XXX
[cli][debug]  --loglevel=debug
[cli][debug]  --player=mpv
[cli][debug]  --player-no-close=True
[cli][debug]  --output=/dev/null
[cli][debug]  --default-stream=['720p', 'best', 'vod']
[cli][debug]  --ringbuffer-size=33554432
[cli][debug]  --stream-segment-attempts=4
[cli][debug]  --stream-segment-timeout=30.0
[cli][debug]  --stream-timeout=60.0
[cli][debug]  --hls-playlist-reload-attempts=4
[cli][debug]  --hls-playlist-reload-time=segment
[cli][debug]  --ffmpeg-ffmpeg=/usr/bin/ffmpeg
[cli][debug]  --http-header=[('User-Agent', '"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36 OPR/62.0.3331.66"'), ('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; rv:114.0) Gecko/20100101 Firefox/114.0')]
[cli][debug]  --twitch-disable-ads=True
[cli][debug]  --twitch-disable-hosting=True
[cli][info] Found matching plugin hls for URL XXX
[plugins.hls][debug] URL=private
[utils.l10n][debug] Language code: en_US
[stream.ffmpegmux][error] Could not validate FFmpeg!
[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']
[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.
[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!
[cli][info] Available streams: 234p_alt (worst), 234p, 360p_alt2, 360p_alt, 360p, 540p, 720p_alt, 720p, 1080p (best)
[cli][info] Opening stream: 720p (hls)
[cli][info] Writing output to
/dev/null
[cli][debug] Checking file output
[stream.hls][debug] Reloading playlist
[cli][debug] Pre-buffering 8192 bytes
[stream.hls][debug] Segments in this playlist are encrypted
[stream.hls][debug] First Sequence: 4946541; Last Sequence: 4947172
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 4947170; End Sequence: None
[stream.hls][debug] Adding segment 4947170 to queue
[stream.hls][debug] Adding segment 4947171 to queue
[stream.hls][debug] Adding segment 4947172 to queue
[stream.hls][debug] Writing segment 4947170 to output
[stream.hls][debug] Segment 4947170 complete
[stream.hls][debug] Writing segment 4947171 to output
[stream.hls][debug] Segment 4947171 complete
[stream.hls][debug] Writing segment 4947172 to output
[stream.hls][debug] Segment 4947172 complete
[cli][debug] Writing stream to output
[download] Written 1.36 MiB to /dev/null (4s @ 303.87 KiB/s)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Segments in this playlist are encrypted
[stream.hls][debug] Adding segment 4947173 to queue
[stream.hls][debug] Writing segment 4947173 to output
[stream.hls][debug] Segment 4947173 complete
[download] Written 1.83 MiB to /dev/null (6s @ 292.90 KiB/s)
^C
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[cli][info] Stream ended
Interrupted! Exiting...
[cli][info] Closing currently open stream...

this is de info Url is a paid service with my personal info...
streamlink --loglevel=debug --output=/dev/null --ffmpeg-ffmpeg=/usr/bin/ffmpeg "XXX.m3u8"

ffmpeg -version 2>/dev/null | head -n1
ffmpeg version 5.1.1-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2022 the FFmpeg developers

This looks like an issue with your ffmpeg binary and not with Streamlink. As I've shown in the link above, Streamlink reads the first line of the stdout stream and tries to match it with the version string regex, which is `^ffmpeg version (\S+)`.

In order for the ffmpeg binary to be considered valid, it must exit with status code 0 and the version string must have matched.
https://github.com/streamlink/streamlink/blob/6.0.0/src/streamlink/stream/ffmpegmux.py#L274-L286

Post the full stdout and stderr output when running ffmpeg (using the absolute path)
```bash
/usr/bin/ffmpeg -version
```
and post its status/exit code
```bash
echo $?
```

----

There's also `--ffmpeg-no-validation` for skipping the validation step:
https://streamlink.github.io/cli.html#cmdoption-ffmpeg-no-validation
/usr/bin/ffmpeg -version
ffmpeg version 5.1.1-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2022 the FFmpeg developers

#echo $?
0
i tried --ffmpeg-no-validation and its now working.

Thank you for the help.
> /usr/bin/ffmpeg -version
> ffmpeg version 5.1.1-static [johnvansickle.com/ffmpeg](https://johnvansickle.com/ffmpeg/) Copyright (c) 2000-2022 the FFmpeg developers

There is no way that `-version` doesn't also output the ffmpeg build options. You're either leaving this out, or something else is going on here. I have checked the 5.1.1 build and 6.0 build from that site in my docker container and both behave as I'm expecting.

Please check the FFmpeg builds from here as well, because `--ffmpeg-no-validation` is not a solution:
https://github.com/BtbN/FFmpeg-Builds

----

It's possible that there is an async issue with the spawned child process in python where it processes the termination task first before processing the stdout task, hence why it doesn't validate an exit code of 0. If your ffmpeg binary only spits out one line, then this could explain the async timing issue.
https://github.com/streamlink/streamlink/blob/6.0.0/src/streamlink/utils/processoutput.py#L32

I will have a look at rewriting the `ProcessOutput` class using `trio` at some point though because the code would be much cleaner. This could fix a potential issue like this.
> Please check the FFmpeg builds from here as well, because `--ffmpeg-no-validation` is not a solution: https://github.com/BtbN/FFmpeg-Builds

I have checked the ffmpeg build.
I think my VPS is to old.
On my other local  (@ home) linux system it works fine. No --ffmpeg-no-validation. That system is newer. Unfortunately i  can at the moment not upgrade my VPS.
The nightly ffmpeg build works also fine on my local system.
Thank you.

i have met this issue too , don't ask me what static build I was using  I don't remember. 

Resolving patch:
diff --git a/src/streamlink/utils/processoutput.py b/src/streamlink/utils/processoutput.py
--- a/src/streamlink/utils/processoutput.py
+++ b/src/streamlink/utils/processoutput.py
@@ -48,9 +48,9 @@ async def onoutput(callback: Callable[[int, str], Optional[bool]], streamreader:
 
         tasks = (
             loop.create_task(ontimeout()),
-            loop.create_task(onexit()),
             loop.create_task(onoutput(self.onstdout, process.stdout)),
             loop.create_task(onoutput(self.onstderr, process.stderr)),
+            loop.create_task(onexit()),
         )
 
         try:


Test patch:
diff --git a/tests/utils/test_processoutput.py b/tests/utils/test_processoutput.py
--- a/tests/utils/test_processoutput.py
+++ b/tests/utils/test_processoutput.py
@@ -217,3 +217,23 @@ async def test_onoutput_exception(event_loop: asyncio.BaseEventLoop, processoutp
     assert processoutput.onstdout.call_args_list == [call(0, "foo")]
     assert processoutput.onstderr.call_args_list == []
     assert mock_process.kill.called
+
+
+@pytest.mark.asyncio()
+async def test_exit_before_onoutput(event_loop: asyncio.BaseEventLoop, processoutput: FakeProcessOutput, mock_process: Mock):
+    # resolve process.wait() in the onexit task immediately
+    mock_process.wait = AsyncMock(return_value=0)
+
+    # add some data to stdout, but don't actually interpret it in onstdout
+    mock_process.stdout.append(b"foo")
+    processoutput.onstdout.return_value = True
+
+    # the result of the `done` future should have already been set by the onoutput task
+    processoutput.onexit.return_value = False
+
+    result = await processoutput._run()
+
+    assert result is True
+    assert processoutput.onexit.called
+    assert processoutput.onstdout.called
+    assert mock_process.kill.called