Click here to Skip to main content
15,909,498 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


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.

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.

JavaScript
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);
});
Posted
Updated 22-May-24 17:13pm
v2

1 solution

It often serves to search on the internet to see what others have done already in this space. I had a search and found this solution[^] on StackOverflow.
 
Share this answer
 
Comments
Richard Deeming 23-May-24 8:23am    
NB: Hopefully the OP isn't still looking for an answer four years later! :)

It got dragged back up the list by a spam answer[^], which has since been deleted.
Pete O'Hanlon 23-May-24 9:22am    
Dammit. I normally check. Thanks Richard.

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