aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/transcoding
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/transcoding')
-rw-r--r--server/lib/transcoding/video-transcoding-profiles.ts33
1 files changed, 11 insertions, 22 deletions
diff --git a/server/lib/transcoding/video-transcoding-profiles.ts b/server/lib/transcoding/video-transcoding-profiles.ts
index c5ea72a5f..2309f38d4 100644
--- a/server/lib/transcoding/video-transcoding-profiles.ts
+++ b/server/lib/transcoding/video-transcoding-profiles.ts
@@ -1,14 +1,7 @@
1import { logger } from '@server/helpers/logger' 1import { logger } from '@server/helpers/logger'
2import { AvailableEncoders, EncoderOptionsBuilder, getTargetBitrate, VideoResolution } from '../../../shared/models/videos' 2import { AvailableEncoders, EncoderOptionsBuilder, getTargetBitrate, VideoResolution } from '../../../shared/models/videos'
3import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils' 3import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils'
4import { 4import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBitrate } from '../../helpers/ffprobe-utils'
5 canDoQuickAudioTranscode,
6 ffprobePromise,
7 getAudioStream,
8 getMaxAudioBitrate,
9 getVideoFileBitrate,
10 getVideoStreamFromFile
11} from '../../helpers/ffprobe-utils'
12import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' 5import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
13 6
14/** 7/**
@@ -22,8 +15,8 @@ import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
22// * https://slhck.info/video/2017/03/01/rate-control.html 15// * https://slhck.info/video/2017/03/01/rate-control.html
23// * https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate 16// * https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate
24 17
25const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async ({ input, resolution, fps }) => { 18const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async ({ inputBitrate, resolution, fps }) => {
26 const targetBitrate = await buildTargetBitrate({ input, resolution, fps }) 19 const targetBitrate = buildTargetBitrate({ inputBitrate, resolution, fps })
27 if (!targetBitrate) return { outputOptions: [ ] } 20 if (!targetBitrate) return { outputOptions: [ ] }
28 21
29 return { 22 return {
@@ -36,8 +29,8 @@ const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async ({ input, reso
36 } 29 }
37} 30}
38 31
39const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = async ({ resolution, fps, streamNum }) => { 32const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = async ({ resolution, fps, inputBitrate, streamNum }) => {
40 const targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS) 33 const targetBitrate = buildTargetBitrate({ inputBitrate, resolution, fps })
41 34
42 return { 35 return {
43 outputOptions: [ 36 outputOptions: [
@@ -237,20 +230,16 @@ export {
237} 230}
238 231
239// --------------------------------------------------------------------------- 232// ---------------------------------------------------------------------------
240async function buildTargetBitrate (options: { 233
241 input: string 234function buildTargetBitrate (options: {
235 inputBitrate: number
242 resolution: VideoResolution 236 resolution: VideoResolution
243 fps: number 237 fps: number
244}) { 238}) {
245 const { input, resolution, fps } = options 239 const { inputBitrate, resolution, fps } = options
246 const probe = await ffprobePromise(input)
247
248 const videoStream = await getVideoStreamFromFile(input, probe)
249 if (!videoStream) return undefined
250 240
251 const targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS) 241 const targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS)
242 if (!inputBitrate) return targetBitrate
252 243
253 // Don't transcode to an higher bitrate than the original file 244 return Math.min(targetBitrate, inputBitrate)
254 const fileBitrate = await getVideoFileBitrate(input, probe)
255 return Math.min(targetBitrate, fileBitrate)
256} 245}