From: Chocobozzz Date: Tue, 14 Aug 2018 13:38:09 +0000 (+0200) Subject: Don't set a bitrate on unknown audio input X-Git-Tag: delete~11 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=eed24d26db4c8363d5e5874841ee0c4f5fa275a8;p=github%2FChocobozzz%2FPeerTube.git Don't set a bitrate on unknown audio input --- diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index f8299c36f..8936005e0 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -236,7 +236,7 @@ namespace audio { } export namespace bitrate { - export const baseKbitrate = 384 + const baseKbitrate = 384 const toBits = (kbits: number): number => { return kbits * 8000 } @@ -274,7 +274,6 @@ namespace audio { * See https://trac.ffmpeg.org/wiki/Encode/AAC#fdk_vbr */ async function standard (_ffmpeg) { - let _bitrate = audio.bitrate.baseKbitrate let localFfmpeg = _ffmpeg .format('mp4') .videoCodec('libx264') @@ -289,15 +288,6 @@ async function standard (_ffmpeg) { return localFfmpeg.noAudio() } - // we try to reduce the ceiling bitrate by making rough correspondances of bitrates - // of course this is far from perfect, but it might save some space in the end - if (audio.bitrate[_audio.audioStream['codec_name']]) { - _bitrate = audio.bitrate[_audio.audioStream['codec_name']](_audio.audioStream['bit_rate']) - if (_bitrate === -1) { - return localFfmpeg.audioCodec('copy') - } - } - // we favor VBR, if a good AAC encoder is available if ((await checkFFmpegEncoders()).get('libfdk_aac')) { return localFfmpeg @@ -305,5 +295,17 @@ async function standard (_ffmpeg) { .audioQuality(5) } - return localFfmpeg.audioBitrate(_bitrate) + // we try to reduce the ceiling bitrate by making rough correspondances of bitrates + // of course this is far from perfect, but it might save some space in the end + const audioCodecName = _audio.audioStream['codec_name'] + let bitrate: number + if (audio.bitrate[audioCodecName]) { + bitrate = audio.bitrate[audioCodecName](_audio.audioStream['bit_rate']) + + if (bitrate === -1) return localFfmpeg.audioCodec('copy') + } + + if (bitrate !== undefined) return localFfmpeg.audioBitrate(bitrate) + + return localFfmpeg } diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 58381a0e5..cab096a12 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -209,19 +209,19 @@ describe('Test multiple servers', function () { files: [ { resolution: 240, - size: 342000 + size: 187000 }, { resolution: 360, - size: 433000 + size: 278000 }, { resolution: 480, - size: 538000 + size: 383000 }, { resolution: 720, - size: 861000 + size: 706000 } ], thumbnailfile: 'thumbnail',