cherrypick(release-1.4): check for ffmpeg only when starting screencast (#3893)

- PR #3874 SHA: e5c6b19c00

References #3845
This commit is contained in:
Andrey Lushnikov 2020-09-15 16:00:13 -07:00 committed by GitHub
parent 8795d46519
commit 8bc84ff349
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 22 deletions

2
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "playwright-internal", "name": "playwright-internal",
"version": "1.4.0-post", "version": "1.4.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View file

@ -14,13 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
import { launchProcess } from '../processLauncher';
import { ChildProcess } from 'child_process'; import { ChildProcess } from 'child_process';
import * as os from 'os';
import * as path from 'path';
import { assert } from '../../utils/utils';
import { launchProcess } from '../processLauncher';
import { Progress, runAbortableTask } from '../progress'; import { Progress, runAbortableTask } from '../progress';
import * as types from '../types'; import * as types from '../types';
import * as path from 'path'; import { spawnAsync } from '../validateDependencies';
import * as os from 'os';
import { assert } from '../../utils/utils';
const fps = 25; const fps = 25;
@ -59,10 +60,16 @@ export class VideoRecorder {
let ffmpegPath = 'ffmpeg'; let ffmpegPath = 'ffmpeg';
const binPath = path.join(__dirname, '../../../third_party/ffmpeg/'); const binPath = path.join(__dirname, '../../../third_party/ffmpeg/');
if (os.platform() === 'win32') if (os.platform() === 'win32') {
ffmpegPath = path.join(binPath, os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe'); ffmpegPath = path.join(binPath, os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe');
else if (os.platform() === 'darwin') } else if (os.platform() === 'darwin') {
ffmpegPath = path.join(binPath, 'ffmpeg-mac'); ffmpegPath = path.join(binPath, 'ffmpeg-mac');
} else {
// Look for ffmpeg in PATH.
const {code, error} = await spawnAsync(ffmpegPath, ['-version'], {});
if (code !== 0 || error)
throw new Error('ffmpeg not found.\nInstall missing packages with:\n sudo apt-get install ffmpeg');
}
const { launchedProcess, gracefullyClose } = await launchProcess({ const { launchedProcess, gracefullyClose } = await launchProcess({
executablePath: ffmpegPath, executablePath: ffmpegPath,
args, args,

View file

@ -112,8 +112,6 @@ async function validateDependenciesLinux(browserPath: string, browser: BrowserDe
} }
for (const dep of (await missingDLOPENLibraries(browser))) for (const dep of (await missingDLOPENLibraries(browser)))
missingDeps.add(dep); missingDeps.add(dep);
for (const dep of (await missingSystemBinaries(browser)))
missingDeps.add(dep);
if (!missingDeps.size) if (!missingDeps.size)
return; return;
// Check Ubuntu version. // Check Ubuntu version.
@ -233,17 +231,7 @@ async function missingDLOPENLibraries(browser: BrowserDescriptor): Promise<strin
return libraries.filter(library => !isLibraryAvailable(library)); return libraries.filter(library => !isLibraryAvailable(library));
} }
async function missingSystemBinaries(browser: BrowserDescriptor): Promise<string[]> { export function spawnAsync(cmd: string, args: string[], options: any): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
if (browser.name !== 'chromium')
return [];
// Look for ffmpeg in PATH.
const {code, error} = await spawnAsync('ffmpeg', ['-version'], {});
if (code !== 0 || error)
return ['ffmpeg'];
return [];
}
function spawnAsync(cmd: string, args: string[], options: any): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
const process = spawn(cmd, args, options); const process = spawn(cmd, args, options);
return new Promise(resolve => { return new Promise(resolve => {
@ -436,6 +424,4 @@ const MANUAL_LIBRARY_TO_PACKAGE_NAME_UBUNTU: { [s: string]: string} = {
// and if it's missing recommend installing missing gstreamer lib. // and if it's missing recommend installing missing gstreamer lib.
// gstreamer1.0-libav -> libavcodec57 -> libx264-152 // gstreamer1.0-libav -> libavcodec57 -> libx264-152
'libx264.so': 'gstreamer1.0-libav', 'libx264.so': 'gstreamer1.0-libav',
// Required for screencast in Chromium.
'ffmpeg': 'ffmpeg',
}; };