]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/videos/live.ts
Add ability to remove hls/webtorrent files
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / live.ts
index 6aa405b1964545a4515e4f23e1ddc2bcb55674c1..d3665bc9082e93a955e10cc52d69c886a42ced15 100644 (file)
@@ -1,7 +1,7 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import { expect } from 'chai'
-import * as ffmpeg from 'fluent-ffmpeg'
+import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg'
 import { pathExists, readdir } from 'fs-extra'
 import { join } from 'path'
 import { buildAbsoluteFixturePath, wait } from '../miscs'
@@ -22,12 +22,12 @@ function sendRTMPStream (options: {
   command.inputOption('-re')
 
   if (copyCodecs) {
+    command.outputOption('-c copy')
+  } else {
     command.outputOption('-c:v libx264')
     command.outputOption('-g 50')
     command.outputOption('-keyint_min 2')
     command.outputOption('-r 60')
-  } else {
-    command.outputOption('-c copy')
   }
 
   command.outputOption('-f flv')
@@ -50,7 +50,7 @@ function sendRTMPStream (options: {
   return command
 }
 
-function waitFfmpegUntilError (command: ffmpeg.FfmpegCommand, successAfterMS = 10000) {
+function waitFfmpegUntilError (command: FfmpegCommand, successAfterMS = 10000) {
   return new Promise<void>((res, rej) => {
     command.on('error', err => {
       return rej(err)
@@ -62,7 +62,7 @@ function waitFfmpegUntilError (command: ffmpeg.FfmpegCommand, successAfterMS = 1
   })
 }
 
-async function testFfmpegStreamError (command: ffmpeg.FfmpegCommand, shouldHaveError: boolean) {
+async function testFfmpegStreamError (command: FfmpegCommand, shouldHaveError: boolean) {
   let error: Error
 
   try {
@@ -77,7 +77,7 @@ async function testFfmpegStreamError (command: ffmpeg.FfmpegCommand, shouldHaveE
   if (!shouldHaveError && error) throw error
 }
 
-async function stopFfmpeg (command: ffmpeg.FfmpegCommand) {
+async function stopFfmpeg (command: FfmpegCommand) {
   command.kill('SIGINT')
 
   await wait(500)
@@ -89,6 +89,12 @@ async function waitUntilLivePublishedOnAllServers (servers: PeerTubeServer[], vi
   }
 }
 
+async function waitUntilLiveSavedOnAllServers (servers: PeerTubeServer[], videoId: string) {
+  for (const server of servers) {
+    await server.live.waitUntilSaved({ videoId })
+  }
+}
+
 async function checkLiveCleanupAfterSave (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) {
   const basePath = server.servers.buildDirectory('streaming-playlists')
   const hlsPath = join(basePath, 'hls', videoUUID)
@@ -126,5 +132,6 @@ export {
   testFfmpegStreamError,
   stopFfmpeg,
   waitUntilLivePublishedOnAllServers,
+  waitUntilLiveSavedOnAllServers,
   checkLiveCleanupAfterSave
 }