Skip to content

Commit

Permalink
fix(launcher): check for ffmpeg only when starting screencast (#3874)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Sep 14, 2020
1 parent c20cbae commit e5c6b19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
19 changes: 13 additions & 6 deletions src/server/chromium/videoRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

import { launchProcess } from '../processLauncher';
import { ChildProcess } from 'child_process';
import { Progress, ProgressController } from '../progress';
import * as types from '../types';
import * as path from 'path';
import * as os from 'os';
import * as path from 'path';
import { assert } from '../../utils/utils';
import { launchProcess } from '../processLauncher';
import { Progress, ProgressController } from '../progress';
import * as types from '../types';
import { spawnAsync } from '../validateDependencies';

const fps = 25;

Expand Down Expand Up @@ -61,10 +62,16 @@ export class VideoRecorder {

let ffmpegPath = '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');
else if (os.platform() === 'darwin')
} else if (os.platform() === 'darwin') {
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({
executablePath: ffmpegPath,
args,
Expand Down
16 changes: 1 addition & 15 deletions src/server/validateDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ async function validateDependenciesLinux(browserPath: string, browser: BrowserDe
}
for (const dep of (await missingDLOPENLibraries(browser)))
missingDeps.add(dep);
for (const dep of (await missingSystemBinaries(browser)))
missingDeps.add(dep);
if (!missingDeps.size)
return;
// Check Ubuntu version.
Expand Down Expand Up @@ -236,17 +234,7 @@ async function missingDLOPENLibraries(browser: BrowserDescriptor): Promise<strin
return libraries.filter(library => !isLibraryAvailable(library));
}

async function missingSystemBinaries(browser: BrowserDescriptor): Promise<string[]> {
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}> {
export function spawnAsync(cmd: string, args: string[], options: any): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
const process = spawn(cmd, args, options);

return new Promise(resolve => {
Expand Down Expand Up @@ -439,6 +427,4 @@ const MANUAL_LIBRARY_TO_PACKAGE_NAME_UBUNTU: { [s: string]: string} = {
// and if it's missing recommend installing missing gstreamer lib.
// gstreamer1.0-libav -> libavcodec57 -> libx264-152
'libx264.so': 'gstreamer1.0-libav',
// Required for screencast in Chromium.
'ffmpeg': 'ffmpeg',
};

0 comments on commit e5c6b19

Please sign in to comment.