Playing Youtube streams via NodeJS

jts3k's icon

Hi Forum,

I'm working on a patch to play Youtube streams in jit.movie~ via NodeJS and the ytdl package. It is *almost* working. The patch can play standard Youtube videos, with MSP audio, which was very promising. For live streams it can play the video - but no sound. Also it seems to loop the first several seconds of the video rather than allow it to continuously play.

Curiously if one opens the file that the patch downloads in VLC it can play live streams perfectly, with sound. I've experimented with downloading live streams into different "container" types (flv, mp4, webm, etc) - while most of these will play (with sound) in VLC, I just can't get sound working in Max. But standard youtube videos will play fine, with MSP audio.

Any thoughts on how to get sound working with live streams? Seems like an excellent potential source of multimedia antics in this age of copious live streaming...

Patch with the .js and .json's are in the linked zip. Click "script npm install" the first time to install ytdl-core.

OCH's icon

+1

Rob Ramirez's icon

cool patch, I missed this the first time around! it looks like it's just jit.movie~ that's struggling, jit.movie seems to play the audio fine. i'll see if I can figure out why jit.movie~ is unhappy.

OCH's icon

:)

jts3k's icon

Thanks Rob, please let me know if you learn anything!

Dario Ruiz's icon

Hey, really nice!

I was wondering, any way to search a video in YouTube from within a Max patch?


mh77's icon

Hi all!
this is just great. any news on this sound problem?
and, if i may ask... could it also play livestreams from twitch etc. ?

DaveH's icon

@JTS3K Did you ever figure this out?

It appears as if the node.js script is constantly writing to a file on the drive, but when you bang the read command to the jit.movie~ object, it just plays the whatver is currently in that file. If you bang it again, you'll notice that it'll jump back to to the beginning, but now the file is much larger and will play for longer.

Also, the sound issue is weird and I can't seem to figure that one out either.

DaveH's icon

I managed a not-so-perfect workaround where I just monitor the playback position of the jit.movie object, and when it reaches a certain threshold near the end of the stream, it saves the current position of the playback head, triggers a re-read of the stream file, jumps to previous position and then continues playback. It stutters ever so slightly, but it works. Still working on the sound though.

doganos wont's icon

I cant make it run,i do not really understand the patch .. Any advise would be appreciated.

windows 10 x64,max 8.1.8