From f6026de2f0a094fe184e5e0a78416806335ff75c Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Thu, 18 Feb 2021 08:08:29 -0800 Subject: [PATCH] Record video always in 1280x720 Summary: Video recording for Android devices is quite unreliable now, because not all resolutions are supported: https://android.stackexchange.com/questions/168944/unable-to-get-output-buffers-err-38-when-attempting-to-screen-record-emulator In this diff I changed resolution for the captured videos to always be 1280x720 or 720x1280. These resolutions are always supported because they are used by default if device native resolution cannot be detected. Changelog: Android video is now always captured in 1280x720 / 720x1280 to avoid the issue when video cannot be captured because of unsupported resolution (err=-38) Reviewed By: mweststrate Differential Revision: D26225203 fbshipit-source-id: 0f9491309bf049fd975f20e096c5c7362d830adc --- desktop/app/src/devices/AndroidDevice.tsx | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/desktop/app/src/devices/AndroidDevice.tsx b/desktop/app/src/devices/AndroidDevice.tsx index b25be5f2841..518703fc90b 100644 --- a/desktop/app/src/devices/AndroidDevice.tsx +++ b/desktop/app/src/devices/AndroidDevice.tsx @@ -158,8 +158,28 @@ export default class AndroidDevice extends BaseDevice { `mkdir -p "${DEVICE_RECORDING_DIR}" && echo -n > "${DEVICE_RECORDING_DIR}/.nomedia"`, ); const recordingLocation = `${DEVICE_RECORDING_DIR}/video.mp4`; + let newSize: string | undefined; + try { + const sizeString = ( + await adb.util.readAll(await this.adb.shell(this.serial, 'wm size')) + ).toString(); + const size = sizeString.split(' ').slice(-1).pop()?.split('x'); + if (size && size.length === 2) { + const width = parseInt(size[0], 10); + const height = parseInt(size[1], 10); + if (width > height) { + newSize = '1280x720'; + } else { + newSize = '720x1280'; + } + } + } catch (err) { + console.error('Error while getting device size', err); + } + const sizeArg = newSize ? `--size ${newSize}` : ''; + const cmd = `screenrecord --bugreport ${sizeArg} "${recordingLocation}"`; this.recordingProcess = this.adb - .shell(this.serial, `screenrecord --bugreport "${recordingLocation}"`) + .shell(this.serial, cmd) .then(adb.util.readAll) .then(async (output) => { const isValid = await this.isValidFile(recordingLocation); @@ -176,7 +196,9 @@ export default class AndroidDevice extends BaseDevice { this.adb.pull(this.serial, recordingLocation).then((stream) => { stream.on('end', resolve as () => void); stream.on('error', reject); - stream.pipe(createWriteStream(destination)); + stream.pipe(createWriteStream(destination, {autoClose: true}), { + end: true, + }); }); }), )