-
Notifications
You must be signed in to change notification settings - Fork 936
Description
Hello, as the title suggests, I'm streaming from a youtube link, and in the output, I get the following:
[hls @ 0x58fdabd37dc0] Skip ('#EXT-X-VERSION:3')
[hls @ 0x58fdabd37dc0] Skip ('#EXT-X-DISCONTINUITY-SEQUENCE:522')
[hls @ 0x58fdabd37dc0] Skip ('#EXT-X-PROGRAM-DATE-TIME:2026-01-26T13:57:49.460+00:00')
[hls @ 0x58fdabd37dc0] Opening <giant stream link>followed by my desired output, which is great. My confusion lies in the fact that after it reads the data, it does this again, as though it resets the connection and opens it back up. I'm not terribly knowledgeable in the inner workings of ffmpeg, so this might be normal behavior specific to youtube streams that I don't fully understand.
This is the entire script:
streams = streamlink.streams(<youtube livestream link>)
buf = queue.Queue(maxsize=100)
ffstr = (
ffmpeg
.input(streams['best'].url)
.audio
.output('pipe:', format='s16le', acodec='pcm_s16le', ac=1, ar='16k')
.overwrite_output()
.run_async(pipe_stdout=True)
)
def _read_audio():
while True:
chunk = ffstr.stdout.read(4096)
if not chunk:
break
try:
buf.put_nowait(chunk)
except queue.Full:
continue
ffreader = threading.Thread(target=_read_audio).start()
while True:
stuff = np.frombuffer(buf.get(), dtype=np.uint16)
print(stuff)I took a look at #855 in regards to the implementation, so I thought that it would open the stream once and continuously read data when available, in chunks. I haven't tested whether the chunks are contiguous or segmented due to the stream re-opening, but my assumption is yes.
If the implementation isn't correct, please let me know what to change. My other thought is to stream data to ffmpeg as well, but the data stream using streamlink has null terminators over which ffmpeg freaks out.