From fb7194043d0486ce0a6a40b2ffbdf32878c33a6f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 25 Sep 2020 16:19:35 +0200 Subject: Check live duration and size --- server/helpers/core-utils.ts | 1 + server/helpers/custom-validators/misc.ts | 5 +++++ server/helpers/ffmpeg-utils.ts | 22 +++++++++++++--------- 3 files changed, 19 insertions(+), 9 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index 49eee7c59..e1c15a6eb 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts @@ -41,6 +41,7 @@ const timeTable = { } export function parseDurationToMs (duration: number | string): number { + if (duration === null) return null if (typeof duration === 'number') return duration if (typeof duration === 'string') { diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index cf32201c4..61c03f0c9 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts @@ -45,6 +45,10 @@ function isBooleanValid (value: any) { return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) } +function isIntOrNull (value: any) { + return value === null || validator.isInt('' + value) +} + function toIntOrNull (value: string) { const v = toValueOrNull(value) @@ -116,6 +120,7 @@ export { isArrayOf, isNotEmptyIntArray, isArray, + isIntOrNull, isIdValid, isSafePath, isUUIDValid, diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index fac2595f1..b25dcaa90 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -5,7 +5,7 @@ import { VideoFileMetadata } from '@shared/models/videos/video-file-metadata' import { getMaxBitrate, getTargetBitrate, VideoResolution } from '../../shared/models/videos' import { checkFFmpegEncoders } from '../initializers/checker-before-init' import { CONFIG } from '../initializers/config' -import { FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' +import { FFMPEG_NICE, VIDEO_LIVE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' import { processImage } from './image-utils' import { logger } from './logger' @@ -353,7 +353,7 @@ function convertWebPToJPG (path: string, destination: string): Promise { }) } -function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: number[]) { +function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: number[], deleteSegments: boolean) { const command = getFFmpeg(rtmpUrl) command.inputOption('-fflags nobuffer') @@ -399,7 +399,7 @@ function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: numb varStreamMap.push(`v:${i},a:${i}`) } - addDefaultLiveHLSParams(command, outPath) + addDefaultLiveHLSParams(command, outPath, deleteSegments) command.outputOption('-var_stream_map', varStreamMap.join(' ')) @@ -408,7 +408,7 @@ function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: numb return command } -function runLiveMuxing (rtmpUrl: string, outPath: string) { +function runLiveMuxing (rtmpUrl: string, outPath: string, deleteSegments: boolean) { const command = getFFmpeg(rtmpUrl) command.inputOption('-fflags nobuffer') @@ -417,7 +417,7 @@ function runLiveMuxing (rtmpUrl: string, outPath: string) { command.outputOption('-map 0:a?') command.outputOption('-map 0:v?') - addDefaultLiveHLSParams(command, outPath) + addDefaultLiveHLSParams(command, outPath, deleteSegments) command.run() @@ -457,10 +457,14 @@ function addDefaultX264Params (command: ffmpeg.FfmpegCommand) { .outputOption('-map_metadata -1') // strip all metadata } -function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string) { - command.outputOption('-hls_time 4') - command.outputOption('-hls_list_size 15') - command.outputOption('-hls_flags delete_segments') +function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string, deleteSegments: boolean) { + command.outputOption('-hls_time ' + VIDEO_LIVE.SEGMENT_TIME) + command.outputOption('-hls_list_size ' + VIDEO_LIVE.SEGMENTS_LIST_SIZE) + + if (deleteSegments === true) { + command.outputOption('-hls_flags delete_segments') + } + command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%d.ts')}`) command.outputOption('-master_pl_name master.m3u8') command.outputOption(`-f hls`) -- cgit v1.2.3