Click here to Skip to main content
15,668,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


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

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.

What I have tried:

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 = "";

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:// -f wav -";

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

  res.writeHead(200, { "Content-Type": "audio/wav; codecs=PCM" });
Updated 19-Jun-20 19:35pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900