From c826f34a45757b324a20f71665b44ed10e6953b5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 6 Aug 2021 10:39:40 +0200 Subject: Limit live bitrate --- shared/extra-utils/videos/live-command.ts | 5 +++-- shared/extra-utils/videos/live.ts | 23 ++++++++++++++++++----- shared/models/videos/video-transcoding.model.ts | 1 + 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'shared') diff --git a/shared/extra-utils/videos/live-command.ts b/shared/extra-utils/videos/live-command.ts index bf9486a05..81ae458e0 100644 --- a/shared/extra-utils/videos/live-command.ts +++ b/shared/extra-utils/videos/live-command.ts @@ -68,11 +68,12 @@ export class LiveCommand extends AbstractCommand { async sendRTMPStreamInVideo (options: OverrideCommandOptions & { videoId: number | string fixtureName?: string + copyCodecs?: boolean }) { - const { videoId, fixtureName } = options + const { videoId, fixtureName, copyCodecs } = options const videoLive = await this.get({ videoId }) - return sendRTMPStream(videoLive.rtmpUrl, videoLive.streamKey, fixtureName) + return sendRTMPStream({ rtmpBaseUrl: videoLive.rtmpUrl, streamKey: videoLive.streamKey, fixtureName, copyCodecs }) } async runAndTestStreamError (options: OverrideCommandOptions & { diff --git a/shared/extra-utils/videos/live.ts b/shared/extra-utils/videos/live.ts index 94f5f5b59..6aa405b19 100644 --- a/shared/extra-utils/videos/live.ts +++ b/shared/extra-utils/videos/live.ts @@ -7,16 +7,29 @@ import { join } from 'path' import { buildAbsoluteFixturePath, wait } from '../miscs' import { PeerTubeServer } from '../server/server' -function sendRTMPStream (rtmpBaseUrl: string, streamKey: string, fixtureName = 'video_short.mp4') { +function sendRTMPStream (options: { + rtmpBaseUrl: string + streamKey: string + fixtureName?: string // default video_short.mp4 + copyCodecs?: boolean // default false +}) { + const { rtmpBaseUrl, streamKey, fixtureName = 'video_short.mp4', copyCodecs = false } = options + const fixture = buildAbsoluteFixturePath(fixtureName) const command = ffmpeg(fixture) command.inputOption('-stream_loop -1') command.inputOption('-re') - command.outputOption('-c:v libx264') - command.outputOption('-g 50') - command.outputOption('-keyint_min 2') - command.outputOption('-r 60') + + if (copyCodecs) { + command.outputOption('-c:v libx264') + command.outputOption('-g 50') + command.outputOption('-keyint_min 2') + command.outputOption('-r 60') + } else { + command.outputOption('-c copy') + } + command.outputOption('-f flv') const rtmpUrl = rtmpBaseUrl + '/' + streamKey diff --git a/shared/models/videos/video-transcoding.model.ts b/shared/models/videos/video-transcoding.model.ts index 3f2382ce8..f1fe4609b 100644 --- a/shared/models/videos/video-transcoding.model.ts +++ b/shared/models/videos/video-transcoding.model.ts @@ -5,6 +5,7 @@ import { VideoResolution } from './video-resolution.enum' export type EncoderOptionsBuilder = (params: { input: string resolution: VideoResolution + inputBitrate: number fps?: number streamNum?: number }) => Promise | EncoderOptions -- cgit v1.2.3