X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fffmpeg-utils.ts;h=69564a1a3b4c068b4aaad19987c5b3b0a7b0d74a;hb=9e2b2e76ba5f7f570dcf59fc03bfec98ea5ffab8;hp=3b794b8a29144167f996ea4b237536d6b5633dc6;hpb=68e70a745b2010cd0199864a2addd60d8f99c732;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 3b794b8a2..69564a1a3 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -271,6 +271,8 @@ type TranscodeOptions = | QuickTranscodeOptions function transcode (options: TranscodeOptions) { + logger.debug('Will run transcode.', { options }) + return new Promise(async (res, rej) => { try { let command = getFFmpeg(options.inputPath) @@ -423,8 +425,14 @@ function runLiveMuxing (rtmpUrl: string, outPath: string, deleteSegments: boolea } async function hlsPlaylistToFragmentedMP4 (hlsDirectory: string, segmentFiles: string[], outputPath: string) { - const concatFile = 'concat.txt' - const concatFilePath = join(hlsDirectory, concatFile) + const concatFilePath = join(hlsDirectory, 'concat.txt') + + function cleaner () { + remove(concatFilePath) + .catch(err => logger.error('Cannot remove concat file in %s.', hlsDirectory, { err })) + } + + // First concat the ts files to a mp4 file const content = segmentFiles.map(f => 'file ' + f) .join('\n') @@ -434,25 +442,25 @@ async function hlsPlaylistToFragmentedMP4 (hlsDirectory: string, segmentFiles: s command.inputOption('-safe 0') command.inputOption('-f concat') - command.outputOption('-c copy') + command.outputOption('-c:v copy') + command.audioFilter('aresample=async=1:first_pts=0') command.output(outputPath) - command.run() + return runCommand(command, cleaner) +} - function cleaner () { - remove(concatFilePath) - .catch(err => logger.error('Cannot remove concat file in %s.', hlsDirectory, { err })) - } +async function runCommand (command: ffmpeg.FfmpegCommand, onEnd?: Function) { + command.run() return new Promise((res, rej) => { command.on('error', err => { - cleaner() + if (onEnd) onEnd() rej(err) }) command.on('end', () => { - cleaner() + if (onEnd) onEnd() res() }) @@ -501,7 +509,7 @@ function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string command.outputOption('-hls_flags delete_segments') } - command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%d.ts')}`) + command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%04d.ts')}`) command.outputOption('-master_pl_name master.m3u8') command.outputOption(`-f hls`)