(params: {
videoPath: string;
scriptPath: string;
scriptArgs: string[];
commandDescription: string;
})
| 64 | } |
| 65 | |
| 66 | async function exportProcessedVideo(params: { |
| 67 | videoPath: string; |
| 68 | scriptPath: string; |
| 69 | scriptArgs: string[]; |
| 70 | commandDescription: string; |
| 71 | }): Promise<void> { |
| 72 | const { videoPath, scriptPath, scriptArgs, commandDescription } = params; |
| 73 | await waitForStableFile(videoPath); |
| 74 | await waitForPlayableVideo(videoPath); |
| 75 | |
| 76 | const outputPath = temporarySiblingVideoPath(videoPath); |
| 77 | try { |
| 78 | const executablePath = await compileSwiftSourceFile({ sourcePath: scriptPath }); |
| 79 | await runCmd(executablePath, ['--input', videoPath, '--output', outputPath, ...scriptArgs], { |
| 80 | timeoutMs: 120_000, |
| 81 | env: buildSwiftToolEnv(), |
| 82 | }); |
| 83 | await waitForPlayableVideo(outputPath); |
| 84 | fs.renameSync(outputPath, videoPath); |
| 85 | } catch (error) { |
| 86 | const cause = |
| 87 | error instanceof AppError |
| 88 | ? error |
| 89 | : new AppError( |
| 90 | 'COMMAND_FAILED', |
| 91 | String(error), |
| 92 | undefined, |
| 93 | error instanceof Error ? error : undefined, |
| 94 | ); |
| 95 | throw new AppError( |
| 96 | 'COMMAND_FAILED', |
| 97 | commandDescription, |
| 98 | { |
| 99 | ...cause.details, |
| 100 | videoPath, |
| 101 | script: scriptPath, |
| 102 | }, |
| 103 | cause, |
| 104 | ); |
| 105 | } finally { |
| 106 | fs.rmSync(outputPath, { force: true }); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | function temporarySiblingVideoPath(videoPath: string): string { |
| 111 | const parsed = path.parse(videoPath); |
no test coverage detected