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'
6 interface TranscodingWrapperEvents {
9 'error': (options: { err: Error }) => void
12 declare interface AbstractTranscodingWrapper {
13 on<U extends keyof TranscodingWrapperEvents>(
14 event: U, listener: TranscodingWrapperEvents[U]
17 emit<U extends keyof TranscodingWrapperEvents>(
18 event: U, ...args: Parameters<TranscodingWrapperEvents[U]>
22 interface AbstractTranscodingWrapperOptions {
23 streamingPlaylist: MStreamingPlaylistVideo
24 videoLive: MVideoLiveVideo
30 inputPublicUrl: string
42 segmentListSize: number
43 segmentDuration: number
48 abstract class AbstractTranscodingWrapper extends EventEmitter {
49 protected readonly videoLive: MVideoLiveVideo
51 protected readonly toTranscode: {
56 protected readonly sessionId: string
57 protected readonly inputLocalUrl: string
58 protected readonly inputPublicUrl: string
60 protected readonly fps: number
61 protected readonly bitrate: number
62 protected readonly ratio: number
63 protected readonly hasAudio: boolean
65 protected readonly segmentListSize: number
66 protected readonly segmentDuration: number
68 protected readonly videoUUID: string
70 protected readonly outDirectory: string
72 protected readonly lTags: LoggerTagsFn
74 protected readonly streamingPlaylist: MStreamingPlaylistVideo
76 constructor (options: AbstractTranscodingWrapperOptions) {
79 this.lTags = options.lTags
81 this.videoLive = options.videoLive
82 this.videoUUID = options.videoLive.Video.uuid
83 this.streamingPlaylist = options.streamingPlaylist
85 this.sessionId = options.sessionId
86 this.inputLocalUrl = options.inputLocalUrl
87 this.inputPublicUrl = options.inputPublicUrl
89 this.fps = options.fps
90 this.toTranscode = options.toTranscode
92 this.bitrate = options.bitrate
93 this.ratio = options.ratio
94 this.hasAudio = options.hasAudio
96 this.segmentListSize = options.segmentListSize
97 this.segmentDuration = options.segmentDuration
99 this.outDirectory = options.outDirectory
102 abstract run (): Promise<void>
104 abstract abort (error?: LiveVideoError): void
108 AbstractTranscodingWrapper,
109 AbstractTranscodingWrapperOptions