]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/live/shared/muxing-session.ts
Limit live bitrate
[github/Chocobozzz/PeerTube.git] / server / lib / live / shared / muxing-session.ts
index 96f6c2c890adf75ab1450d4aef6e790a59ac6f89..62708b14b504dde626cc0c2d7130358265a234db 100644 (file)
@@ -54,6 +54,7 @@ class MuxingSession extends EventEmitter {
   private readonly streamingPlaylist: MStreamingPlaylistVideo
   private readonly rtmpUrl: string
   private readonly fps: number
+  private readonly bitrate: number
   private readonly allResolutions: number[]
 
   private readonly videoId: number
@@ -83,6 +84,7 @@ class MuxingSession extends EventEmitter {
     streamingPlaylist: MStreamingPlaylistVideo
     rtmpUrl: string
     fps: number
+    bitrate: number
     allResolutions: number[]
   }) {
     super()
@@ -94,6 +96,7 @@ class MuxingSession extends EventEmitter {
     this.streamingPlaylist = options.streamingPlaylist
     this.rtmpUrl = options.rtmpUrl
     this.fps = options.fps
+    this.bitrate = options.bitrate
     this.allResolutions = options.allResolutions
 
     this.videoId = this.videoLive.Video.id
@@ -112,13 +115,18 @@ class MuxingSession extends EventEmitter {
     this.ffmpegCommand = CONFIG.LIVE.TRANSCODING.ENABLED
       ? await getLiveTranscodingCommand({
         rtmpUrl: this.rtmpUrl,
+
         outPath,
+        masterPlaylistName: this.streamingPlaylist.playlistFilename,
+
         resolutions: this.allResolutions,
         fps: this.fps,
+        bitrate: this.bitrate,
+
         availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
         profile: CONFIG.LIVE.TRANSCODING.PROFILE
       })
-      : getLiveMuxingCommand(this.rtmpUrl, outPath)
+      : getLiveMuxingCommand(this.rtmpUrl, outPath, this.streamingPlaylist.playlistFilename)
 
     logger.info('Running live muxing/transcoding for %s.', this.videoUUID, this.lTags)
 
@@ -135,10 +143,15 @@ class MuxingSession extends EventEmitter {
   }
 
   abort () {
-    if (!this.ffmpegCommand) return false
+    if (!this.ffmpegCommand) return
 
     this.ffmpegCommand.kill('SIGINT')
-    return true
+  }
+
+  destroy () {
+    this.removeAllListeners()
+    this.isAbleToUploadVideoWithCache.clear()
+    this.hasClientSocketInBadHealthWithCache.clear()
   }
 
   private onFFmpegError (err: any, stdout: string, stderr: string, outPath: string) {
@@ -177,7 +190,7 @@ class MuxingSession extends EventEmitter {
   }
 
   private watchMasterFile (outPath: string) {
-    this.masterWatcher = chokidar.watch(outPath + '/master.m3u8')
+    this.masterWatcher = chokidar.watch(outPath + '/' + this.streamingPlaylist.playlistFilename)
 
     this.masterWatcher.on('add', async () => {
       this.emit('master-playlist-created', { videoId: this.videoId })