Search code examples
pythonnode.jsffmpegwebrtcmkfifo

Sending video stream from NodeJS to python in real time


I'm using a NodeJS server to catch a video stream through a WebRTC PeerConnection and I need to send it to a python script.

I use NodeJS mainly because it's easy to use WebRTC in it and the package 'wrtc' supports RTCVideoSink and python's aiortc doesn't.

I was thinking of using a named pipe with ffmpeg to stream the video stream but 3 questions arose :

  • Should I use python instead of NodeJS and completely avoid the stream through a named pipe part ? (This means there is a way to extract individual frames from a MediaStreamTrack in python)

  • If I stick with the "NodeJS - Python" approach, how do I send the stream from one script to the other ? Named pipe ? Unix domain sockets ? And with FFMpeg ?

  • Finally, for performance purpose I think that sending a stream and not each individual frames is better and simpler but is this true ?

Thanks all !


Solution

  • Finally, I found that the MediaStreamTrack API of Python's aiortc has recv().

    It's a Coroutine that returns the next frame. So I will just port my NodeJS script to python using this coroutine to replace RTCVideoSink. No piping or whatsoever !