diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2023-03-18 03:31:10 +0100 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2023-03-22 14:08:01 +0100 |
commit | c4bb8002b2124d7af8ec26ee44396df8d8df3015 (patch) | |
tree | 0a25dbd5c762609170539e5b5ed0a90f7e92c674 /recording | |
parent | ecfb51a953dcecf7b185353531dfd56c048dfa04 (diff) |
Extract builder for recorder arguments to its own class
This will make easier to override the values set in the configuration
for specific runs.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'recording')
3 files changed, 81 insertions, 43 deletions
diff --git a/recording/src/nextcloud/talk/recording/RecorderArgumentsBuilder.py b/recording/src/nextcloud/talk/recording/RecorderArgumentsBuilder.py new file mode 100644 index 000000000..c0f89ca15 --- /dev/null +++ b/recording/src/nextcloud/talk/recording/RecorderArgumentsBuilder.py @@ -0,0 +1,74 @@ +# +# @copyright Copyright (c) 2023, Daniel Calviño Sánchez (danxuliu@gmail.com) +# +# @license GNU AGPL version 3 or any later version +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +from nextcloud.talk.recording import RECORDING_STATUS_AUDIO_AND_VIDEO, RECORDING_STATUS_AUDIO_ONLY +from .Config import config + +class RecorderArgumentsBuilder: + """ + Helper class to get the arguments to start the recorder process. + + Some of the recorder arguments, like the arguments for the output video + codec, can be customized. Those values are got from the configuration, + either a specific value set in the configuration file or a default value. + """ + + def __init__(self): + self._ffmpegOutputAudio = None + self._ffmpegOutputVideo = None + self._extension = None + + def getRecorderArguments(self, status, displayId, audioSinkIndex, width, height, extensionlessOutputFileName): + """ + Returns the list of arguments to start the recorder process. + + :param status: whether to record audio and video or only audio. + :param displayId: the ID of the display that the browser is running in. + :param audioSinkIndex: the index of the sink for the browser audio output. + :param width: the width of the display and the recording. + :param height: the height of the display and the recording. + :param extensionlessOutputFileName: the file name for the recording, without + extension. + :returns: the file name for the recording, with extension. + """ + + ffmpegCommon = ['ffmpeg', '-loglevel', 'level+warning', '-n'] + ffmpegInputAudio = ['-f', 'pulse', '-i', audioSinkIndex] + ffmpegInputVideo = ['-f', 'x11grab', '-draw_mouse', '0', '-video_size', f'{width}x{height}', '-i', displayId] + ffmpegOutputAudio = config.getFfmpegOutputAudio() + ffmpegOutputVideo = config.getFfmpegOutputVideo() + + extension = config.getFfmpegExtensionAudio() + if status == RECORDING_STATUS_AUDIO_AND_VIDEO: + extension = config.getFfmpegExtensionVideo() + + outputFileName = extensionlessOutputFileName + extension + + ffmpegArguments = ffmpegCommon + ffmpegArguments += ffmpegInputAudio + + if status == RECORDING_STATUS_AUDIO_AND_VIDEO: + ffmpegArguments += ffmpegInputVideo + + ffmpegArguments += ffmpegOutputAudio + + if status == RECORDING_STATUS_AUDIO_AND_VIDEO: + ffmpegArguments += ffmpegOutputVideo + + return ffmpegArguments + [outputFileName] diff --git a/recording/src/nextcloud/talk/recording/Service.py b/recording/src/nextcloud/talk/recording/Service.py index 1cece1a68..4f575d05f 100644 --- a/recording/src/nextcloud/talk/recording/Service.py +++ b/recording/src/nextcloud/talk/recording/Service.py @@ -30,51 +30,11 @@ from pyvirtualdisplay import Display from secrets import token_urlsafe from threading import Event, Thread +from nextcloud.talk.recording import RECORDING_STATUS_AUDIO_AND_VIDEO, RECORDING_STATUS_AUDIO_ONLY from . import BackendNotifier from .Config import config from .Participant import Participant - -RECORDING_STATUS_AUDIO_AND_VIDEO = 1 -RECORDING_STATUS_AUDIO_ONLY = 2 - -def getRecorderArguments(status, displayId, audioSinkIndex, width, height, extensionlessOutputFileName): - """ - Returns the list of arguments to start the recorder process. - - :param status: whether to record audio and video or only audio. - :param displayId: the ID of the display that the browser is running in. - :param audioSinkIndex: the index of the sink for the browser audio output. - :param width: the width of the display and the recording. - :param height: the height of the display and the recording. - :param extensionlessOutputFileName: the file name for the recording, without - extension. - :returns: the file name for the recording, with extension. - """ - - ffmpegCommon = ['ffmpeg', '-loglevel', 'level+warning', '-n'] - ffmpegInputAudio = ['-f', 'pulse', '-i', audioSinkIndex] - ffmpegInputVideo = ['-f', 'x11grab', '-draw_mouse', '0', '-video_size', f'{width}x{height}', '-i', displayId] - ffmpegOutputAudio = config.getFfmpegOutputAudio() - ffmpegOutputVideo = config.getFfmpegOutputVideo() - - extension = config.getFfmpegExtensionAudio() - if status == RECORDING_STATUS_AUDIO_AND_VIDEO: - extension = config.getFfmpegExtensionVideo() - - outputFileName = extensionlessOutputFileName + extension - - ffmpegArguments = ffmpegCommon - ffmpegArguments += ffmpegInputAudio - - if status == RECORDING_STATUS_AUDIO_AND_VIDEO: - ffmpegArguments += ffmpegInputVideo - - ffmpegArguments += ffmpegOutputAudio - - if status == RECORDING_STATUS_AUDIO_AND_VIDEO: - ffmpegArguments += ffmpegOutputVideo - - return ffmpegArguments + [outputFileName] +from .RecorderArgumentsBuilder import RecorderArgumentsBuilder def newAudioSink(baseSinkName): """ @@ -246,7 +206,8 @@ class Service: extensionlessFileName = f'{fullDirectory}/recording-{datetime.now().strftime("%Y%m%d-%H%M%S")}' - recorderArguments = getRecorderArguments(self.status, self._display.new_display_var, audioSinkIndex, width, height, extensionlessFileName) + recorderArgumentsBuilder = RecorderArgumentsBuilder() + recorderArguments = recorderArgumentsBuilder.getRecorderArguments(self.status, self._display.new_display_var, audioSinkIndex, width, height, extensionlessFileName) self._fileName = recorderArguments[-1] diff --git a/recording/src/nextcloud/talk/recording/__init__.py b/recording/src/nextcloud/talk/recording/__init__.py index 80d5d3a8c..42678ef6c 100644 --- a/recording/src/nextcloud/talk/recording/__init__.py +++ b/recording/src/nextcloud/talk/recording/__init__.py @@ -18,3 +18,6 @@ # __version__ = 0.1 + +RECORDING_STATUS_AUDIO_AND_VIDEO = 1 +RECORDING_STATUS_AUDIO_ONLY = 2 |