Skip to content

Commit

Permalink
add flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nzws committed Apr 7, 2023
1 parent c6f6cff commit 4375948
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions apps/push/src/services/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ export class Encoder {

const stream = ffmpeg(this.rtmp)
.outputFPS(30)
.format('mp4')
.output(`${chunkDir}/${timestamp}.mp4`)
.outputOptions([`-vf scale='if(gt(iw\\,1920)\\,1920\\,iw)':-2`])
.audioCodec('aac')
.audioBitrate('128k')
.audioChannels(2)
.videoCodec('libx264')
.videoBitrate('2500k')
.size('1920x1080')
.autopad()
.format('flv')
.output(`${chunkDir}/${timestamp}.flv`)
.duration(remainingSeconds);

stream.on('start', (cmd: string) => {
Expand Down Expand Up @@ -119,23 +125,18 @@ export class Encoder {
if (recordingStream) {
recordingStream.stream.kill('SIGKILL');
}
const ext = 'mp4';

const chunkDir = this.persistentDir + '/chunks';
const files = (await readdir(chunkDir))
.map(f => parseInt(f.split('.')[0], 10))
.sort((a, b) => a - b)
.map(f => `${chunkDir}/${f}.${ext}`);
.map(f => `${chunkDir}/${f}.flv`);
if (files.length === 0) {
return;
}

if (files.length === 1) {
return files[0];
}

return new Promise<string>((resolve, reject) => {
const filePath = `${this.persistentDir}/recording.${ext}`;
const filePath = `${this.persistentDir}/recording.mp4`;
const stream = ffmpeg();
files.forEach(f => {
stream.input(f);
Expand Down

0 comments on commit 4375948

Please sign in to comment.