We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/streamlink/utils/processoutput.py`
Content:
```
1 import asyncio
2 from contextlib import suppress
3 from typing import Callable, List, Optional
4 
5 
6 class ProcessOutput:
7     def __init__(self, command: List[str], timeout: Optional[float] = None):
8         self.command = command
9         self.timeout = timeout
10 
11     def run(self) -> bool:  # pragma: no cover
12         return asyncio.run(self._run())
13 
14     async def _run(self) -> bool:
15         loop = asyncio.get_event_loop()
16         done: asyncio.Future[bool] = loop.create_future()
17         process = await asyncio.create_subprocess_exec(
18             *self.command,
19             stdin=None,
20             stdout=asyncio.subprocess.PIPE,
21             stderr=asyncio.subprocess.PIPE,
22         )
23         if not process.stdout or not process.stderr:  # pragma: no cover
24             return False
25 
26         async def ontimeout():
27             if self.timeout:
28                 await asyncio.sleep(self.timeout)
29                 done.set_result(False)
30 
31         async def onexit():
32             code = await process.wait()
33             done.set_result(self.onexit(code))
34 
35         async def onoutput(callback: Callable[[int, str], Optional[bool]], streamreader: asyncio.StreamReader):
36             line: bytes
37             idx = 0
38             async for line in streamreader:
39                 try:
40                     result = callback(idx, line.decode().rstrip())
41                 except Exception as err:
42                     done.set_exception(err)
43                     break
44                 if result is not None:
45                     done.set_result(bool(result))
46                     break
47                 idx += 1
48 
49         tasks = (
50             loop.create_task(ontimeout()),
51             loop.create_task(onexit()),
52             loop.create_task(onoutput(self.onstdout, process.stdout)),
53             loop.create_task(onoutput(self.onstderr, process.stderr)),
54         )
55 
56         try:
57             return await done
58         finally:
59             for task in tasks:
60                 task.cancel()
61             with suppress(OSError):
62                 process.kill()
63 
64     def onexit(self, code: int) -> bool:
65         return code == 0
66 
67     def onstdout(self, idx: int, line: str) -> Optional[bool]:  # pragma: no cover
68         pass
69 
70     def onstderr(self, idx: int, line: str) -> Optional[bool]:  # pragma: no cover
71         pass
72
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
 
         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:

