Skip to content

Commit

Permalink
Fixed FileOut FileName StreamStats
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewiski committed May 3, 2023
1 parent 08354fd commit 0eb85b6
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 28 deletions.
18 changes: 15 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ var radarDatabase = new RadarDatabase(objOptions.radarDatabase, logUtilHelper, o
var commonData = {
game: null,
currentRadarSpeedData: null,
radar: {log:[]}
radar: {log:[]},
videoStreamStats : {
youtube: null,
gamechanger: null,
file: null
}
}

var privateData = {
Expand Down Expand Up @@ -449,6 +454,7 @@ var videoStreamYoutubeStart = function (options) {
privateData.videoStreams.youtube.on("streamStats", function(data){
//logUtilHelper.log(appLogName, "app", "debug",'videoStream', 'Youtube Stream Stats', data);
//sendToVideoStreamSubscribedSocketClients("videoStreams", { cmd: "youtubeStreamStats", data: data });
commonData.videoStreamStats.youtube = data;
sendToSubscribedSocketClients("videoStreams", "videoStreams", { cmd: "youtubeStreamStats", data: data });
});
}
Expand Down Expand Up @@ -507,7 +513,7 @@ var videoStreamGamechangerStart = function (options) {
});
privateData.videoStreams.gamechanger.on("streamStats", function(data){
//logUtilHelper.log(appLogName, "app", "debug",'videoStream', 'Gamechanger Stream Stats', data);

commonData.videoStreamStats.gamechanger = data;
sendToSubscribedSocketClients("videoStreams", "videoStreams", { cmd: "gamechangerStreamStats", data: data });
});
}
Expand Down Expand Up @@ -568,6 +574,7 @@ var videoStreamFileStart = function (options) {
logUtilHelper.log(appLogName, "app", "info",'videoStream', 'videoStreamFileStart');

if(privateData.videoStreams.file ===null){

privateData.videoStreams.file = new FfmpegVideoInput(objOptions.videoStreams.file, videoOverlayParser, logUtilHelper);
privateData.videoStreams.file.on("stopped", function(){
logUtilHelper.log(appLogName, "app", "info",'videoStream', 'File was Stopped');
Expand All @@ -579,7 +586,9 @@ var videoStreamFileStart = function (options) {
});
privateData.videoStreams.file.on("streamStats", function(data){
//logUtilHelper.log(appLogName, "app", "debug",'videoStream', 'File Stream Stats', data);
commonData.videoStreamStats.file = data;
sendToSubscribedSocketClients("videoStreams", "videoStreams", { cmd: "fileStreamStats", data: data });

});
}
if (options){
Expand All @@ -601,7 +610,8 @@ var videoStreamFileStart = function (options) {
}
let fileName = getDateFileName() + "_" + objOptions.videoStreams.teamName.replace(/[^a-zA-Z0-9]/g,"_") + "_vs_" + objOptions.videoStreams.opponentTeamName.replace(/[^a-zA-Z0-9]/g,"_") + ".flv";
fileName = path.join(objOptions.videoStreams.videosFolder, fileName);
objOptions.videoStreams.file.outputs.ffmpegVideoOutputFile.outputFile = fileName;
//objOptions.videoStreams.file.outputs.ffmpegVideoOutputFile.outputFile = fileName;
privateData.videoStreams.file.options.outputs.ffmpegVideoOutputFile.outputFile = fileName;
}
privateData.videoStreams.file.streamStart();
}catch(ex){
Expand Down Expand Up @@ -896,6 +906,8 @@ io.on('connection', function(socket) {
socket.emit('softwareConfig', radarStalker2.getSoftwareConfig());
socket.emit('radarSpeedDataHistory', radarStalker2.getradarSpeedDataHistory());
socket.emit('gameChanged', {cmd:"gameChanged", data:commonData.game});
socket.emit('videoStreams', {cmd:"allStreamStats", data:commonData.videoStreamStats});

}
//send the current Battery Voltage
socket.emit('batteryVoltage', batteryMonitor.getBatteryVoltage());
Expand Down
41 changes: 30 additions & 11 deletions modules/ffmpegVideoInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ var FfmpegVideoInput = function (options, videoOverlayParser, logUtilHelper) {
status: "disconnected",
error: null,
metadata: {},
}
},
rtmp: null,
rtmp2: null,
file: null
},
shouldRestartStream: false,
activeMp4Streams: []
Expand Down Expand Up @@ -177,7 +180,8 @@ var FfmpegVideoInput = function (options, videoOverlayParser, logUtilHelper) {
case 'info':
case 'verbose':
if (stdOut.values.size) {
commonData.streamStats.info = stdOut.values;
commonData.streamStats.incoming.info = stdOut.values;
self.emit('streamStats', commonData.streamStats);
logUtilHelper.log(appLogName, "app", 'trace', 'parsed stdErr: ', stdOut);
} else {
logUtilHelper.log(appLogName, "app", 'debug', 'parsed stdErr: ', stdOut);
Expand All @@ -193,8 +197,8 @@ var FfmpegVideoInput = function (options, videoOverlayParser, logUtilHelper) {

var commandError = function (err, stdout, stderr) {
logUtilHelper.log(appLogName, "app", 'error', 'an error happened: ' + err.message, err); //, stdout, stderr);
commonData.streamStats.status = "disconnected";
commonData.streamStats.error = err;
commonData.streamStats.incoming.status = "disconnected";
commonData.streamStats.incoming.error = err;
//commonData.streamStats.stdout = stdout;
//commonData.streamStats.stderr = stderr;
self.emit('streamStats', commonData.streamStats);
Expand All @@ -207,17 +211,17 @@ var FfmpegVideoInput = function (options, videoOverlayParser, logUtilHelper) {

var commandProgress = function (progress) {

if (commonData.streamStats.status === "disconnected") {
commonData.streamStats.status = "connected";
if (commonData.streamStats.incoming.status === "disconnected") {
commonData.streamStats.incoming.status = "connected";
self.emit('streamStats', commonData.streamStats);

}
//proc_count++;
};

var commandEnd = function (result) {
commonData.streamStats.status = "disconnected";
commonData.streamStats.error = "commandEnd Called";
commonData.streamStats.incoming.status = "disconnected";
commonData.streamStats.incoming.error = "commandEnd Called";
self.emit('streamStats', commonData.streamStats);
logUtilHelper.log(appLogName, "app", 'error', 'Source Stream Closed');
if(commonData.shouldRestartStream === true){
Expand Down Expand Up @@ -300,7 +304,7 @@ var FfmpegVideoInput = function (options, videoOverlayParser, logUtilHelper) {
if (!(command === null || command === undefined)) {
command.kill();
}
commonData.streamStats.status = "connected";
commonData.streamStats.incoming.status = "connected";
self.emit('streamStats', commonData.streamStats);
logUtilHelper.log(appLogName, "app", "debug", "Source Video URL", self.options.input, "Rtmp Video URL", self.options.rtmpUrl)
if(self.options.input.startsWith("libcamera")){
Expand Down Expand Up @@ -397,11 +401,17 @@ var FfmpegVideoInput = function (options, videoOverlayParser, logUtilHelper) {
if (ffmpegVideoOutputRtmp === null) {
ffmpegVideoOutputRtmp = new FfmpegVideoOutputRtmp(self.options.outputs.ffmpegVideoOutputRtmp, self.videoOverlayParser, logUtilHelper);
ffmpegVideoOutputRtmp.on("streamStart", function (data) {
commonData.streamStats.rtmp = data;
self.emit("streamStartRtmp",{});
});
ffmpegVideoOutputRtmp.on("streamStop", function (data) {
self.emit("streamStopRtmp",{});
})
ffmpegVideoOutputRtmp.on("streamStats", function (data) {
commonData.streamStats.rtmp = data;
self.emit("streamStats", commonData.streamStats);
})

}
ffmpegVideoOutputRtmp.streamStart(incomingTransStream, throwError);
}
Expand All @@ -416,12 +426,16 @@ var FfmpegVideoInput = function (options, videoOverlayParser, logUtilHelper) {

if (ffmpegVideoOutputRtmp2 === null) {
ffmpegVideoOutputRtmp2 = new FfmpegVideoOutputRtmp(self.options.outputs.ffmpegVideoOutputRtmp2, self.videoOverlayParser, logUtilHelper);
ffmpegVideoOutputRtmp.on("streamStart", function (data) {
ffmpegVideoOutputRtmp2.on("streamStart", function (data) {
self.emit("streamStartRtmp2",{});
});
ffmpegVideoOutputRtmp.on("streamStop", function (data) {
ffmpegVideoOutputRtmp2.on("streamStop", function (data) {
self.emit("streamStopRtmp2",{});
});
ffmpegVideoOutputRtmp2.on("streamStats", function (data) {
commonData.streamStats.rtmp2 = data;
self.emit("streamStats", commonData.streamStats);
})
}
ffmpegVideoOutputRtmp2.streamStart(incomingTransStream, throwError);
}
Expand All @@ -442,6 +456,11 @@ var FfmpegVideoInput = function (options, videoOverlayParser, logUtilHelper) {
ffmpegVideoOutputFile.on("streamStop", function (data) {
self.emit("streamStopFile",{});
});
ffmpegVideoOutputFile.on("streamStats", function (data) {
commonData.streamStats.file = data;
self.emit("streamStats", commonData.streamStats);
})

}
ffmpegVideoOutputFile.streamStart(incomingTransStream, throwError);
}
Expand Down
3 changes: 2 additions & 1 deletion modules/ffmpegVideoOutputFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ var FfmpegVideoOutputFile = function (options, videoOverlayParser, logUtilHelper
case 'verbose':
if (stdOut.values.size) {
commonData.streamStats.info = stdOut.values;
self.emit('streamStats', commonData.streamStats);
logUtilHelper.log(appLogName, "app", 'trace', 'parsed stdErr: ', stdOut);
} else {
logUtilHelper.log(appLogName, "app", 'debug', 'parsed stdErr: ', stdOut);
Expand All @@ -191,7 +192,7 @@ var FfmpegVideoOutputFile = function (options, videoOverlayParser, logUtilHelper
commonData.streamStats.stderr = stderr;
self.emit('streamStats', commonData.streamStats);
if (err && err.message && err.message.startsWith('ffmpeg exited with code') === true) {
setTimeout(restartStream, 30000);
//setTimeout(restartStream, 30000);
}
};

Expand Down
1 change: 1 addition & 0 deletions modules/ffmpegVideoOutputRtmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ var FfmpegVideoOutputRtmp = function (options, videoOverlayParser, logUtilHelper
case 'verbose':
if (stdOut.values.size) {
commonData.streamStats.info = stdOut.values;
self.emit('streamStats', commonData.streamStats);
logUtilHelper.log(appLogName, "app", 'trace', self.options.rtmpUrl, 'parsed stdErr: ', stdOut);
} else {
logUtilHelper.log(appLogName, "app", 'debug', self.options.rtmpUrl, 'parsed stdErr: ', stdOut);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "radargunmonitor",
"version": "0.0.15",
"version": "0.0.16",
"private": false,
"license": "Apache-2.0",
"keywords": [
Expand Down
37 changes: 25 additions & 12 deletions public/app/scoreboard/scoreboard.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -1219,16 +1219,29 @@
<button class="btn btn-primary" ng-click="videoStreamFileStop()">Stop Stream</button>
</div>

<div ng-show="commonData.videoStreamStats.file.info !== undefined">
<span ng-class="{'text-success': commonData.videoStreamStats.file.status=='connected'}"><i class="fa-solid fa-cloud"></i></span>
<label>status: </label><span ng-bind="commonData.videoStreamStats.file.status"></span>
<label>time: </label><span ng-bind="commonData.videoStreamStats.file.info.time"></span>
<label>frame: </label><span ng-bind="commonData.videoStreamStats.file.info.frame"></span>
<label>size: </label><span ng-bind="commonData.videoStreamStats.file.info.size"></span>
<label>fps: </label> <span ng-bind="commonData.videoStreamStats.file.info.fps"></span>
<label>bitrate: </label><span ng-bind="commonData.videoStreamStats.file.info.bitrate"></span>
<label>speed: </label><span ng-bind="commonData.videoStreamStats.file.info.speed"></span>
<label ng-show="commonData.videoStreamStats.file.error !== null">error: </label><span ng-show="commonData.videoStreamStats.file.error !== null" ng-bind="commonData.videoStreamStats.file.error"></span>
<div ng-show="commonData.videoStreamStats.file !== null && commonData.videoStreamStats.file.incoming !== null">
<label>Incoming:</label>
<span ng-class="{'text-success': commonData.videoStreamStats.file.incoming.status=='connected'}"><i class="fa-solid fa-cloud"></i></span>
<label>status: </label><span ng-bind="commonData.videoStreamStats.file.incoming.status"></span>
<label>time: </label><span ng-bind="commonData.videoStreamStats.file.incoming.info.time"></span>
<label>frame: </label><span ng-bind="commonData.videoStreamStats.file.incoming.info.frame"></span>
<label>size: </label><span ng-bind="commonData.videoStreamStats.file.incoming.info.size"></span>
<label>fps: </label> <span ng-bind="commonData.videoStreamStats.file.incoming.info.fps"></span>
<label>bitrate: </label><span ng-bind="commonData.videoStreamStats.file.incoming.info.bitrate"></span>
<label>speed: </label><span ng-bind="commonData.videoStreamStats.file.incoming.info.speed"></span>
<label ng-show="commonData.videoStreamStats.file.incoming.error !== null">error: </label><span ng-show="commonData.videoStreamStats.file.incoming.error !== null" ng-bind="commonData.videoStreamStats.file.incoming.error"></span>
</div>
<div ng-show="commonData.videoStreamStats.file !== null && commonData.videoStreamStats.file.file !== null">
<label>File:</label>
<span ng-class="{'text-success': commonData.videoStreamStats.file.file.status=='connected'}"><i class="fa-solid fa-cloud"></i></span>
<label>status: </label><span ng-bind="commonData.videoStreamStats.file.file.status"></span>
<label>time: </label><span ng-bind="commonData.videoStreamStats.file.file.info.time"></span>
<label>frame: </label><span ng-bind="commonData.videoStreamStats.file.file.info.frame"></span>
<label>size: </label><span ng-bind="commonData.videoStreamStats.file.file.info.size"></span>
<label>fps: </label> <span ng-bind="commonData.videoStreamStats.file.file.info.fps"></span>
<label>bitrate: </label><span ng-bind="commonData.videoStreamStats.file.file.info.bitrate"></span>
<label>speed: </label><span ng-bind="commonData.videoStreamStats.file.file.info.speed"></span>
<label ng-show="commonData.videoStreamStats.file.file.error !== null">error: </label><span ng-show="commonData.videoStreamStats.file.file.error !== null" ng-bind="commonData.videoStreamStats.file.file.error"></span>
</div>
</div>
</div>
Expand All @@ -1250,7 +1263,7 @@
<button class="btn btn-primary" ng-click="videoStreamYoutubeStart()">Start Stream</button>
<button class="btn btn-primary" ng-click="videoStreamYoutubeStop()">Stop Stream</button>
</div>
<div ng-show="commonData.videoStreamStats.youtube.info !== undefined">
<div ng-show="commonData.videoStreamStats.youtube !== null">
<span ng-class="{'text-success': commonData.videoStreamStats.youtube.status=='connected'}"><i class="fa-solid fa-cloud"></i></span>
<label>status: </label><span ng-bind="commonData.videoStreamStats.youtube.status"></span>
<label>time: </label><span ng-bind="commonData.videoStreamStats.youtube.info.time"></span>
Expand Down Expand Up @@ -1283,7 +1296,7 @@
<button class="btn btn-primary" ng-click="videoStreamGameChangerStart()">Start Stream</button>
<button class="btn btn-primary" ng-click="videoStreamGameChangerStop()">Stop Stream</button>
</div>
<div ng-show="commonData.videoStreamStats.gamechanger.info !== undefined">
<div ng-show="commonData.videoStreamStats.gamechanger !== null">
<span ng-class="{'text-success': commonData.videoStreamStats.gamechanger.status=='connected'}"><i class="fa-solid fa-cloud"></i></span>
<label>status: </label><span ng-bind="commonData.videoStreamStats.gamechanger.status"></span>
<label>time: </label><span ng-bind="commonData.videoStreamStats.gamechanger.info.time"></span>
Expand Down
7 changes: 7 additions & 0 deletions public/app/scoreboard/scoreboardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1380,16 +1380,23 @@
case "updateSettings":
updateVideoStreamSettings(message.data);
break;
case "allStreamStats":
//$.extend($scope.commonData.videoStreamStats.youtube, message.data);
$scope.commonData.videoStreamStats = message.data;
$scope.$apply();
break;
case "youtubeStreamStats":
//$.extend($scope.commonData.videoStreamStats.youtube, message.data);
$scope.commonData.videoStreamStats.youtube = message.data;
$scope.$apply();
break;
case "gamechangerStreamStats":
$scope.commonData.videoStreamStats.gamechanger = message.data;
$scope.$apply();
break;
case "fileStreamStats":
$scope.commonData.videoStreamStats.file = message.data;
$scope.$apply();
break;
}
//$scope.$apply();
Expand Down

0 comments on commit 0eb85b6

Please sign in to comment.