diff options
author | Chocobozzz <me@florianbigard.com> | 2020-09-25 16:19:35 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | fb7194043d0486ce0a6a40b2ffbdf32878c33a6f (patch) | |
tree | 6ed304a5d730a75da0a4460b3009df88684fa598 /server/helpers/ffmpeg-utils.ts | |
parent | a5cf76afa378aae81af2a9b0ce548e5d2582f832 (diff) | |
download | PeerTube-fb7194043d0486ce0a6a40b2ffbdf32878c33a6f.tar.gz PeerTube-fb7194043d0486ce0a6a40b2ffbdf32878c33a6f.tar.zst PeerTube-fb7194043d0486ce0a6a40b2ffbdf32878c33a6f.zip |
Check live duration and size
Diffstat (limited to 'server/helpers/ffmpeg-utils.ts')
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 22 |
1 files changed, 13 insertions, 9 deletions
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' | |||
5 | import { getMaxBitrate, getTargetBitrate, VideoResolution } from '../../shared/models/videos' | 5 | import { getMaxBitrate, getTargetBitrate, VideoResolution } from '../../shared/models/videos' |
6 | import { checkFFmpegEncoders } from '../initializers/checker-before-init' | 6 | import { checkFFmpegEncoders } from '../initializers/checker-before-init' |
7 | import { CONFIG } from '../initializers/config' | 7 | import { CONFIG } from '../initializers/config' |
8 | import { FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' | 8 | import { FFMPEG_NICE, VIDEO_LIVE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' |
9 | import { processImage } from './image-utils' | 9 | import { processImage } from './image-utils' |
10 | import { logger } from './logger' | 10 | import { logger } from './logger' |
11 | 11 | ||
@@ -353,7 +353,7 @@ function convertWebPToJPG (path: string, destination: string): Promise<void> { | |||
353 | }) | 353 | }) |
354 | } | 354 | } |
355 | 355 | ||
356 | function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: number[]) { | 356 | function 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 | ||
411 | function runLiveMuxing (rtmpUrl: string, outPath: string) { | 411 | function 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 | ||
460 | function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string) { | 460 | function 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`) |