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

This commit is contained in:
Yury Semikhatsky 2020-09-02 08:47:43 -07:00 committed by GitHub
parent 659013051f
commit fc29623508
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View file

@ -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

View file

@ -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,

View file

@ -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<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);
@ -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',
};