@@ -125,20 +125,20 @@ export class FFMPEG extends EventEmitter {
125
125
* @param {RtpData[] } rtpInputs.cameraRtps
126
126
*/
127
127
async merge ( rtpInputs ) {
128
- const sdp = formatSdp ( rtpInputs ) ;
129
- this . _process = child_process . spawn ( "ffmpeg" , this . _processArgs , {
128
+ this . _startProcess ( this . _processArgs , formatSdp ( rtpInputs ) ) ;
129
+ }
130
+
131
+ _startProcess ( args , sdp ) {
132
+ this . _process = child_process . spawn ( "ffmpeg" , args , {
130
133
stdio : [ "pipe" , "pipe" , process . stderr ] ,
131
134
} ) ;
132
-
133
135
if ( ! this . _process . stdin . writable ) {
134
136
throw new Error ( "FFMPEG stdin not writable." ) ;
135
137
}
136
- this . _process . stdin . write ( sdp ) ; // TODO (maybe pass args earlier)
138
+ this . _process . stdin . write ( sdp ) ;
137
139
this . _process . stdin . end ( ) ;
138
140
this . _process . on ( "close" , ( code ) => {
139
- if ( code === 0 ) {
140
- this . emit ( "success" ) ;
141
- }
141
+ this . emit ( "complete" , code ) ;
142
142
} ) ;
143
143
144
144
logger . debug (
@@ -147,7 +147,19 @@ export class FFMPEG extends EventEmitter {
147
147
}
148
148
149
149
concat ( filePaths ) {
150
- return filePaths [ 0 ] ;
150
+ this . _startProcess (
151
+ this . _processArgs , // TODO check if all args make sense or if need custom
152
+ `-f concat -safe 0 -i ${ filePaths . join ( "\n" ) } -c copy` // SDP
153
+ ) ;
154
+ return new Promise ( ( resolve , reject ) => {
155
+ this . once ( "complete" , ( code ) => {
156
+ if ( code === 0 ) {
157
+ resolve ( this . _filePath ) ;
158
+ } else {
159
+ reject ( new Error ( `FFMPEG exited with code ${ code } ` ) ) ;
160
+ }
161
+ } ) ;
162
+ } ) ;
151
163
}
152
164
153
165
kill ( ) {
0 commit comments