From 51bf7ec17617a9ed056dd563afdb98e17da07373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Tue, 26 Jan 2021 09:31:49 +0100 Subject: [PATCH] screencastService: Improve the gstreamer pipeline for recording The current gstreamer pipeline performs quite bad on slower machines and is dropping lots of frames, improve the pipeline by changing a few things: - Use threads for videoconvert and improve speed of videoconvert by disabling some unneeded things - Add a queue before the encoding step, this allows the encoder to work at its own pace and will lead to a lot more stability - Remove the fixed quantizer and only set a max quantizer, this helps quite a bit with performance - Change the deadline parameter of vp8enc to 1: This makes the encoder go into real time mode, which will make it a lot faster - Set cpu-used to 16, the maximum possible value. - Set static-threshold to 1000, static-threshold is the motion detection threshold, and while a value of 100 is recommended for screencasting in the gstreamer documentation (see [1]), using 1000 appears to perform a lot better and still outputs fairly good quality - Set a larger buffer size than the default size, this seems to get a bit more stability during high load scenarios All in all, those changes make the pipeline drop no more frames when recording at 30 FPS and 2K screen resolution. That was tested on a fairly recent mobile core-i5 processor. Also, because we now have two %T replacement strings for the number of threads, we need to switch to replaceAll(). For that to work, we have to put the %T matching expression into quotes. [1] https://gstreamer.freedesktop.org/documentation/vpx/GstVPXEnc.html?gi-language=c#GstVPXEnc:static-threshold Part-of: --- js/dbusServices/screencast/screencastService.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/js/dbusServices/screencast/screencastService.js b/js/dbusServices/screencast/screencastService.js index 94e6f8f9c..fb56fdb3a 100644 --- a/js/dbusServices/screencast/screencastService.js +++ b/js/dbusServices/screencast/screencastService.js @@ -23,7 +23,7 @@ const ScreenCastProxy = Gio.DBusProxy.makeProxyWrapper(ScreenCastIface); const ScreenCastSessionProxy = Gio.DBusProxy.makeProxyWrapper(ScreenCastSessionIface); const ScreenCastStreamProxy = Gio.DBusProxy.makeProxyWrapper(ScreenCastStreamIface); -const DEFAULT_PIPELINE = 'vp8enc min_quantizer=13 max_quantizer=13 cpu-used=5 deadline=1000000 threads=%T ! queue ! webmmux'; +const DEFAULT_PIPELINE = 'videoconvert chroma-mode=GST_VIDEO_CHROMA_MODE_NONE dither=GST_VIDEO_DITHER_NONE matrix-mode=GST_VIDEO_MATRIX_MODE_OUTPUT_ONLY n-threads=%T ! queue ! vp8enc cpu-used=16 max-quantizer=17 deadline=1 keyframe-mode=disabled threads=%T static-threshold=1000 buffer-size=20000 ! queue ! webmmux'; const DEFAULT_FRAMERATE = 30; const DEFAULT_DRAW_CURSOR = true; @@ -218,7 +218,7 @@ var Recorder = class { _substituteThreadCount(pipelineDescr) { const numProcessors = GLib.get_num_processors(); const numThreads = Math.min(Math.max(1, numProcessors), 64); - return pipelineDescr.replace(/%T/, numThreads); + return pipelineDescr.replaceAll('%T', numThreads); } _ensurePipeline(nodeId) { @@ -230,7 +230,6 @@ var Recorder = class { keepalive-time=1000 resend-last=true ! video/x-raw,max-framerate=${framerate}/1 ! - videoconvert ! ${this._pipelineString} ! filesink location="${this._filePath}"`; fullPipeline = this._substituteThreadCount(fullPipeline);