var child_process = require("child_process"); var http = require('http'); var url = require('url'); var liveStream = function (req, resp) { // handle each client request by instantiating a new FFMPEG instance resp.writeHead(200, { "Connection": "keep-alive" , "Content-Type": "audio/ogg" , "Accept-Ranges": "bytes" // Helps Chrome }); var song = "/storage/samba/Music/Chvrches - Every Open Eye/02 Leave A Trace.mp3"; var query = url.parse(req.url, true).query; if ("song" in query) song=query.song; transcoder = child_process.spawn("/usr/bin/ffmpeg", [ "-i",song, "-c:a", "libvorbis", "-vn", "-b:a", "192k", "-f", "ogg", "-y", "-" ], {detached: false}); transcoder.stdout.pipe(resp); transcoder.stdout.on("data",function(data) { }); transcoder.stderr.on("data", function (data) { console.log(" -> " + data); }); transcoder.on("exit", function (code) { console.log( " live FFMPEG terminated with code " + code); }); transcoder.on("error", function (e) { console.log(" live FFMPEG system error: " + e); }); req.on("close", function () { shutStream("closed") }) req.on("end", function () { shutStream("ended") }); function shutStream(event) { console.log("Live streaming connection to client has " + event) if (typeof transcoder !== "undefined") { transcoder.kill(); } } return true } http.createServer(liveStream).listen(1337, "0.0.0.0"); console.log("runnen");