aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffmpeg-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-10-27 16:06:24 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commit31c82cd914e13dbf53280d0aad0740d70c414441 (patch)
treee2f5ad1ee0e501f58c971eb89a60fc3b1c633f04 /server/helpers/ffmpeg-utils.ts
parentda0310f821b039fea1fcbf8aea49e1d2279ba98e (diff)
downloadPeerTube-31c82cd914e13dbf53280d0aad0740d70c414441.tar.gz
PeerTube-31c82cd914e13dbf53280d0aad0740d70c414441.tar.zst
PeerTube-31c82cd914e13dbf53280d0aad0740d70c414441.zip
Fix replay saving
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