Jo Aqra Ответов: 0

Как я могу транслировать аудио в прямом эфире node.js-что?


I'm trying stream live audio to a wide range of clients in a web browser.

My current solution :

Dotnet core 3.1 console application

-receive the audio data over UDP

-trimming the first 28 bytes of each received packet

-and send the processed packet over UDP.


Node JS

-execute a Ffmepg as a child process to receive audio data packets over UDP from the console app, and encode each packet to audio WAV format

-Pipe out the result of the child process into a GET HTTP endpoint response


Browser

=HTML audio element with source value equals to the node js GET endpoint
Problem:

The solution is giving a good result, but only for one device(one to one), which is not what I want to achieve.


I believe that I've to make some changes to the node js implementation, so here I'll share it with you, hoping to get a clue to solve the problem.


Что я уже пробовал:

I've tried many solutions to make it applicable to a wide range of devices, such as using working threads and forking a child process, but none of them changes the result.


var express = require("express");
var app = express();
var children = require("child_process");

var port = 5001;
var host = "192.168.1.230";

app.listen(port, host, () => {
  console.log("Server running at http://" + host + ":" + port + "/");
});

app.get('/stream', (req, res) => {
  const ffmpegCommand = "ffmpeg";
  var ffmpegOptions =
    "-f s16le -ar 48000 -ac 2 -i udp://192.168.1.230:65535 -f wav -";

  var ffm = children.spawn(ffmpegCommand, ffmpegOptions.split(" "));

  res.writeHead(200, { "Content-Type": "audio/wav; codecs=PCM" });
  ffm.stdout.pipe(res);
});

0 Ответов