{"golden_diff": "diff --git a/src/streamlink/utils/processoutput.py b/src/streamlink/utils/processoutput.py\n--- a/src/streamlink/utils/processoutput.py\n+++ b/src/streamlink/utils/processoutput.py\n@@ -48,9 +48,9 @@\n \n         tasks = (\n             loop.create_task(ontimeout()),\n-            loop.create_task(onexit()),\n             loop.create_task(onoutput(self.onstdout, process.stdout)),\n             loop.create_task(onoutput(self.onstderr, process.stderr)),\n+            loop.create_task(onexit()),\n         )\n \n         try:\n", "issue": "Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']\n### Checklist\n\n- [X] This is a bug report and not a different kind of issue\n- [X] [I have read the contribution guidelines](https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#contributing-to-streamlink)\n- [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)\n- [X] [I have checked the commit log of the master branch](https://github.com/streamlink/streamlink/commits/master)\n\n### Streamlink version\n\nLatest stable release\n\n### Description\n\nFFmpeg binary not validated.\r\nStreamlink version 6.0.0.0 Linux Appimage x86_64\r\nGot this error message:\r\n\r\n[stream.ffmpegmux][error] Could not validate FFmpeg!\r\n[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']\r\n[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.\r\n[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!\r\n\r\nffmpeg output:\r\nffmpeg -version\r\nffmpeg version 6.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2023 the FFmpeg developers\r\nbuilt with gcc 8 (Debian 8.3.0-6)\r\n\r\nffmpeg is in /usr/bin\n\n### Debug log\n\n```text\n[utils.l10n][debug] Language code: en_US\r\n[stream.ffmpegmux][error] Could not validate FFmpeg!\r\n[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']\r\n[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.\r\n[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!\r\n[cli][info] Available streams: 234p_alt (worst), 234p, 360p_alt2, 360p_alt, 360p, 540p, 720p_alt, 720p, 1080p (best)\r\n[cli][info] Opening stream: 720p (hls)\r\n[cli][info] Starting player: mpv\r\n[stream.hls][debug] Reloading playlist\r\n[cli][debug] Pre-buffering 8192 bytes\r\n[stream.hls][debug] Segments in this playlist are encrypted\r\n[stream.hls][debug] First Sequence: 22258880; Last Sequence: 22259722\r\n[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 22259720; End Sequence: None\r\n[stream.hls][debug] Adding segment 22259720 to queue\r\n[stream.hls][debug] Adding segment 22259721 to queue\r\n[stream.hls][debug] Adding segment 22259722 to queue\r\n[stream.hls][debug] Writing segment 22259720 to output\r\n[stream.hls][debug] Segment 22259720 complete\n```\n\nUnexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']\n### Checklist\n\n- [X] This is a bug report and not a different kind of issue\n- [X] [I have read the contribution guidelines](https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#contributing-to-streamlink)\n- [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)\n- [X] [I have checked the commit log of the master branch](https://github.com/streamlink/streamlink/commits/master)\n\n### Streamlink version\n\nLatest stable release\n\n### Description\n\nFFmpeg binary not validated.\r\nStreamlink version 6.0.0.0 Linux Appimage x86_64\r\nGot this error message:\r\n\r\n[stream.ffmpegmux][error] Could not validate FFmpeg!\r\n[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']\r\n[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.\r\n[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!\r\n\r\nffmpeg output:\r\nffmpeg -version\r\nffmpeg version 6.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2023 the FFmpeg developers\r\nbuilt with gcc 8 (Debian 8.3.0-6)\r\n\r\nffmpeg is in /usr/bin\n\n### Debug log\n\n```text\n[utils.l10n][debug] Language code: en_US\r\n[stream.ffmpegmux][error] Could not validate FFmpeg!\r\n[stream.ffmpegmux][error] Unexpected FFmpeg version output while running ['/usr/bin/ffmpeg', '-version']\r\n[stream.ffmpegmux][warning] No valid FFmpeg binary was found. See the --ffmpeg-ffmpeg option.\r\n[stream.ffmpegmux][warning] Muxing streams is unsupported! Only a subset of the available streams can be returned!\r\n[cli][info] Available streams: 234p_alt (worst), 234p, 360p_alt2, 360p_alt, 360p, 540p, 720p_alt, 720p, 1080p (best)\r\n[cli][info] Opening stream: 720p (hls)\r\n[cli][info] Starting player: mpv\r\n[stream.hls][debug] Reloading playlist\r\n[cli][debug] Pre-buffering 8192 bytes\r\n[stream.hls][debug] Segments in this playlist are encrypted\r\n[stream.hls][debug] First Sequence: 22258880; Last Sequence: 22259722\r\n[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 22259720; End Sequence: None\r\n[stream.hls][debug] Adding segment 22259720 to queue\r\n[stream.hls][debug] Adding segment 22259721 to queue\r\n[stream.hls][debug] Adding segment 22259722 to queue\r\n[stream.hls][debug] Writing segment 22259720 to output\r\n[stream.hls][debug] Segment 22259720 complete\n```\n\n", "before_files": [{"content": "import asyncio\nfrom contextlib import suppress\nfrom typing import Callable, List, Optional\n\n\nclass ProcessOutput:\n    def __init__(self, command: List[str], timeout: Optional[float] = None):\n        self.command = command\n        self.timeout = timeout\n\n    def run(self) -> bool:  # pragma: no cover\n        return asyncio.run(self._run())\n\n    async def _run(self) -> bool:\n        loop = asyncio.get_event_loop()\n        done: asyncio.Future[bool] = loop.create_future()\n        process = await asyncio.create_subprocess_exec(\n            *self.command,\n            stdin=None,\n            stdout=asyncio.subprocess.PIPE,\n            stderr=asyncio.subprocess.PIPE,\n        )\n        if not process.stdout or not process.stderr:  # pragma: no cover\n            return False\n\n        async def ontimeout():\n            if self.timeout:\n                await asyncio.sleep(self.timeout)\n                done.set_result(False)\n\n        async def onexit():\n            code = await process.wait()\n            done.set_result(self.onexit(code))\n\n        async def onoutput(callback: Callable[[int, str], Optional[bool]], streamreader: asyncio.StreamReader):\n            line: bytes\n            idx = 0\n            async for line in streamreader:\n                try:\n                    result = callback(idx, line.decode().rstrip())\n                except Exception as err:\n                    done.set_exception(err)\n                    break\n                if result is not None:\n                    done.set_result(bool(result))\n                    break\n                idx += 1\n\n        tasks = (\n            loop.create_task(ontimeout()),\n            loop.create_task(onexit()),\n            loop.create_task(onoutput(self.onstdout, process.stdout)),\n            loop.create_task(onoutput(self.onstderr, process.stderr)),\n        )\n\n        try:\n            return await done\n        finally:\n            for task in tasks:\n                task.cancel()\n            with suppress(OSError):\n                process.kill()\n\n    def onexit(self, code: int) -> bool:\n        return code == 0\n\n    def onstdout(self, idx: int, line: str) -> Optional[bool]:  # pragma: no cover\n        pass\n\n    def onstderr(self, idx: int, line: str) -> Optional[bool]:  # pragma: no cover\n        pass\n", "path": "src/streamlink/utils/processoutput.py"}], "after_files": [{"content": "import asyncio\nfrom contextlib import suppress\nfrom typing import Callable, List, Optional\n\n\nclass ProcessOutput:\n    def __init__(self, command: List[str], timeout: Optional[float] = None):\n        self.command = command\n        self.timeout = timeout\n\n    def run(self) -> bool:  # pragma: no cover\n        return asyncio.run(self._run())\n\n    async def _run(self) -> bool:\n        loop = asyncio.get_event_loop()\n        done: asyncio.Future[bool] = loop.create_future()\n        process = await asyncio.create_subprocess_exec(\n            *self.command,\n            stdin=None,\n            stdout=asyncio.subprocess.PIPE,\n            stderr=asyncio.subprocess.PIPE,\n        )\n        if not process.stdout or not process.stderr:  # pragma: no cover\n            return False\n\n        async def ontimeout():\n            if self.timeout:\n                await asyncio.sleep(self.timeout)\n                done.set_result(False)\n\n        async def onexit():\n            code = await process.wait()\n            done.set_result(self.onexit(code))\n\n        async def onoutput(callback: Callable[[int, str], Optional[bool]], streamreader: asyncio.StreamReader):\n            line: bytes\n            idx = 0\n            async for line in streamreader:\n                try:\n                    result = callback(idx, line.decode().rstrip())\n                except Exception as err:\n                    done.set_exception(err)\n                    break\n                if result is not None:\n                    done.set_result(bool(result))\n                    break\n                idx += 1\n\n        tasks = (\n            loop.create_task(ontimeout()),\n            loop.create_task(onoutput(self.onstdout, process.stdout)),\n            loop.create_task(onoutput(self.onstderr, process.stderr)),\n            loop.create_task(onexit()),\n        )\n\n        try:\n            return await done\n        finally:\n            for task in tasks:\n                task.cancel()\n            with suppress(OSError):\n                process.kill()\n\n    def onexit(self, code: int) -> bool:\n        return code == 0\n\n    def onstdout(self, idx: int, line: str) -> Optional[bool]:  # pragma: no cover\n        pass\n\n    def onstderr(self, idx: int, line: str) -> Optional[bool]:  # pragma: no cover\n        pass\n", "path": "src/streamlink/utils/processoutput.py"}]}