mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Add latency setting support
This commit is contained in:
parent
01dd04cd5a
commit
f443a74649
42 changed files with 516 additions and 81 deletions
|
@ -1,7 +1,7 @@
|
|||
import { FfmpegCommand, FilterSpecification } from 'fluent-ffmpeg'
|
||||
import { join } from 'path'
|
||||
import { VIDEO_LIVE } from '@server/initializers/constants'
|
||||
import { AvailableEncoders } from '@shared/models'
|
||||
import { AvailableEncoders, LiveVideoLatencyMode } from '@shared/models'
|
||||
import { logger, loggerTagsFactory } from '../logger'
|
||||
import { buildStreamSuffix, getFFmpeg, getScaleFilter, StreamType } from './ffmpeg-commons'
|
||||
import { getEncoderBuilderResult } from './ffmpeg-encoders'
|
||||
|
@ -15,6 +15,7 @@ async function getLiveTranscodingCommand (options: {
|
|||
|
||||
outPath: string
|
||||
masterPlaylistName: string
|
||||
latencyMode: LiveVideoLatencyMode
|
||||
|
||||
resolutions: number[]
|
||||
|
||||
|
@ -26,7 +27,7 @@ async function getLiveTranscodingCommand (options: {
|
|||
availableEncoders: AvailableEncoders
|
||||
profile: string
|
||||
}) {
|
||||
const { inputUrl, outPath, resolutions, fps, bitrate, availableEncoders, profile, masterPlaylistName, ratio } = options
|
||||
const { inputUrl, outPath, resolutions, fps, bitrate, availableEncoders, profile, masterPlaylistName, ratio, latencyMode } = options
|
||||
|
||||
const command = getFFmpeg(inputUrl, 'live')
|
||||
|
||||
|
@ -120,14 +121,21 @@ async function getLiveTranscodingCommand (options: {
|
|||
|
||||
command.complexFilter(complexFilter)
|
||||
|
||||
addDefaultLiveHLSParams(command, outPath, masterPlaylistName)
|
||||
addDefaultLiveHLSParams({ command, outPath, masterPlaylistName, latencyMode })
|
||||
|
||||
command.outputOption('-var_stream_map', varStreamMap.join(' '))
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
function getLiveMuxingCommand (inputUrl: string, outPath: string, masterPlaylistName: string) {
|
||||
function getLiveMuxingCommand (options: {
|
||||
inputUrl: string
|
||||
outPath: string
|
||||
masterPlaylistName: string
|
||||
latencyMode: LiveVideoLatencyMode
|
||||
}) {
|
||||
const { inputUrl, outPath, masterPlaylistName, latencyMode } = options
|
||||
|
||||
const command = getFFmpeg(inputUrl, 'live')
|
||||
|
||||
command.outputOption('-c:v copy')
|
||||
|
@ -135,22 +143,39 @@ function getLiveMuxingCommand (inputUrl: string, outPath: string, masterPlaylist
|
|||
command.outputOption('-map 0:a?')
|
||||
command.outputOption('-map 0:v?')
|
||||
|
||||
addDefaultLiveHLSParams(command, outPath, masterPlaylistName)
|
||||
addDefaultLiveHLSParams({ command, outPath, masterPlaylistName, latencyMode })
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
function getLiveSegmentTime (latencyMode: LiveVideoLatencyMode) {
|
||||
if (latencyMode === LiveVideoLatencyMode.SMALL_LATENCY) {
|
||||
return VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY
|
||||
}
|
||||
|
||||
return VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
getLiveSegmentTime,
|
||||
|
||||
getLiveTranscodingCommand,
|
||||
getLiveMuxingCommand
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function addDefaultLiveHLSParams (command: FfmpegCommand, outPath: string, masterPlaylistName: string) {
|
||||
command.outputOption('-hls_time ' + VIDEO_LIVE.SEGMENT_TIME_SECONDS)
|
||||
function addDefaultLiveHLSParams (options: {
|
||||
command: FfmpegCommand
|
||||
outPath: string
|
||||
masterPlaylistName: string
|
||||
latencyMode: LiveVideoLatencyMode
|
||||
}) {
|
||||
const { command, outPath, masterPlaylistName, latencyMode } = options
|
||||
|
||||
command.outputOption('-hls_time ' + getLiveSegmentTime(latencyMode))
|
||||
command.outputOption('-hls_list_size ' + VIDEO_LIVE.SEGMENTS_LIST_SIZE)
|
||||
command.outputOption('-hls_flags delete_segments+independent_segments')
|
||||
command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%06d.ts')}`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue