Skip to content

Commit e7e1995

Browse files
[FIX] fixup: concat
1 parent 7140d37 commit e7e1995

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/models/recorder.js

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class Recorder extends EventEmitter {
125125
logger.warn(`Session ${id} not found`);
126126
continue;
127127
}
128+
// TODO could be parallelized
128129
if (audioRtps.length < recording.audioLimit) {
129130
const audioRtpData = await session.getRtp(STREAM_TYPE.AUDIO);
130131
audioRtpData && audioRtps.push(audioRtpData);

src/utils/ffmpeg.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,20 @@ export class FFMPEG extends EventEmitter {
125125
* @param {RtpData[]} rtpInputs.cameraRtps
126126
*/
127127
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, {
130133
stdio: ["pipe", "pipe", process.stderr],
131134
});
132-
133135
if (!this._process.stdin.writable) {
134136
throw new Error("FFMPEG stdin not writable.");
135137
}
136-
this._process.stdin.write(sdp); // TODO (maybe pass args earlier)
138+
this._process.stdin.write(sdp);
137139
this._process.stdin.end();
138140
this._process.on("close", (code) => {
139-
if (code === 0) {
140-
this.emit("success");
141-
}
141+
this.emit("complete", code);
142142
});
143143

144144
logger.debug(
@@ -147,7 +147,19 @@ export class FFMPEG extends EventEmitter {
147147
}
148148

149149
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+
});
151163
}
152164

153165
kill() {

0 commit comments

Comments
 (0)