X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Flive%2Fshared%2Fmuxing-session.ts;h=a6907142d25ea74d71dbd102029bc62bcbfe7017;hb=3edbafb6377cfb65bca3964d46fa27bc9f813300;hp=709d6c61549faa61d2cd87fedae97ea29da7454e;hpb=ac27887774e63d99f4e227fbe18846f143cc4b3c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/live/shared/muxing-session.ts b/server/lib/live/shared/muxing-session.ts index 709d6c615..a6907142d 100644 --- a/server/lib/live/shared/muxing-session.ts +++ b/server/lib/live/shared/muxing-session.ts @@ -1,6 +1,6 @@ -import * as Bluebird from 'bluebird' -import * as chokidar from 'chokidar' +import { mapSeries } from 'bluebird' +import { FSWatcher, watch } from 'chokidar' import { FfmpegCommand } from 'fluent-ffmpeg' import { appendFile, ensureDir, readFile, stat } from 'fs-extra' import { basename, join } from 'path' @@ -11,9 +11,9 @@ import { CONFIG } from '@server/initializers/config' import { MEMOIZE_TTL, VIDEO_LIVE } from '@server/initializers/constants' import { VideoFileModel } from '@server/models/video/video-file' import { MStreamingPlaylistVideo, MUserId, MVideoLiveVideo } from '@server/types/models' +import { getLiveDirectory } from '../../paths' import { VideoTranscodingProfilesManager } from '../../transcoding/video-transcoding-profiles' import { isAbleToUploadVideo } from '../../user' -import { getHLSDirectory } from '../../video-paths' import { LiveQuotaStore } from '../live-quota-store' import { LiveSegmentShaStore } from '../live-segment-sha-store' import { buildConcatenatedName } from '../live-utils' @@ -56,6 +56,9 @@ class MuxingSession extends EventEmitter { private readonly fps: number private readonly allResolutions: number[] + private readonly bitrate: number + private readonly ratio: number + private readonly videoId: number private readonly videoUUID: string private readonly saveReplay: boolean @@ -64,8 +67,8 @@ class MuxingSession extends EventEmitter { private segmentsToProcessPerPlaylist: { [playlistId: string]: string[] } = {} - private tsWatcher: chokidar.FSWatcher - private masterWatcher: chokidar.FSWatcher + private tsWatcher: FSWatcher + private masterWatcher: FSWatcher private readonly isAbleToUploadVideoWithCache = memoizee((userId: number) => { return isAbleToUploadVideo(userId, 1000) @@ -83,6 +86,8 @@ class MuxingSession extends EventEmitter { streamingPlaylist: MStreamingPlaylistVideo rtmpUrl: string fps: number + bitrate: number + ratio: number allResolutions: number[] }) { super() @@ -94,6 +99,10 @@ class MuxingSession extends EventEmitter { this.streamingPlaylist = options.streamingPlaylist this.rtmpUrl = options.rtmpUrl this.fps = options.fps + + this.bitrate = options.bitrate + this.ratio = options.bitrate + this.allResolutions = options.allResolutions this.videoId = this.videoLive.Video.id @@ -118,6 +127,9 @@ class MuxingSession extends EventEmitter { resolutions: this.allResolutions, fps: this.fps, + bitrate: this.bitrate, + ratio: this.ratio, + availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(), profile: CONFIG.LIVE.TRANSCODING.PROFILE }) @@ -185,9 +197,9 @@ class MuxingSession extends EventEmitter { } private watchMasterFile (outPath: string) { - this.masterWatcher = chokidar.watch(outPath + '/' + this.streamingPlaylist.playlistFilename) + this.masterWatcher = watch(outPath + '/' + this.streamingPlaylist.playlistFilename) - this.masterWatcher.on('add', async () => { + this.masterWatcher.on('add', () => { this.emit('master-playlist-created', { videoId: this.videoId }) this.masterWatcher.close() @@ -198,7 +210,7 @@ class MuxingSession extends EventEmitter { private watchTSFiles (outPath: string) { const startStreamDateTime = new Date().getTime() - this.tsWatcher = chokidar.watch(outPath + '/*.ts') + this.tsWatcher = watch(outPath + '/*.ts') const playlistIdMatcher = /^([\d+])-/ @@ -270,7 +282,7 @@ class MuxingSession extends EventEmitter { } private async prepareDirectories () { - const outPath = getHLSDirectory(this.videoLive.Video) + const outPath = getLiveDirectory(this.videoLive.Video) await ensureDir(outPath) const replayDirectory = join(outPath, VIDEO_LIVE.REPLAY_DIRECTORY) @@ -294,7 +306,7 @@ class MuxingSession extends EventEmitter { } private processSegments (hlsVideoPath: string, segmentPaths: string[]) { - Bluebird.mapSeries(segmentPaths, async previousSegment => { + mapSeries(segmentPaths, async previousSegment => { // Add sha hash of previous segments, because ffmpeg should have finished generating them await LiveSegmentShaStore.Instance.addSegmentSha(this.videoUUID, previousSegment)