aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/live/shared/muxing-session.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/live/shared/muxing-session.ts')
-rw-r--r--server/lib/live/shared/muxing-session.ts33
1 files changed, 17 insertions, 16 deletions
diff --git a/server/lib/live/shared/muxing-session.ts b/server/lib/live/shared/muxing-session.ts
index a703f5b5f..588ee8749 100644
--- a/server/lib/live/shared/muxing-session.ts
+++ b/server/lib/live/shared/muxing-session.ts
@@ -11,7 +11,7 @@ import { CONFIG } from '@server/initializers/config'
11import { MEMOIZE_TTL, VIDEO_LIVE } from '@server/initializers/constants' 11import { MEMOIZE_TTL, VIDEO_LIVE } from '@server/initializers/constants'
12import { VideoFileModel } from '@server/models/video/video-file' 12import { VideoFileModel } from '@server/models/video/video-file'
13import { MStreamingPlaylistVideo, MUserId, MVideoLiveVideo } from '@server/types/models' 13import { MStreamingPlaylistVideo, MUserId, MVideoLiveVideo } from '@server/types/models'
14import { getLiveDirectory } from '../../paths' 14import { getLiveDirectory, getLiveReplayBaseDirectory } from '../../paths'
15import { VideoTranscodingProfilesManager } from '../../transcoding/default-transcoding-profiles' 15import { VideoTranscodingProfilesManager } from '../../transcoding/default-transcoding-profiles'
16import { isAbleToUploadVideo } from '../../user' 16import { isAbleToUploadVideo } from '../../user'
17import { LiveQuotaStore } from '../live-quota-store' 17import { LiveQuotaStore } from '../live-quota-store'
@@ -63,6 +63,9 @@ class MuxingSession extends EventEmitter {
63 private readonly videoUUID: string 63 private readonly videoUUID: string
64 private readonly saveReplay: boolean 64 private readonly saveReplay: boolean
65 65
66 private readonly outDirectory: string
67 private readonly replayDirectory: string
68
66 private readonly lTags: LoggerTagsFn 69 private readonly lTags: LoggerTagsFn
67 70
68 private segmentsToProcessPerPlaylist: { [playlistId: string]: string[] } = {} 71 private segmentsToProcessPerPlaylist: { [playlistId: string]: string[] } = {}
@@ -110,19 +113,22 @@ class MuxingSession extends EventEmitter {
110 113
111 this.saveReplay = this.videoLive.saveReplay 114 this.saveReplay = this.videoLive.saveReplay
112 115
116 this.outDirectory = getLiveDirectory(this.videoLive.Video)
117 this.replayDirectory = join(getLiveReplayBaseDirectory(this.videoLive.Video), new Date().toISOString())
118
113 this.lTags = loggerTagsFactory('live', this.sessionId, this.videoUUID) 119 this.lTags = loggerTagsFactory('live', this.sessionId, this.videoUUID)
114 } 120 }
115 121
116 async runMuxing () { 122 async runMuxing () {
117 this.createFiles() 123 this.createFiles()
118 124
119 const outPath = await this.prepareDirectories() 125 await this.prepareDirectories()
120 126
121 this.ffmpegCommand = CONFIG.LIVE.TRANSCODING.ENABLED 127 this.ffmpegCommand = CONFIG.LIVE.TRANSCODING.ENABLED
122 ? await getLiveTranscodingCommand({ 128 ? await getLiveTranscodingCommand({
123 inputUrl: this.inputUrl, 129 inputUrl: this.inputUrl,
124 130
125 outPath, 131 outPath: this.outDirectory,
126 masterPlaylistName: this.streamingPlaylist.playlistFilename, 132 masterPlaylistName: this.streamingPlaylist.playlistFilename,
127 133
128 latencyMode: this.videoLive.latencyMode, 134 latencyMode: this.videoLive.latencyMode,
@@ -137,15 +143,15 @@ class MuxingSession extends EventEmitter {
137 }) 143 })
138 : getLiveMuxingCommand({ 144 : getLiveMuxingCommand({
139 inputUrl: this.inputUrl, 145 inputUrl: this.inputUrl,
140 outPath, 146 outPath: this.outDirectory,
141 masterPlaylistName: this.streamingPlaylist.playlistFilename, 147 masterPlaylistName: this.streamingPlaylist.playlistFilename,
142 latencyMode: this.videoLive.latencyMode 148 latencyMode: this.videoLive.latencyMode
143 }) 149 })
144 150
145 logger.info('Running live muxing/transcoding for %s.', this.videoUUID, this.lTags()) 151 logger.info('Running live muxing/transcoding for %s.', this.videoUUID, this.lTags())
146 152
147 this.watchTSFiles(outPath) 153 this.watchTSFiles(this.outDirectory)
148 this.watchMasterFile(outPath) 154 this.watchMasterFile(this.outDirectory)
149 155
150 let ffmpegShellCommand: string 156 let ffmpegShellCommand: string
151 this.ffmpegCommand.on('start', cmdline => { 157 this.ffmpegCommand.on('start', cmdline => {
@@ -155,10 +161,10 @@ class MuxingSession extends EventEmitter {
155 }) 161 })
156 162
157 this.ffmpegCommand.on('error', (err, stdout, stderr) => { 163 this.ffmpegCommand.on('error', (err, stdout, stderr) => {
158 this.onFFmpegError({ err, stdout, stderr, outPath, ffmpegShellCommand }) 164 this.onFFmpegError({ err, stdout, stderr, outPath: this.outDirectory, ffmpegShellCommand })
159 }) 165 })
160 166
161 this.ffmpegCommand.on('end', () => this.onFFmpegEnded(outPath)) 167 this.ffmpegCommand.on('end', () => this.onFFmpegEnded(this.outDirectory))
162 168
163 this.ffmpegCommand.run() 169 this.ffmpegCommand.run()
164 } 170 }
@@ -304,16 +310,11 @@ class MuxingSession extends EventEmitter {
304 } 310 }
305 311
306 private async prepareDirectories () { 312 private async prepareDirectories () {
307 const outPath = getLiveDirectory(this.videoLive.Video) 313 await ensureDir(this.outDirectory)
308 await ensureDir(outPath)
309
310 const replayDirectory = join(outPath, VIDEO_LIVE.REPLAY_DIRECTORY)
311 314
312 if (this.videoLive.saveReplay === true) { 315 if (this.videoLive.saveReplay === true) {
313 await ensureDir(replayDirectory) 316 await ensureDir(this.replayDirectory)
314 } 317 }
315
316 return outPath
317 } 318 }
318 319
319 private isDurationConstraintValid (streamingStartTime: number) { 320 private isDurationConstraintValid (streamingStartTime: number) {
@@ -364,7 +365,7 @@ class MuxingSession extends EventEmitter {
364 365
365 private async addSegmentToReplay (hlsVideoPath: string, segmentPath: string) { 366 private async addSegmentToReplay (hlsVideoPath: string, segmentPath: string) {
366 const segmentName = basename(segmentPath) 367 const segmentName = basename(segmentPath)
367 const dest = join(hlsVideoPath, VIDEO_LIVE.REPLAY_DIRECTORY, buildConcatenatedName(segmentName)) 368 const dest = join(this.replayDirectory, buildConcatenatedName(segmentName))
368 369
369 try { 370 try {
370 const data = await readFile(segmentPath) 371 const data = await readFile(segmentPath)