From fc296235080a14f9ed74f642e082f313723782c4 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 2 Sep 2020 08:47:43 -0700 Subject: [PATCH] feat(screencast): use system ffmpeg on linux (#3724) --- .github/workflows/infra.yml | 1 + src/server/chromium/videoRecorder.ts | 3 ++- src/server/validateDependencies.ts | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/infra.yml b/.github/workflows/infra.yml index 8eccd7b369..7523e3d887 100644 --- a/.github/workflows/infra.yml +++ b/.github/workflows/infra.yml @@ -24,6 +24,7 @@ jobs: sudo apt-get update sudo apt-get install libgbm-dev sudo apt-get install xvfb + sudo apt-get install ffmpeg - run: npm ci - run: npm run build - run: npm run lint diff --git a/src/server/chromium/videoRecorder.ts b/src/server/chromium/videoRecorder.ts index da50437879..9c4fd1a2e5 100644 --- a/src/server/chromium/videoRecorder.ts +++ b/src/server/chromium/videoRecorder.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path; import { launchProcess } from '../processLauncher'; import { ChildProcess } from 'child_process'; import { Progress, runAbortableTask } from '../progress'; @@ -55,6 +54,8 @@ export class VideoRecorder { const args = `-f image2pipe -c:v mjpeg -i - -y -an -r ${fps} -c:v vp8 -vf pad=${w}:${h}:0:0:gray,crop=${w}:${h}:0:0`.split(' '); args.push(options.outputFile); const progress = this._progress; + // Use ffmpeg provided by the host system. + const ffmpegPath = process.platform === 'linux' ? 'ffmpeg' : require('@ffmpeg-installer/ffmpeg').path; const { launchedProcess, gracefullyClose } = await launchProcess({ executablePath: ffmpegPath, args, diff --git a/src/server/validateDependencies.ts b/src/server/validateDependencies.ts index 734a1e921a..98a4193c5e 100644 --- a/src/server/validateDependencies.ts +++ b/src/server/validateDependencies.ts @@ -112,6 +112,8 @@ 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. @@ -231,6 +233,16 @@ async function missingDLOPENLibraries(browser: BrowserDescriptor): Promise !isLibraryAvailable(library)); } +async function missingSystemBinaries(browser: BrowserDescriptor): Promise { + 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); @@ -423,5 +435,7 @@ const MANUAL_LIBRARY_TO_PACKAGE_NAME_UBUNTU: { [s: string]: string} = { // in the ldconfig cache, so we detect the actual library required for playing h.264 // and if it's missing recommend installing missing gstreamer lib. // gstreamer1.0-libav -> libavcodec57 -> libx264-152 - 'libx264.so': 'gstreamer1.0-libav' + 'libx264.so': 'gstreamer1.0-libav', + // Required for screencast in Chromium. + 'ffmpeg': 'ffmpeg', };