aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-transcoding-profiles.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video-transcoding-profiles.ts')
-rw-r--r--server/lib/video-transcoding-profiles.ts35
1 files changed, 28 insertions, 7 deletions
diff --git a/server/lib/video-transcoding-profiles.ts b/server/lib/video-transcoding-profiles.ts
index 91a5c65f2..03c26f236 100644
--- a/server/lib/video-transcoding-profiles.ts
+++ b/server/lib/video-transcoding-profiles.ts
@@ -1,11 +1,22 @@
1import { logger } from '@server/helpers/logger'
1import { getTargetBitrate } from '../../shared/models/videos' 2import { getTargetBitrate } from '../../shared/models/videos'
2import { AvailableEncoders, buildStreamSuffix, EncoderOptionsBuilder } from '../helpers/ffmpeg-utils' 3import { AvailableEncoders, buildStreamSuffix, EncoderOptionsBuilder } from '../helpers/ffmpeg-utils'
3import { ffprobePromise, getAudioStream, getMaxAudioBitrate, getVideoFileBitrate, getVideoStreamFromFile } from '../helpers/ffprobe-utils' 4import {
5 canDoQuickAudioTranscode,
6 ffprobePromise,
7 getAudioStream,
8 getMaxAudioBitrate,
9 getVideoFileBitrate,
10 getVideoStreamFromFile
11} from '../helpers/ffprobe-utils'
4import { VIDEO_TRANSCODING_FPS } from '../initializers/constants' 12import { VIDEO_TRANSCODING_FPS } from '../initializers/constants'
5 13
6// --------------------------------------------------------------------------- 14/**
7// Available encoders profiles 15 *
8// --------------------------------------------------------------------------- 16 * Available encoders and profiles for the transcoding jobs
17 * These functions are used by ffmpeg-utils that will get the encoders and options depending on the chosen profile
18 *
19 */
9 20
10// Resources: 21// Resources:
11// * https://slhck.info/video/2017/03/01/rate-control.html 22// * https://slhck.info/video/2017/03/01/rate-control.html
@@ -27,7 +38,8 @@ const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async ({ input, reso
27 38
28 return { 39 return {
29 outputOptions: [ 40 outputOptions: [
30 `-maxrate ${targetBitrate}`, `-bufsize ${targetBitrate * 2}` 41 `-maxrate ${targetBitrate}`,
42 `-bufsize ${targetBitrate * 2}`
31 ] 43 ]
32 } 44 }
33} 45}
@@ -45,7 +57,14 @@ const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = async ({ resolution
45} 57}
46 58
47const defaultAACOptionsBuilder: EncoderOptionsBuilder = async ({ input, streamNum }) => { 59const defaultAACOptionsBuilder: EncoderOptionsBuilder = async ({ input, streamNum }) => {
48 const parsedAudio = await getAudioStream(input) 60 const probe = await ffprobePromise(input)
61
62 if (await canDoQuickAudioTranscode(input, probe)) {
63 logger.debug('Copy audio stream %s by AAC encoder.', input)
64 return { copy: true, outputOptions: [] }
65 }
66
67 const parsedAudio = await getAudioStream(input, probe)
49 68
50 // We try to reduce the ceiling bitrate by making rough matches of bitrates 69 // We try to reduce the ceiling bitrate by making rough matches of bitrates
51 // Of course this is far from perfect, but it might save some space in the end 70 // Of course this is far from perfect, but it might save some space in the end
@@ -54,11 +73,13 @@ const defaultAACOptionsBuilder: EncoderOptionsBuilder = async ({ input, streamNu
54 73
55 const bitrate = getMaxAudioBitrate(audioCodecName, parsedAudio.bitrate) 74 const bitrate = getMaxAudioBitrate(audioCodecName, parsedAudio.bitrate)
56 75
76 logger.debug('Calculating audio bitrate of %s by AAC encoder.', input, { bitrate: parsedAudio.bitrate, audioCodecName })
77
57 if (bitrate !== undefined && bitrate !== -1) { 78 if (bitrate !== undefined && bitrate !== -1) {
58 return { outputOptions: [ buildStreamSuffix('-b:a', streamNum), bitrate + 'k' ] } 79 return { outputOptions: [ buildStreamSuffix('-b:a', streamNum), bitrate + 'k' ] }
59 } 80 }
60 81
61 return { copy: true, outputOptions: [] } 82 return { outputOptions: [ ] }
62} 83}
63 84
64const defaultLibFDKAACVODOptionsBuilder: EncoderOptionsBuilder = ({ streamNum }) => { 85const defaultLibFDKAACVODOptionsBuilder: EncoderOptionsBuilder = ({ streamNum }) => {