Skip to content
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
16 changes: 5 additions & 11 deletions src/server/chromium/videoRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

import { ChildProcess } from 'child_process';
import * as os from 'os';
import * as path from 'path';
import { ffmpegExecutable } from '../../utils/binaryPaths';
import { assert } from '../../utils/utils';
import { launchProcess } from '../processLauncher';
import { Progress, ProgressController } from '../progress';
Expand Down Expand Up @@ -59,16 +58,11 @@ export class VideoRecorder {
args.push(options.outputFile);
const progress = this._progress;

let ffmpegPath = 'ffmpeg';
const binPath = path.join(__dirname, '../../../third_party/ffmpeg/');
if (os.platform() === 'win32')
ffmpegPath = path.join(binPath, os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe');
else if (os.platform() === 'darwin')
ffmpegPath = path.join(binPath, 'ffmpeg-mac');
else
ffmpegPath = path.join(binPath, 'ffmpeg-linux');
const executablePath = ffmpegExecutable();
if (!executablePath)
throw new Error('ffmpeg executable was not found');
const { launchedProcess, gracefullyClose } = await launchProcess({
executablePath: ffmpegPath,
executablePath,
args,
pipeStdin: true,
progress,
Expand Down
8 changes: 6 additions & 2 deletions src/server/validateDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as os from 'os';
import { spawn } from 'child_process';
import { getUbuntuVersion } from '../utils/ubuntuVersion';
import { linuxLddDirectories, windowsExeAndDllDirectories, BrowserDescriptor } from '../utils/browserPaths.js';
import { printDepsWindowsExecutable } from '../utils/binaryPaths';

const accessAsync = util.promisify(fs.access.bind(fs));
const checkExecutable = (filePath: string) => accessAsync(filePath, fs.constants.X_OK).then(() => true).catch(e => false);
Expand Down Expand Up @@ -190,9 +191,12 @@ async function executablesOrSharedLibraries(directoryPath: string): Promise<stri
}

async function missingFileDependenciesWindows(filePath: string): Promise<Array<string>> {
const executable = printDepsWindowsExecutable();
if (!executable)
return [];

const dirname = path.dirname(filePath);
const printDepsWindowsExecutable = process.env.PW_PRINT_DEPS_WINDOWS_EXECUTABLE || path.join(__dirname, '../../bin/PrintDeps.exe');
const {stdout, code} = await spawnAsync(printDepsWindowsExecutable, [filePath], {
const {stdout, code} = await spawnAsync(executable, [filePath], {
cwd: dirname,
env: {
...process.env,
Expand Down
51 changes: 51 additions & 0 deletions src/utils/binaryPaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';

export function printDepsWindowsExecutable(): string | undefined {
return pathToExecutable(['bin', 'PrintDeps.exe']);
}

export function ffmpegExecutable(): string | undefined {
let ffmpegName;
if (process.platform === 'win32')
ffmpegName = os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe';
else if (process.platform === 'darwin')
ffmpegName = 'ffmpeg-mac';
else
ffmpegName = 'ffmpeg-linux';
return pathToExecutable(['third_party', 'ffmpeg', ffmpegName]);
}

function pathToExecutable(relative: string[]): string | undefined {
const defaultPath = path.join(__dirname, '..', '..', ...relative);
const localPath = path.join(path.dirname(process.argv[0]), relative[relative.length - 1]);
try {
if (fs.existsSync(defaultPath))
return defaultPath;
} catch (e) {
}

try {
if (fs.existsSync(localPath))
return localPath;
} catch (e) {
}
}