aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/core-utils.ts1
-rw-r--r--server/helpers/custom-validators/misc.ts5
-rw-r--r--server/helpers/ffmpeg-utils.ts22
3 files changed, 19 insertions, 9 deletions
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 = {
41} 41}
42 42
43export function parseDurationToMs (duration: number | string): number { 43export function parseDurationToMs (duration: number | string): number {
44 if (duration === null) return null
44 if (typeof duration === 'number') return duration 45 if (typeof duration === 'number') return duration
45 46
46 if (typeof duration === 'string') { 47 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) {
45 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) 45 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
46} 46}
47 47
48function isIntOrNull (value: any) {
49 return value === null || validator.isInt('' + value)
50}
51
48function toIntOrNull (value: string) { 52function toIntOrNull (value: string) {
49 const v = toValueOrNull(value) 53 const v = toValueOrNull(value)
50 54
@@ -116,6 +120,7 @@ export {
116 isArrayOf, 120 isArrayOf,
117 isNotEmptyIntArray, 121 isNotEmptyIntArray,
118 isArray, 122 isArray,
123 isIntOrNull,
119 isIdValid, 124 isIdValid,
120 isSafePath, 125 isSafePath,
121 isUUIDValid, 126 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'
5import { getMaxBitrate, getTargetBitrate, VideoResolution } from '../../shared/models/videos' 5import { getMaxBitrate, getTargetBitrate, VideoResolution } from '../../shared/models/videos'
6import { checkFFmpegEncoders } from '../initializers/checker-before-init' 6import { checkFFmpegEncoders } from '../initializers/checker-before-init'
7import { CONFIG } from '../initializers/config' 7import { CONFIG } from '../initializers/config'
8import { FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' 8import { FFMPEG_NICE, VIDEO_LIVE, VIDEO_TRANSCODING_FPS } from '../initializers/constants'
9import { processImage } from './image-utils' 9import { processImage } from './image-utils'
10import { logger } from './logger' 10import { logger } from './logger'
11 11
@@ -353,7 +353,7 @@ function convertWebPToJPG (path: string, destination: string): Promise<void> {
353 }) 353 })
354} 354}
355 355
356function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: number[]) { 356function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: number[], deleteSegments: boolean) {
357 const command = getFFmpeg(rtmpUrl) 357 const command = getFFmpeg(rtmpUrl)
358 command.inputOption('-fflags nobuffer') 358 command.inputOption('-fflags nobuffer')
359 359
@@ -399,7 +399,7 @@ function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: numb
399 varStreamMap.push(`v:${i},a:${i}`) 399 varStreamMap.push(`v:${i},a:${i}`)
400 } 400 }
401 401
402 addDefaultLiveHLSParams(command, outPath) 402 addDefaultLiveHLSParams(command, outPath, deleteSegments)
403 403
404 command.outputOption('-var_stream_map', varStreamMap.join(' ')) 404 command.outputOption('-var_stream_map', varStreamMap.join(' '))
405 405
@@ -408,7 +408,7 @@ function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: numb
408 return command 408 return command
409} 409}
410 410
411function runLiveMuxing (rtmpUrl: string, outPath: string) { 411function runLiveMuxing (rtmpUrl: string, outPath: string, deleteSegments: boolean) {
412 const command = getFFmpeg(rtmpUrl) 412 const command = getFFmpeg(rtmpUrl)
413 command.inputOption('-fflags nobuffer') 413 command.inputOption('-fflags nobuffer')
414 414
@@ -417,7 +417,7 @@ function runLiveMuxing (rtmpUrl: string, outPath: string) {
417 command.outputOption('-map 0:a?') 417 command.outputOption('-map 0:a?')
418 command.outputOption('-map 0:v?') 418 command.outputOption('-map 0:v?')
419 419
420 addDefaultLiveHLSParams(command, outPath) 420 addDefaultLiveHLSParams(command, outPath, deleteSegments)
421 421
422 command.run() 422 command.run()
423 423
@@ -457,10 +457,14 @@ function addDefaultX264Params (command: ffmpeg.FfmpegCommand) {
457 .outputOption('-map_metadata -1') // strip all metadata 457 .outputOption('-map_metadata -1') // strip all metadata
458} 458}
459 459
460function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string) { 460function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string, deleteSegments: boolean) {
461 command.outputOption('-hls_time 4') 461 command.outputOption('-hls_time ' + VIDEO_LIVE.SEGMENT_TIME)
462 command.outputOption('-hls_list_size 15') 462 command.outputOption('-hls_list_size ' + VIDEO_LIVE.SEGMENTS_LIST_SIZE)
463 command.outputOption('-hls_flags delete_segments') 463
464 if (deleteSegments === true) {
465 command.outputOption('-hls_flags delete_segments')
466 }
467
464 command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%d.ts')}`) 468 command.outputOption(`-hls_segment_filename ${join(outPath, '%v-%d.ts')}`)
465 command.outputOption('-master_pl_name master.m3u8') 469 command.outputOption('-master_pl_name master.m3u8')
466 command.outputOption(`-f hls`) 470 command.outputOption(`-f hls`)