Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Record video always in 1280x720
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikoant authored and facebook-github-bot committed Feb 18, 2021
1 parent c0010be commit f6026de
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions desktop/app/src/devices/AndroidDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
});
});
}),
)
Expand Down

0 comments on commit f6026de

Please sign in to comment.