File tree 1 file changed +20
-4
lines changed
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'
2
2
3
3
import * as puppeteer from 'puppeteer-core'
4
4
@@ -87,11 +87,27 @@ async function main() {
87
87
' ' ,
88
88
)
89
89
90
- execSync ( ffmpegCmd )
90
+ const ffmpeg = spawn ( ffmpegCmd , { shell : true } )
91
91
92
- await browser . close ( )
92
+ const forwardSignal = ( signal : NodeJS . Signals | number ) => {
93
+ ffmpeg . kill ( signal )
94
+ }
93
95
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
+ } )
95
111
}
96
112
97
113
main ( ) . catch ( ( err ) => {
You can’t perform that action at this time.
0 commit comments