diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-26 11:29:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-26 11:30:18 +0100 |
commit | 884d2c39ae23b44d0d037aaff0f66ad9ae0807ba (patch) | |
tree | 1e06fa6954a987b08894c574e31db7e8c106bafe /server/lib | |
parent | 0151c41c65e0e3e94288314afe295358b9d698f7 (diff) | |
download | PeerTube-884d2c39ae23b44d0d037aaff0f66ad9ae0807ba.tar.gz PeerTube-884d2c39ae23b44d0d037aaff0f66ad9ae0807ba.tar.zst PeerTube-884d2c39ae23b44d0d037aaff0f66ad9ae0807ba.zip |
Fix live FPS limit
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/video-transcoding-profiles.ts | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/server/lib/video-transcoding-profiles.ts b/server/lib/video-transcoding-profiles.ts index 03c26f236..3bf83d6a8 100644 --- a/server/lib/video-transcoding-profiles.ts +++ b/server/lib/video-transcoding-profiles.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { logger } from '@server/helpers/logger' | 1 | import { logger } from '@server/helpers/logger' |
2 | import { getTargetBitrate } from '../../shared/models/videos' | 2 | import { getTargetBitrate, VideoResolution } from '../../shared/models/videos' |
3 | import { AvailableEncoders, buildStreamSuffix, EncoderOptionsBuilder } from '../helpers/ffmpeg-utils' | 3 | import { AvailableEncoders, buildStreamSuffix, EncoderOptionsBuilder } from '../helpers/ffmpeg-utils' |
4 | import { | 4 | import { |
5 | canDoQuickAudioTranscode, | 5 | canDoQuickAudioTranscode, |
@@ -23,21 +23,12 @@ import { VIDEO_TRANSCODING_FPS } from '../initializers/constants' | |||
23 | // * https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate | 23 | // * https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate |
24 | 24 | ||
25 | const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async ({ input, resolution, fps }) => { | 25 | const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async ({ input, resolution, fps }) => { |
26 | let targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS) | 26 | const targetBitrate = await buildTargetBitrate({ input, resolution, fps }) |
27 | 27 | if (!targetBitrate) return { outputOptions: [ ] } | |
28 | const probe = await ffprobePromise(input) | ||
29 | |||
30 | const videoStream = await getVideoStreamFromFile(input, probe) | ||
31 | if (!videoStream) { | ||
32 | return { outputOptions: [ ] } | ||
33 | } | ||
34 | |||
35 | // Don't transcode to an higher bitrate than the original file | ||
36 | const fileBitrate = await getVideoFileBitrate(input, probe) | ||
37 | targetBitrate = Math.min(targetBitrate, fileBitrate) | ||
38 | 28 | ||
39 | return { | 29 | return { |
40 | outputOptions: [ | 30 | outputOptions: [ |
31 | `-r ${fps}`, | ||
41 | `-maxrate ${targetBitrate}`, | 32 | `-maxrate ${targetBitrate}`, |
42 | `-bufsize ${targetBitrate * 2}` | 33 | `-bufsize ${targetBitrate * 2}` |
43 | ] | 34 | ] |
@@ -49,6 +40,7 @@ const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = async ({ resolution | |||
49 | 40 | ||
50 | return { | 41 | return { |
51 | outputOptions: [ | 42 | outputOptions: [ |
43 | `${buildStreamSuffix('-r:v', streamNum)} ${fps}`, | ||
52 | `${buildStreamSuffix('-b:v', streamNum)} ${targetBitrate}`, | 44 | `${buildStreamSuffix('-b:v', streamNum)} ${targetBitrate}`, |
53 | `-maxrate ${targetBitrate}`, | 45 | `-maxrate ${targetBitrate}`, |
54 | `-bufsize ${targetBitrate * 2}` | 46 | `-bufsize ${targetBitrate * 2}` |
@@ -115,3 +107,21 @@ export { | |||
115 | } | 107 | } |
116 | 108 | ||
117 | // --------------------------------------------------------------------------- | 109 | // --------------------------------------------------------------------------- |
110 | async function buildTargetBitrate (options: { | ||
111 | input: string | ||
112 | resolution: VideoResolution | ||
113 | fps: number | ||
114 | |||
115 | }) { | ||
116 | const { input, resolution, fps } = options | ||
117 | const probe = await ffprobePromise(input) | ||
118 | |||
119 | const videoStream = await getVideoStreamFromFile(input, probe) | ||
120 | if (!videoStream) return undefined | ||
121 | |||
122 | const targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS) | ||
123 | |||
124 | // Don't transcode to an higher bitrate than the original file | ||
125 | const fileBitrate = await getVideoFileBitrate(input, probe) | ||
126 | return Math.min(targetBitrate, fileBitrate) | ||
127 | } | ||