-import { getAverageBitrate, getMinLimitBitrate } from '@shared/core-utils'
-import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptionsBuilderParams, VideoResolution } from '../../../shared/models/videos'
-import {
- buildStreamSuffix,
- canDoQuickAudioTranscode,
- ffprobePromise,
- getAudioStream,
- getMaxAudioBitrate,
- resetSupportedEncoders
-} from '../../helpers/ffmpeg'
-
-/**
- *
- * Available encoders and profiles for the transcoding jobs
- * These functions are used by ffmpeg-utils that will get the encoders and options depending on the chosen profile
- *
- * Resources:
- * * https://slhck.info/video/2017/03/01/rate-control.html
- * * https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate
- */
-
-// ---------------------------------------------------------------------------
-// Default builders
-// ---------------------------------------------------------------------------
-
-const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => {
- const { fps, inputRatio, inputBitrate, resolution } = options
-
- // TODO: remove in 4.2, fps is not optional anymore
- if (!fps) return { outputOptions: [ ] }
-
- const targetBitrate = getTargetBitrate({ inputBitrate, ratio: inputRatio, fps, resolution })
-
- return {
- outputOptions: [
- ...getCommonOutputOptions(targetBitrate),
-
- `-r ${fps}`
- ]
- }
-}
-
-const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => {
- const { streamNum, fps, inputBitrate, inputRatio, resolution } = options
-
- const targetBitrate = getTargetBitrate({ inputBitrate, ratio: inputRatio, fps, resolution })
-
- return {
- outputOptions: [
- ...getCommonOutputOptions(targetBitrate),
-
- `${buildStreamSuffix('-r:v', streamNum)} ${fps}`,
- `${buildStreamSuffix('-b:v', streamNum)} ${targetBitrate}`
- ]
- }
-}
-
-const defaultAACOptionsBuilder: EncoderOptionsBuilder = async ({ input, streamNum, canCopyAudio }) => {
- const probe = await ffprobePromise(input)
-
- if (canCopyAudio && await canDoQuickAudioTranscode(input, probe)) {
- logger.debug('Copy audio stream %s by AAC encoder.', input)
- return { copy: true, outputOptions: [ ] }
- }
-
- const parsedAudio = await getAudioStream(input, probe)
-
- // We try to reduce the ceiling bitrate by making rough matches of bitrates
- // Of course this is far from perfect, but it might save some space in the end
-
- const audioCodecName = parsedAudio.audioStream['codec_name']
-
- const bitrate = getMaxAudioBitrate(audioCodecName, parsedAudio.bitrate)
-
- logger.debug('Calculating audio bitrate of %s by AAC encoder.', input, { bitrate: parsedAudio.bitrate, audioCodecName })
-
- if (bitrate !== -1) {
- return { outputOptions: [ buildStreamSuffix('-b:a', streamNum), bitrate + 'k' ] }
- }
-
- return { outputOptions: [ ] }
-}
-
-const defaultLibFDKAACVODOptionsBuilder: EncoderOptionsBuilder = ({ streamNum }) => {
- return { outputOptions: [ buildStreamSuffix('-q:a', streamNum), '5' ] }
-}