]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/ffmpeg-utils.ts
Fix live infohash block
[github/Chocobozzz/PeerTube.git] / server / helpers / ffmpeg-utils.ts
index b25dcaa9095af2c7457875ce8af6b02bcc890dd2..b985988d3cb20a8bbaac8531cc7507e923ea5aac 100644 (file)
@@ -424,6 +424,43 @@ function runLiveMuxing (rtmpUrl: string, outPath: string, deleteSegments: boolea
   return command
 }
 
+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<string>((res, rej) => {
+    command.on('error', err => {
+      cleaner()
+
+      rej(err)
+    })
+
+    command.on('end', () => {
+      cleaner()
+
+      res()
+    })
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 export {
@@ -443,6 +480,7 @@ export {
   getVideoFileFPS,
   computeResolutionsToTranscode,
   audio,
+  hlsPlaylistToFragmentedMP4,
   getVideoFileBitrate,
   canDoQuickTranscode
 }