Sunday, 18 August 2019

Sending 2 streams to FFmpeg from nodejs

I am trying to send 2 ReadableStreams to FFmpeg from nodejs. I have tried using fluent-ffmpeg library to do this, but it only supports sending one stream for processing. Check here

My problem is: I have 2 incoming mono audio streams, I want to send them to ffmpeg to create a stereo stream, which I will then send to google's speech to text service, to generate a transcription.

I am successfully receiving both the mono streams to the nodejs server. How to utilize FFmpeg to merge them in realtime is still unclear, I could spawn a FFmpeg child process, but I'm not sure how to give 2 ReadableStreams as inputs and get the output as another stream? FFmpeg supports multiple input streams.

I can merge the 2 mono streams if they are in two separate files with this code.

const { spawn } = childProcess;
const ffmpeg = spawn('ffmpeg', [
  '-i', this.phoneAudioFile,
  '-i', this.micAudioFile,
  '-filter_complex', '[0:a][1:a]amerge=inputs=2[a]',
  '-map', '[a]',
  this.outputLosslessFile,
]);

How can I acheive the same using 2 streams instead of 2 files?



from Sending 2 streams to FFmpeg from nodejs

No comments:

Post a Comment