Skip to content

Commit 8bc84ff

Browse files
authored
cherrypick(release-1.4): check for ffmpeg only when starting screencast (microsoft#3893)
- PR microsoft#3874 SHA: e5c6b19 References microsoft#3845
1 parent 8795d46 commit 8bc84ff

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server/chromium/videoRecorder.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { launchProcess } from '../processLauncher';
1817
import { ChildProcess } from 'child_process';
19-
import { Progress, runAbortableTask } from '../progress';
20-
import * as types from '../types';
21-
import * as path from 'path';
2218
import * as os from 'os';
19+
import * as path from 'path';
2320
import { assert } from '../../utils/utils';
21+
import { launchProcess } from '../processLauncher';
22+
import { Progress, runAbortableTask } from '../progress';
23+
import * as types from '../types';
24+
import { spawnAsync } from '../validateDependencies';
2425

2526
const fps = 25;
2627

@@ -59,10 +60,16 @@ export class VideoRecorder {
5960

6061
let ffmpegPath = 'ffmpeg';
6162
const binPath = path.join(__dirname, '../../../third_party/ffmpeg/');
62-
if (os.platform() === 'win32')
63+
if (os.platform() === 'win32') {
6364
ffmpegPath = path.join(binPath, os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe');
64-
else if (os.platform() === 'darwin')
65+
} else if (os.platform() === 'darwin') {
6566
ffmpegPath = path.join(binPath, 'ffmpeg-mac');
67+
} else {
68+
// Look for ffmpeg in PATH.
69+
const {code, error} = await spawnAsync(ffmpegPath, ['-version'], {});
70+
if (code !== 0 || error)
71+
throw new Error('ffmpeg not found.\nInstall missing packages with:\n sudo apt-get install ffmpeg');
72+
}
6673
const { launchedProcess, gracefullyClose } = await launchProcess({
6774
executablePath: ffmpegPath,
6875
args,

src/server/validateDependencies.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ async function validateDependenciesLinux(browserPath: string, browser: BrowserDe
112112
}
113113
for (const dep of (await missingDLOPENLibraries(browser)))
114114
missingDeps.add(dep);
115-
for (const dep of (await missingSystemBinaries(browser)))
116-
missingDeps.add(dep);
117115
if (!missingDeps.size)
118116
return;
119117
// Check Ubuntu version.
@@ -233,17 +231,7 @@ async function missingDLOPENLibraries(browser: BrowserDescriptor): Promise<strin
233231
return libraries.filter(library => !isLibraryAvailable(library));
234232
}
235233

236-
async function missingSystemBinaries(browser: BrowserDescriptor): Promise<string[]> {
237-
if (browser.name !== 'chromium')
238-
return [];
239-
// Look for ffmpeg in PATH.
240-
const {code, error} = await spawnAsync('ffmpeg', ['-version'], {});
241-
if (code !== 0 || error)
242-
return ['ffmpeg'];
243-
return [];
244-
}
245-
246-
function spawnAsync(cmd: string, args: string[], options: any): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
234+
export function spawnAsync(cmd: string, args: string[], options: any): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
247235
const process = spawn(cmd, args, options);
248236

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

0 commit comments

Comments
 (0)