diff options
Diffstat (limited to 'server/helpers/ffmpeg/ffmpeg-live.ts')
-rw-r--r-- | server/helpers/ffmpeg/ffmpeg-live.ts | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/server/helpers/ffmpeg/ffmpeg-live.ts b/server/helpers/ffmpeg/ffmpeg-live.ts index ff571626c..fd20971eb 100644 --- a/server/helpers/ffmpeg/ffmpeg-live.ts +++ b/server/helpers/ffmpeg/ffmpeg-live.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { FfmpegCommand, FilterSpecification } from 'fluent-ffmpeg' | 1 | import { FfmpegCommand, FilterSpecification } from 'fluent-ffmpeg' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { VIDEO_LIVE } from '@server/initializers/constants' | 3 | import { VIDEO_LIVE } from '@server/initializers/constants' |
4 | import { AvailableEncoders } from '@shared/models' | 4 | import { AvailableEncoders, LiveVideoLatencyMode } from '@shared/models' |
5 | import { logger, loggerTagsFactory } from '../logger' | 5 | import { logger, loggerTagsFactory } from '../logger' |
6 | import { buildStreamSuffix, getFFmpeg, getScaleFilter, StreamType } from './ffmpeg-commons' | 6 | import { buildStreamSuffix, getFFmpeg, getScaleFilter, StreamType } from './ffmpeg-commons' |
7 | import { getEncoderBuilderResult } from './ffmpeg-encoders' | 7 | import { getEncoderBuilderResult } from './ffmpeg-encoders' |
@@ -15,6 +15,7 @@ async function getLiveTranscodingCommand (options: { | |||
15 | 15 | ||
16 | outPath: string | 16 | outPath: string |
17 | masterPlaylistName: string | 17 | masterPlaylistName: string |
18 | latencyMode: LiveVideoLatencyMode | ||
18 | 19 | ||
19 | resolutions: number[] | 20 | resolutions: number[] |
20 | 21 | ||
@@ -26,7 +27,7 @@ async function getLiveTranscodingCommand (options: { | |||
26 | availableEncoders: AvailableEncoders | 27 | availableEncoders: AvailableEncoders |
27 | profile: string | 28 | profile: string |
28 | }) { | 29 | }) { |
29 | const { inputUrl, outPath, resolutions, fps, bitrate, availableEncoders, profile, masterPlaylistName, ratio } = options | 30 | const { inputUrl, outPath, resolutions, fps, bitrate, availableEncoders, profile, masterPlaylistName, ratio, latencyMode } = options |
30 | 31 | ||
31 | const command = getFFmpeg(inputUrl, 'live') | 32 | const command = getFFmpeg(inputUrl, 'live') |
32 | 33 | ||
@@ -120,14 +121,21 @@ async function getLiveTranscodingCommand (options: { | |||
120 | 121 | ||
121 | command.complexFilter(complexFilter) | 122 | command.complexFilter(complexFilter) |
122 | 123 | ||
123 | addDefaultLiveHLSParams(command, outPath, masterPlaylistName) | 124 | addDefaultLiveHLSParams({ command, outPath, masterPlaylistName, latencyMode }) |
124 | 125 | ||
125 | command.outputOption('-var_stream_map', varStreamMap.join(' ')) | 126 | command.outputOption('-var_stream_map', varStreamMap.join(' ')) |
126 | 127 | ||
127 | return command | 128 | return command |
128 | } | 129 | } |
129 | 130 | ||
130 | function getLiveMuxingCommand (inputUrl: string, outPath: string, masterPlaylistName: string) { | 131 | function getLiveMuxingCommand (options: { |
132 | inputUrl: string | ||
133 | outPath: string | ||
134 | masterPlaylistName: string | ||
135 | latencyMode: LiveVideoLatencyMode | ||
136 | }) { | ||
137 | const { inputUrl, outPath, masterPlaylistName, latencyMode } = options | ||
138 | |||
131 | const command = getFFmpeg(inputUrl, 'live') | 139 | const command = getFFmpeg(inputUrl, 'live') |
132 | 140 | ||
133 | command.outputOption('-c:v copy') | 141 | command.outputOption('-c:v copy') |
@@ -135,22 +143,39 @@ function getLiveMuxingCommand (inputUrl: string, outPath: string, masterPlaylist | |||
135 | command.outputOption('-map 0:a?') | 143 | command.outputOption('-map 0:a?') |
136 | command.outputOption('-map 0:v?') | 144 | command.outputOption('-map 0:v?') |
137 | 145 | ||
138 | addDefaultLiveHLSParams(command, outPath, masterPlaylistName) | 146 | addDefaultLiveHLSParams({ command, outPath, masterPlaylistName, latencyMode }) |
139 | 147 | ||
140 | return command | 148 | return command |
141 | } | 149 | } |
142 | 150 | ||
151 | function getLiveSegmentTime (latencyMode: LiveVideoLatencyMode) { | ||
152 | if (latencyMode === LiveVideoLatencyMode.SMALL_LATENCY) { | ||
153 | return VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY | ||
154 | } | ||
155 | |||
156 | return VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY | ||
157 | } | ||
158 | |||
143 | // --------------------------------------------------------------------------- | 159 | // --------------------------------------------------------------------------- |
144 | 160 | ||
145 | export { | 161 | export { |
162 | getLiveSegmentTime, | ||
163 | |||
146 | getLiveTranscodingCommand, | 164 | getLiveTranscodingCommand, |
147 | getLiveMuxingCommand | 165 | getLiveMuxingCommand |
148 | } | 166 | } |
149 | 167 | ||
150 | // --------------------------------------------------------------------------- | 168 | // --------------------------------------------------------------------------- |
151 | 169 | ||
152 | function addDefaultLiveHLSParams (command: FfmpegCommand, outPath: string, masterPlaylistName: string) { | 170 | function addDefaultLiveHLSParams (options: { |
153 | command.outputOption('-hls_time ' + VIDEO_LIVE.SEGMENT_TIME_SECONDS) | 171 | command: FfmpegCommand |
172 | outPath: string | ||
173 | masterPlaylistName: string | ||
174 | latencyMode: LiveVideoLatencyMode | ||
175 | }) { | ||
176 | const { command, outPath, masterPlaylistName, latencyMode } = options | ||
177 | |||
178 | command.outputOption('-hls_time ' + getLiveSegmentTime(latencyMode)) | ||
154 | command.outputOption('-hls_list_size ' + VIDEO_LIVE.SEGMENTS_LIST_SIZE) | 179 | command.outputOption('-hls_list_size ' + VIDEO_LIVE.SEGMENTS_LIST_SIZE) |
155 | command.outputOption('-hls_flags delete_segments+independent_segments') | 180 | command.outputOption('-hls_flags delete_segments+independent_segments') |
156 | command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%06d.ts')}`) | 181 | command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%06d.ts')}`) |