File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change 1- import { execSync } from 'node:child_process'
1+ import { spawn } from 'node:child_process'
22
33import * as puppeteer from 'puppeteer-core'
44
@@ -87,11 +87,27 @@ async function main() {
8787 ' ' ,
8888 )
8989
90- execSync ( ffmpegCmd )
90+ const ffmpeg = spawn ( ffmpegCmd , { shell : true } )
9191
92- await browser . close ( )
92+ const forwardSignal = ( signal : NodeJS . Signals | number ) => {
93+ ffmpeg . kill ( signal )
94+ }
9395
94- await exporter . finalizeExport ( )
96+ process . on ( 'SIGINT' , forwardSignal )
97+ process . on ( 'SIGTERM' , forwardSignal )
98+
99+ await new Promise ( ( resolve , reject ) => {
100+ ffmpeg . on ( 'exit' , async ( code ) => {
101+ await browser . close ( )
102+ await exporter . finalizeExport ( )
103+
104+ if ( code === 0 || code === null ) {
105+ resolve ( null )
106+ } else {
107+ reject ( new Error ( `FFmpeg exited with code ${ code } ` ) )
108+ }
109+ } )
110+ } )
95111}
96112
97113main ( ) . catch ( ( err ) => {
You can’t perform that action at this time.
0 commit comments