X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fffmpeg%2Fffmpeg-live.ts;h=8377dc7e25435f72d72204e813d8afcf8d4092de;hb=edacb640332eae37665551d35bf29160707336f0;hp=ff571626c98bb11557c944d3df3820e488c30671;hpb=7b51ede977c299a74728171d8c124bcc4cbba6ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/ffmpeg/ffmpeg-live.ts b/server/helpers/ffmpeg/ffmpeg-live.ts index ff571626c..8377dc7e2 100644 --- a/server/helpers/ffmpeg/ffmpeg-live.ts +++ b/server/helpers/ffmpeg/ffmpeg-live.ts @@ -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,24 +143,41 @@ 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_flags delete_segments+independent_segments+program_date_time') command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%06d.ts')}`) command.outputOption('-master_pl_name ' + masterPlaylistName) command.outputOption(`-f hls`)