Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(screencast): use system ffmpeg on linux #3724

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/server/chromium/videoRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion src/server/validateDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -231,6 +233,16 @@ 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}> {
const process = spawn(cmd, args, options);

Expand Down Expand Up @@ -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',
};