From 31c82cd914e13dbf53280d0aad0740d70c414441 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 27 Oct 2020 16:06:24 +0100 Subject: Fix replay saving --- server/helpers/ffmpeg-utils.ts | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 2f167a580..b063cedcb 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -8,6 +8,7 @@ import { CONFIG } from '../initializers/config' import { FFMPEG_NICE, VIDEO_LIVE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' import { processImage } from './image-utils' import { logger } from './logger' +import { concat } from 'lodash' /** * A toolbox to play with audio @@ -424,17 +425,40 @@ function runLiveMuxing (rtmpUrl: string, outPath: string, deleteSegments: boolea return command } -function hlsPlaylistToFragmentedMP4 (playlistPath: string, outputPath: string) { - const command = getFFmpeg(playlistPath) +async function hlsPlaylistToFragmentedMP4 (hlsDirectory: string, segmentFiles: string[], outputPath: string) { + const concatFile = 'concat.txt' + const concatFilePath = join(hlsDirectory, concatFile) + const content = segmentFiles.map(f => 'file ' + f) + .join('\n') + + await writeFile(concatFilePath, content + '\n') + + const command = getFFmpeg(concatFilePath) + command.inputOption('-safe 0') + command.inputOption('-f concat') command.outputOption('-c copy') command.output(outputPath) command.run() + function cleaner () { + remove(concatFile) + .catch(err => logger.error('Cannot remove concat file in %s.', hlsDirectory, { err })) + } + return new Promise((res, rej) => { - command.on('error', err => rej(err)) - command.on('end', () => res()) + command.on('error', err => { + cleaner() + + rej(err) + }) + + command.on('end', () => { + cleaner() + + res() + }) }) } -- cgit v1.2.3