Make sure that each substream's buffer always gets fully emptied when closing the stream, so that no data is missing when muxing the output stream.
The second commit fixes another race condition in the NamedPipePosix implementation when attempting to close the file descriptor of a broken named pipe where the fifo wouldn't get unlinked in the filesystem.
As mentioned in #5159 (comment), I will have a look at properly refactoring/rewriting the FFMPEGMuxer class some time later.
Pipe-copying now ends simultaneously and no data should be missing in the muxed output stream:
$ streamlink -l debug -o /tmp/foo.mkv 'https://vimeo.com/channels/staffpicks/790905324' best
...
[stream.dash][debug] Download of segment: 0c433f4a.mp4 complete
[stream.dash][debug] Download of segment: 9ae75d32.mp4 complete
...
[stream.dash][debug] Download of segment: 0c433f4a.mp4 complete
[stream.dash][debug] Download of segment: 9ae75d32.mp4 complete
[stream.segmented][debug] Closing writer thread
[stream.dash][debug] Download of segment: 0c433f4a.mp4 complete
[stream.dash][debug] Download of segment: 0c433f4a.mp4 complete
...
[stream.dash][debug] Download of segment: 0c433f4a.mp4 complete
[stream.segmented][debug] Closing writer thread
[stream.ffmpegmux][debug] Pipe copy complete: /tmp/streamlinkpipe-26548-1-3723
[stream.ffmpegmux][debug] Pipe copy complete: /tmp/streamlinkpipe-26548-2-7524
[stream.ffmpegmux][debug] Closing ffmpeg thread
[stream.ffmpegmux][debug] Closed all the substreams
[cli][info] Stream ended
[cli][info] Closing currently open stream...
$ ffmpeg -i /tmp/foo.mkv -c copy /tmp/foo.mp4
...
$ ffprobe -v error -of json -show_streams /tmp/foo.mp4 | jq -r .streams[].duration
914.916000
914.922333