aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/video-transcoding-profiles.ts36
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 @@
1import { logger } from '@server/helpers/logger' 1import { logger } from '@server/helpers/logger'
2import { getTargetBitrate } from '../../shared/models/videos' 2import { getTargetBitrate, VideoResolution } from '../../shared/models/videos'
3import { AvailableEncoders, buildStreamSuffix, EncoderOptionsBuilder } from '../helpers/ffmpeg-utils' 3import { AvailableEncoders, buildStreamSuffix, EncoderOptionsBuilder } from '../helpers/ffmpeg-utils'
4import { 4import {
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
25const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async ({ input, resolution, fps }) => { 25const 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// ---------------------------------------------------------------------------
110async 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}