diff options
Diffstat (limited to 'server/lib/live/shared/transcoding-wrapper')
4 files changed, 0 insertions, 241 deletions
diff --git a/server/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts b/server/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts deleted file mode 100644 index 95168745d..000000000 --- a/server/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts +++ /dev/null | |||
@@ -1,110 +0,0 @@ | |||
1 | import EventEmitter from 'events' | ||
2 | import { LoggerTagsFn } from '@server/helpers/logger' | ||
3 | import { MStreamingPlaylistVideo, MVideoLiveVideo } from '@server/types/models' | ||
4 | import { LiveVideoError } from '@shared/models' | ||
5 | |||
6 | interface TranscodingWrapperEvents { | ||
7 | 'end': () => void | ||
8 | |||
9 | 'error': (options: { err: Error }) => void | ||
10 | } | ||
11 | |||
12 | declare interface AbstractTranscodingWrapper { | ||
13 | on<U extends keyof TranscodingWrapperEvents>( | ||
14 | event: U, listener: TranscodingWrapperEvents[U] | ||
15 | ): this | ||
16 | |||
17 | emit<U extends keyof TranscodingWrapperEvents>( | ||
18 | event: U, ...args: Parameters<TranscodingWrapperEvents[U]> | ||
19 | ): boolean | ||
20 | } | ||
21 | |||
22 | interface AbstractTranscodingWrapperOptions { | ||
23 | streamingPlaylist: MStreamingPlaylistVideo | ||
24 | videoLive: MVideoLiveVideo | ||
25 | |||
26 | lTags: LoggerTagsFn | ||
27 | |||
28 | sessionId: string | ||
29 | inputLocalUrl: string | ||
30 | inputPublicUrl: string | ||
31 | |||
32 | fps: number | ||
33 | toTranscode: { | ||
34 | resolution: number | ||
35 | fps: number | ||
36 | }[] | ||
37 | |||
38 | bitrate: number | ||
39 | ratio: number | ||
40 | hasAudio: boolean | ||
41 | |||
42 | segmentListSize: number | ||
43 | segmentDuration: number | ||
44 | |||
45 | outDirectory: string | ||
46 | } | ||
47 | |||
48 | abstract class AbstractTranscodingWrapper extends EventEmitter { | ||
49 | protected readonly videoLive: MVideoLiveVideo | ||
50 | |||
51 | protected readonly toTranscode: { | ||
52 | resolution: number | ||
53 | fps: number | ||
54 | }[] | ||
55 | |||
56 | protected readonly sessionId: string | ||
57 | protected readonly inputLocalUrl: string | ||
58 | protected readonly inputPublicUrl: string | ||
59 | |||
60 | protected readonly fps: number | ||
61 | protected readonly bitrate: number | ||
62 | protected readonly ratio: number | ||
63 | protected readonly hasAudio: boolean | ||
64 | |||
65 | protected readonly segmentListSize: number | ||
66 | protected readonly segmentDuration: number | ||
67 | |||
68 | protected readonly videoUUID: string | ||
69 | |||
70 | protected readonly outDirectory: string | ||
71 | |||
72 | protected readonly lTags: LoggerTagsFn | ||
73 | |||
74 | protected readonly streamingPlaylist: MStreamingPlaylistVideo | ||
75 | |||
76 | constructor (options: AbstractTranscodingWrapperOptions) { | ||
77 | super() | ||
78 | |||
79 | this.lTags = options.lTags | ||
80 | |||
81 | this.videoLive = options.videoLive | ||
82 | this.videoUUID = options.videoLive.Video.uuid | ||
83 | this.streamingPlaylist = options.streamingPlaylist | ||
84 | |||
85 | this.sessionId = options.sessionId | ||
86 | this.inputLocalUrl = options.inputLocalUrl | ||
87 | this.inputPublicUrl = options.inputPublicUrl | ||
88 | |||
89 | this.fps = options.fps | ||
90 | this.toTranscode = options.toTranscode | ||
91 | |||
92 | this.bitrate = options.bitrate | ||
93 | this.ratio = options.ratio | ||
94 | this.hasAudio = options.hasAudio | ||
95 | |||
96 | this.segmentListSize = options.segmentListSize | ||
97 | this.segmentDuration = options.segmentDuration | ||
98 | |||
99 | this.outDirectory = options.outDirectory | ||
100 | } | ||
101 | |||
102 | abstract run (): Promise<void> | ||
103 | |||
104 | abstract abort (error?: LiveVideoError): void | ||
105 | } | ||
106 | |||
107 | export { | ||
108 | AbstractTranscodingWrapper, | ||
109 | AbstractTranscodingWrapperOptions | ||
110 | } | ||
diff --git a/server/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts b/server/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts deleted file mode 100644 index c6ee8ebf1..000000000 --- a/server/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts +++ /dev/null | |||
@@ -1,107 +0,0 @@ | |||
1 | import { FfmpegCommand } from 'fluent-ffmpeg' | ||
2 | import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg' | ||
3 | import { logger } from '@server/helpers/logger' | ||
4 | import { CONFIG } from '@server/initializers/config' | ||
5 | import { VIDEO_LIVE } from '@server/initializers/constants' | ||
6 | import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles' | ||
7 | import { FFmpegLive } from '@shared/ffmpeg' | ||
8 | import { getLiveSegmentTime } from '../../live-utils' | ||
9 | import { AbstractTranscodingWrapper } from './abstract-transcoding-wrapper' | ||
10 | |||
11 | export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper { | ||
12 | private ffmpegCommand: FfmpegCommand | ||
13 | |||
14 | private aborted = false | ||
15 | private errored = false | ||
16 | private ended = false | ||
17 | |||
18 | async run () { | ||
19 | this.ffmpegCommand = CONFIG.LIVE.TRANSCODING.ENABLED | ||
20 | ? await this.buildFFmpegLive().getLiveTranscodingCommand({ | ||
21 | inputUrl: this.inputLocalUrl, | ||
22 | |||
23 | outPath: this.outDirectory, | ||
24 | masterPlaylistName: this.streamingPlaylist.playlistFilename, | ||
25 | |||
26 | segmentListSize: this.segmentListSize, | ||
27 | segmentDuration: this.segmentDuration, | ||
28 | |||
29 | toTranscode: this.toTranscode, | ||
30 | |||
31 | bitrate: this.bitrate, | ||
32 | ratio: this.ratio, | ||
33 | |||
34 | hasAudio: this.hasAudio | ||
35 | }) | ||
36 | : this.buildFFmpegLive().getLiveMuxingCommand({ | ||
37 | inputUrl: this.inputLocalUrl, | ||
38 | outPath: this.outDirectory, | ||
39 | |||
40 | masterPlaylistName: this.streamingPlaylist.playlistFilename, | ||
41 | |||
42 | segmentListSize: VIDEO_LIVE.SEGMENTS_LIST_SIZE, | ||
43 | segmentDuration: getLiveSegmentTime(this.videoLive.latencyMode) | ||
44 | }) | ||
45 | |||
46 | logger.info('Running local live muxing/transcoding for %s.', this.videoUUID, this.lTags()) | ||
47 | |||
48 | let ffmpegShellCommand: string | ||
49 | this.ffmpegCommand.on('start', cmdline => { | ||
50 | ffmpegShellCommand = cmdline | ||
51 | |||
52 | logger.debug('Running ffmpeg command for live', { ffmpegShellCommand, ...this.lTags() }) | ||
53 | }) | ||
54 | |||
55 | this.ffmpegCommand.on('error', (err, stdout, stderr) => { | ||
56 | this.onFFmpegError({ err, stdout, stderr, ffmpegShellCommand }) | ||
57 | }) | ||
58 | |||
59 | this.ffmpegCommand.on('end', () => { | ||
60 | this.onFFmpegEnded() | ||
61 | }) | ||
62 | |||
63 | this.ffmpegCommand.run() | ||
64 | } | ||
65 | |||
66 | abort () { | ||
67 | if (this.ended || this.errored || this.aborted) return | ||
68 | |||
69 | logger.debug('Killing ffmpeg after live abort of ' + this.videoUUID, this.lTags()) | ||
70 | |||
71 | this.ffmpegCommand.kill('SIGINT') | ||
72 | |||
73 | this.aborted = true | ||
74 | this.emit('end') | ||
75 | } | ||
76 | |||
77 | private onFFmpegError (options: { | ||
78 | err: any | ||
79 | stdout: string | ||
80 | stderr: string | ||
81 | ffmpegShellCommand: string | ||
82 | }) { | ||
83 | const { err, stdout, stderr, ffmpegShellCommand } = options | ||
84 | |||
85 | // Don't care that we killed the ffmpeg process | ||
86 | if (err?.message?.includes('Exiting normally')) return | ||
87 | if (this.ended || this.errored || this.aborted) return | ||
88 | |||
89 | logger.error('FFmpeg transcoding error.', { err, stdout, stderr, ffmpegShellCommand, ...this.lTags() }) | ||
90 | |||
91 | this.errored = true | ||
92 | this.emit('error', { err }) | ||
93 | } | ||
94 | |||
95 | private onFFmpegEnded () { | ||
96 | if (this.ended || this.errored || this.aborted) return | ||
97 | |||
98 | logger.debug('Live ffmpeg transcoding ended for ' + this.videoUUID, this.lTags()) | ||
99 | |||
100 | this.ended = true | ||
101 | this.emit('end') | ||
102 | } | ||
103 | |||
104 | private buildFFmpegLive () { | ||
105 | return new FFmpegLive(getFFmpegCommandWrapperOptions('live', VideoTranscodingProfilesManager.Instance.getAvailableEncoders())) | ||
106 | } | ||
107 | } | ||
diff --git a/server/lib/live/shared/transcoding-wrapper/index.ts b/server/lib/live/shared/transcoding-wrapper/index.ts deleted file mode 100644 index ae28fa1ca..000000000 --- a/server/lib/live/shared/transcoding-wrapper/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | export * from './abstract-transcoding-wrapper' | ||
2 | export * from './ffmpeg-transcoding-wrapper' | ||
3 | export * from './remote-transcoding-wrapper' | ||
diff --git a/server/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts b/server/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts deleted file mode 100644 index 2aeeb31fb..000000000 --- a/server/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | import { LiveRTMPHLSTranscodingJobHandler } from '@server/lib/runners' | ||
2 | import { AbstractTranscodingWrapper } from './abstract-transcoding-wrapper' | ||
3 | |||
4 | export class RemoteTranscodingWrapper extends AbstractTranscodingWrapper { | ||
5 | async run () { | ||
6 | await new LiveRTMPHLSTranscodingJobHandler().create({ | ||
7 | rtmpUrl: this.inputPublicUrl, | ||
8 | sessionId: this.sessionId, | ||
9 | toTranscode: this.toTranscode, | ||
10 | video: this.videoLive.Video, | ||
11 | outputDirectory: this.outDirectory, | ||
12 | playlist: this.streamingPlaylist, | ||
13 | segmentListSize: this.segmentListSize, | ||
14 | segmentDuration: this.segmentDuration | ||
15 | }) | ||
16 | } | ||
17 | |||
18 | abort () { | ||
19 | this.emit('end') | ||
20 | } | ||
21 | } | ||