diff --git a/lib/commands/recordscreen.js b/lib/commands/recordscreen.js index ff9cb560a..e53687100 100644 --- a/lib/commands/recordscreen.js +++ b/lib/commands/recordscreen.js @@ -12,6 +12,7 @@ const DEFAULT_RECORDING_TIME_SEC = 60 * 3; const DEFAULT_MJPEG_SERVER_PORT = 9100; const DEFAULT_FPS = 10; const DEFAULT_QUALITY = 'medium'; +const DEFAULT_VCODEC = 'mjpeg'; const MP4_EXT = '.mp4'; const FFMPEG_BINARY = 'ffmpeg'; const ffmpegLogger = logger.getLogger(FFMPEG_BINARY); @@ -49,9 +50,14 @@ class ScreenRecorder { const args = [ '-f', 'mjpeg', '-i', `http://localhost:${localPort}`, - '-vcodec', 'mjpeg', - '-y', this.videoPath, ]; + if (this.opts.videoScale) { + args.push('-vf', `scale=${this.opts.videoScale}`); + } + args.push( + '-vcodec', this.opts.videoType, + '-y', this.videoPath + ); this.mainProcess = new SubProcess(FFMPEG_BINARY, args); this.mainProcess.on('output', (stdout, stderr) => { if (stderr && !stderr.includes('frame=')) { @@ -142,20 +148,23 @@ class ScreenRecorder { * @property {?string} remotePath - The path to the remote location, where the resulting video should be uploaded. * The following protocols are supported: http/https, ftp. * Null or empty string value (the default setting) means the content of resulting - * file should be encoded as Base64 and passed as the endpount response value. + * file should be encoded as Base64 and passed as the endpoint response value. * An exception will be thrown if the generated media file is too big to * fit into the available process memory. - * This option only has an effect if there is screen recording process in progreess + * This option only has an effect if there is screen recording process in progress * and `forceRestart` parameter is not set to `true`. * @property {?string} user - The name of the user for the remote authentication. Only works if `remotePath` is provided. * @property {?string} pass - The password for the remote authentication. Only works if `remotePath` is provided. * @property {?string} method - The http multipart upload method name. The 'PUT' one is used by default. * Only works if `remotePath` is provided. - * @property {?string} videoType - The format of the screen capture to be recorded. - * Available formats: "h264", "mp4" or "fmp4". Default is "mp4". + * @property {?string} videoType - The video codec type used for encoding of the be recorded screen capture. + * Execute `ffmpeg -codecs` in the terminal to see the list of supported video codecs. + * 'mjpeg' by default. * @property {?string|number} videoQuality - The video encoding quality (low, medium, high, photo - defaults to medium). * @property {?string|number} videoFps - The Frames Per Second rate of the recorded video. Change this value if the resulting video * is too slow or too fast. Defaults to 10. + * @property {?string} videoScale - The scaling value to apply. Read https://trac.ffmpeg.org/wiki/Scaling for possible values. + * No scale is applied by default. * @property {?boolean} forceRestart - Whether to try to catch and upload/return the currently running screen recording * (`false`, the default setting) or ignore the result of it and start a new recording * immediately. @@ -164,8 +173,8 @@ class ScreenRecorder { */ /** - * Record the display of devices running iOS Simulator since Xcode 8.3 or real devices since iOS 8 - * (ios-minicap utility is required: https://github.com/openstf/ios-minicap). + * Record the display of devices running iOS Simulator since Xcode 9 or real devices since iOS 11 + * (ffmpeg utility is required: 'brew install ffmpeg'). * It records screen activity to a MPEG-4 file. Audio is not recorded with the video file. * If screen recording has been already started then the command will stop it forcefully and start a new one. * The previously recorded video file will be deleted. @@ -177,11 +186,11 @@ class ScreenRecorder { */ commands.startRecordingScreen = async function (options = {}) { const { - // TODO: Apply video type to ffmpeg command line - // videoType, + videoType = DEFAULT_VCODEC, timeLimit = DEFAULT_RECORDING_TIME_SEC, videoQuality = DEFAULT_QUALITY, videoFps = DEFAULT_FPS, + videoScale, forceRestart, } = options; @@ -200,6 +209,8 @@ commands.startRecordingScreen = async function (options = {}) { const screenRecorder = new ScreenRecorder(this.opts.device.udid, videoPath, { remotePort: this.opts.mjpegServerPort || DEFAULT_MJPEG_SERVER_PORT, usePortForwarding: this.isRealDevice(), + videoType, + videoScale, }); if (!await screenRecorder.interrupt(true)) { log.errorAndThrow('Unable to stop screen recording process'); @@ -264,7 +275,7 @@ commands.startRecordingScreen = async function (options = {}) { * @property {?string} remotePath - The path to the remote location, where the resulting video should be uploaded. * The following protocols are supported: http/https, ftp. * Null or empty string value (the default setting) means the content of resulting - * file should be encoded as Base64 and passed as the endpount response value. + * file should be encoded as Base64 and passed as the endpoint response value. * An exception will be thrown if the generated media file is too big to * fit into the available process memory. * @property {?string} user - The name of the user for the remote authentication. Only works if `remotePath` is provided.