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
This commit is contained in:
Anton Nikolaev
2021-02-18 08:08:29 -08:00
committed by Facebook GitHub Bot
parent c0010bea4c
commit f6026de2f0

View File

@@ -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,
});
});
}),
)