aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffmpeg-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/ffmpeg-utils.ts')
-rw-r--r--server/helpers/ffmpeg-utils.ts32
1 files changed, 28 insertions, 4 deletions
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'
8import { FFMPEG_NICE, VIDEO_LIVE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' 8import { FFMPEG_NICE, VIDEO_LIVE, VIDEO_TRANSCODING_FPS } from '../initializers/constants'
9import { processImage } from './image-utils' 9import { processImage } from './image-utils'
10import { logger } from './logger' 10import { logger } from './logger'
11import { concat } from 'lodash'
11 12
12/** 13/**
13 * A toolbox to play with audio 14 * A toolbox to play with audio
@@ -424,17 +425,40 @@ function runLiveMuxing (rtmpUrl: string, outPath: string, deleteSegments: boolea
424 return command 425 return command
425} 426}
426 427
427function hlsPlaylistToFragmentedMP4 (playlistPath: string, outputPath: string) { 428async function hlsPlaylistToFragmentedMP4 (hlsDirectory: string, segmentFiles: string[], outputPath: string) {
428 const command = getFFmpeg(playlistPath) 429 const concatFile = 'concat.txt'
430 const concatFilePath = join(hlsDirectory, concatFile)
431 const content = segmentFiles.map(f => 'file ' + f)
432 .join('\n')
433
434 await writeFile(concatFilePath, content + '\n')
435
436 const command = getFFmpeg(concatFilePath)
437 command.inputOption('-safe 0')
438 command.inputOption('-f concat')
429 439
430 command.outputOption('-c copy') 440 command.outputOption('-c copy')
431 command.output(outputPath) 441 command.output(outputPath)
432 442
433 command.run() 443 command.run()
434 444
445 function cleaner () {
446 remove(concatFile)
447 .catch(err => logger.error('Cannot remove concat file in %s.', hlsDirectory, { err }))
448 }
449
435 return new Promise<string>((res, rej) => { 450 return new Promise<string>((res, rej) => {
436 command.on('error', err => rej(err)) 451 command.on('error', err => {
437 command.on('end', () => res()) 452 cleaner()
453
454 rej(err)
455 })
456
457 command.on('end', () => {
458 cleaner()
459
460 res()
461 })
438 }) 462 })
439} 463}
440 464