added Fps limiter

This commit is contained in:
devl0rd 2020-04-26 18:24:33 -06:00
parent c4b571f4e0
commit ce26ded7c2
5 changed files with 44 additions and 8 deletions

View file

@ -17,6 +17,7 @@ var hidStreamClient = new net.Socket();
var usingVideo = true; var usingVideo = true;
var usingAudio = true; var usingAudio = true;
var abxySwap = false; var abxySwap = false;
var limitFPS = false;
var encoding = "CPU"; var encoding = "CPU";
function connect() { function connect() {
hidStreamClient.connect({ hidStreamClient.connect({
@ -64,12 +65,16 @@ function startAudioProcess() {
}); });
} }
function startVideoProcess() { function startVideoProcess() {
var fps = 60;
if (limitFPS) {
fps = 30;
}
var ffmpegVideoArgs = []; var ffmpegVideoArgs = [];
if (encoding == "NVENC") { if (encoding == "NVENC") {
ffmpegVideoArgs = ["-probesize", "50M", "-threads", "0", "-f", "gdigrab", "-framerate", "60", "-video_size", swidth + "x" + sheight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-c:v", "h264_nvenc", "-gpu", "0", "-rc", "cbr_ld_hq", "-zerolatency", "true", "-f", "h264", "-vf", "scale=1280x720", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-b:v", quality + "M", "-minrate", quality - 3 + "M", "-maxrate", quality + "M", "-bufsize", (quality / 2) + "M", "tcp://" + ip + ":2222"]; ffmpegVideoArgs = ["-probesize", "50M", "-threads", "0", "-f", "gdigrab", "-framerate", fps, "-video_size", swidth + "x" + sheight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-c:v", "h264_nvenc", "-gpu", "0", "-rc", "cbr_ld_hq", "-zerolatency", "true", "-f", "h264", "-vf", "scale=1280x720", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-b:v", quality + "M", "-minrate", quality - 3 + "M", "-maxrate", quality + "M", "-bufsize", (quality / 2) + "M", "tcp://" + ip + ":2222"];
console.log("Using Nvidia Encoding"); console.log("Using Nvidia Encoding");
} else { } else {
ffmpegVideoArgs = ["-probesize", "50M", "-threads", "0", "-f", "gdigrab", "-framerate", "60", "-video_size", swidth + "x" + sheight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-f", "h264", "-vf", "scale=1280x720", "-preset", "ultrafast", "-tune", "zerolatency", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-x264-params", 'nal-hrd=cbr', "-b:v", quality + "M", "-minrate", quality - 3 + "M", "-maxrate", quality + "M", "-bufsize", (quality / 2) + "M", "tcp://" + ip + ":2222"]; ffmpegVideoArgs = ["-probesize", "50M", "-threads", "0", "-f", "gdigrab", "-framerate", fps, "-video_size", swidth + "x" + sheight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-f", "h264", "-vf", "scale=1280x720", "-preset", "ultrafast", "-tune", "zerolatency", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-x264-params", 'nal-hrd=cbr', "-b:v", quality + "M", "-minrate", quality - 3 + "M", "-maxrate", quality + "M", "-bufsize", (quality / 2) + "M", "tcp://" + ip + ":2222"];
console.log("Using CPU Encoding"); console.log("Using CPU Encoding");
} }
ffmpegProcess = spawn( ffmpegProcess = spawn(
@ -413,6 +418,11 @@ if (args.length > 1) {
} else { } else {
abxySwap = false; abxySwap = false;
} }
if (args.includes("/limitFPS")) {
limitFPS = true;
} else {
limitFPS = false;
}
if (args.includes("/e") && args[args.indexOf("/e") + 1]) { if (args.includes("/e") && args[args.indexOf("/e") + 1]) {
encoding = args[args.indexOf("/e") + 1]; encoding = args[args.indexOf("/e") + 1];
} else { } else {

View file

@ -69,7 +69,8 @@
<input id="disableVideo" type="checkbox"> <input id="disableVideo" type="checkbox">
<span class="slider round"></span> <span class="slider round"></span>
</label> </label>
<label class="form-check-label" for="rainbowEnabled"> <label class="form-check-label" for="disableVideo"
title="Great for using you switch as a controller dongle">
Disable Video Disable Video
</label> </label>
</div> </div>
@ -78,7 +79,7 @@
<input id="disableAudio" type="checkbox"> <input id="disableAudio" type="checkbox">
<span class="slider round"></span> <span class="slider round"></span>
</label> </label>
<label class="form-check-label" for="rainbowEnabled"> <label class="form-check-label" for="disableAudio">
Disable Audio Disable Audio
</label> </label>
</div> </div>
@ -87,10 +88,20 @@
<input id="abxySwap" type="checkbox"> <input id="abxySwap" type="checkbox">
<span class="slider round"></span> <span class="slider round"></span>
</label> </label>
<label class="form-check-label" for="rainbowEnabled"> <label class="form-check-label" for="abxySwap" title="Makes your controllers labels match xBox controls">
Swap A-B X-Y Swap A-B X-Y
</label> </label>
</div> </div>
<div class="form-group">
<label class="switch">
<input id="limitFPS" type="checkbox">
<span class="slider round"></span>
</label>
<label class="form-check-label" for="limitFPS"
title="Great when streaming emulators or games running at 30.">
30Fps Limit
</label>
</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -11,13 +11,13 @@ ipcRenderer.on('started', function (event, data) {
}) })
var running = false; var running = false;
function connect() { function connect() {
ipcRenderer.send('connect', { ip: clientSettings.ip, q: clientSettings.quality, disableVideo: clientSettings.disableVideo, disableAudio: clientSettings.disableAudio, abxySwap: clientSettings.abxySwap, encoding: clientSettings.encoding }); ipcRenderer.send('connect', { ip: clientSettings.ip, q: clientSettings.quality, disableVideo: clientSettings.disableVideo, disableAudio: clientSettings.disableAudio, abxySwap: clientSettings.abxySwap, encoding: clientSettings.encoding, limitFPS: clientSettings.limitFPS });
} }
function disconnect() { function disconnect() {
ipcRenderer.send('kill'); ipcRenderer.send('kill');
} }
function restart() { function restart() {
ipcRenderer.send('restart', { ip: clientSettings.ip, q: clientSettings.quality, disableVideo: clientSettings.disableVideo, disableAudio: clientSettings.disableAudio, abxySwap: clientSettings.abxySwap, encoding: clientSettings.encoding }); ipcRenderer.send('restart', { ip: clientSettings.ip, q: clientSettings.quality, disableVideo: clientSettings.disableVideo, disableAudio: clientSettings.disableAudio, abxySwap: clientSettings.abxySwap, encoding: clientSettings.encoding, limitFPS: clientSettings.limitFPS });
} }
$('#startBtn').click(function () { $('#startBtn').click(function () {
if (!running) { if (!running) {

View file

@ -44,6 +44,9 @@ function initSettings() {
if (!clientSettings.hasOwnProperty("abxySwap")) { if (!clientSettings.hasOwnProperty("abxySwap")) {
clientSettings.abxySwap = false; clientSettings.abxySwap = false;
} }
if (!clientSettings.hasOwnProperty("limitFPS")) {
clientSettings.limitFPS = false;
}
if (!clientSettings.hasOwnProperty("encoding")) { if (!clientSettings.hasOwnProperty("encoding")) {
clientSettings.encoding = "CPU"; clientSettings.encoding = "CPU";
} }
@ -73,6 +76,7 @@ function applyClientSettings() {
$('#disableVideo').prop("checked", clientSettings.disableVideo); $('#disableVideo').prop("checked", clientSettings.disableVideo);
$('#disableAudio').prop("checked", clientSettings.disableAudio); $('#disableAudio').prop("checked", clientSettings.disableAudio);
$('#abxySwap').prop("checked", clientSettings.abxySwap); $('#abxySwap').prop("checked", clientSettings.abxySwap);
$('#limitFPS').prop("checked", clientSettings.limitFPS);
$("#ipInput").val(clientSettings.ip); $("#ipInput").val(clientSettings.ip);
if (clientSettings.encoding == "NVENC") { if (clientSettings.encoding == "NVENC") {
$("#encodingDrop").html("Encoding (Nvidia)"); $("#encodingDrop").html("Encoding (Nvidia)");
@ -190,6 +194,15 @@ $("#abxySwap").on('change', function () {
saveClientSettings(); saveClientSettings();
applyClientSettings(); applyClientSettings();
}); });
$("#limitFPS").on('change', function () {
clientSettings.limitFPS = $("#limitFPS").prop("checked");
if (running) {
restart();
}
saveClientSettings();
applyClientSettings();
});
$("#settings-btn").click(function () { $("#settings-btn").click(function () {
$(".contentArea").hide(); $(".contentArea").hide();
$("#settings").fadeIn(400); $("#settings").fadeIn(400);

View file

@ -119,7 +119,9 @@ function startStreamer(arg) {
args.push("/e"); args.push("/e");
args.push("NVENC"); args.push("NVENC");
} }
if (arg.limitFPS) {
args.push("/limitFPS");
}
streamerProcess = spawn( streamerProcess = spawn(
"./NxStreamingService.exe", "./NxStreamingService.exe",
args, args,