aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/ffprobe-utils.ts56
1 files changed, 29 insertions, 27 deletions
diff --git a/server/helpers/ffprobe-utils.ts b/server/helpers/ffprobe-utils.ts
index 5545ddbbf..d03ab91ac 100644
--- a/server/helpers/ffprobe-utils.ts
+++ b/server/helpers/ffprobe-utils.ts
@@ -37,38 +37,37 @@ async function getAudioStream (videoPath: string, existingProbe?: ffmpeg.Ffprobe
37} 37}
38 38
39function getMaxAudioBitrate (type: 'aac' | 'mp3' | string, bitrate: number) { 39function getMaxAudioBitrate (type: 'aac' | 'mp3' | string, bitrate: number) {
40 const baseKbitrate = 384 40 const maxKBitrate = 384
41 const toBits = (kbits: number) => kbits * 8000 41 const kToBits = (kbits: number) => kbits * 1000
42
43 // If we did not manage to get the bitrate, use an average value
44 if (!bitrate) return 256
42 45
43 if (type === 'aac') { 46 if (type === 'aac') {
44 switch (true) { 47 switch (true) {
45 case bitrate > toBits(baseKbitrate): 48 case bitrate > kToBits(maxKBitrate):
46 return baseKbitrate 49 return maxKBitrate
47 50
48 default: 51 default:
49 return -1 // we interpret it as a signal to copy the audio stream as is 52 return -1 // we interpret it as a signal to copy the audio stream as is
50 } 53 }
51 } 54 }
52 55
53 if (type === 'mp3') { 56 /*
54 /* 57 a 192kbit/sec mp3 doesn't hold as much information as a 192kbit/sec aac.
55 a 192kbit/sec mp3 doesn't hold as much information as a 192kbit/sec aac. 58 That's why, when using aac, we can go to lower kbit/sec. The equivalences
56 That's why, when using aac, we can go to lower kbit/sec. The equivalences 59 made here are not made to be accurate, especially with good mp3 encoders.
57 made here are not made to be accurate, especially with good mp3 encoders. 60 */
58 */ 61 switch (true) {
59 switch (true) { 62 case bitrate <= kToBits(192):
60 case bitrate <= toBits(192): 63 return 128
61 return 128
62 64
63 case bitrate <= toBits(384): 65 case bitrate <= kToBits(384):
64 return 256 66 return 256
65 67
66 default: 68 default:
67 return baseKbitrate 69 return maxKBitrate
68 }
69 } 70 }
70
71 return undefined
72} 71}
73 72
74async function getVideoStreamSize (path: string, existingProbe?: ffmpeg.FfprobeData) { 73async function getVideoStreamSize (path: string, existingProbe?: ffmpeg.FfprobeData) {
@@ -208,6 +207,9 @@ async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeDat
208 const bitRate = await getVideoFileBitrate(path, probe) 207 const bitRate = await getVideoFileBitrate(path, probe)
209 const resolution = await getVideoFileResolution(path, probe) 208 const resolution = await getVideoFileResolution(path, probe)
210 209
210 // If ffprobe did not manage to guess the bitrate
211 if (!bitRate) return false
212
211 // check video params 213 // check video params
212 if (videoStream == null) return false 214 if (videoStream == null) return false
213 if (videoStream['codec_name'] !== 'h264') return false 215 if (videoStream['codec_name'] !== 'h264') return false
@@ -221,15 +223,15 @@ async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeDat
221async function canDoQuickAudioTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> { 223async function canDoQuickAudioTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> {
222 const parsedAudio = await getAudioStream(path, probe) 224 const parsedAudio = await getAudioStream(path, probe)
223 225
224 // check audio params (if audio stream exists) 226 if (!parsedAudio.audioStream) return true
225 if (parsedAudio.audioStream) {
226 if (parsedAudio.audioStream['codec_name'] !== 'aac') return false
227 227
228 const audioBitrate = parsedAudio.bitrate 228 if (parsedAudio.audioStream['codec_name'] !== 'aac') return false
229 229
230 const maxAudioBitrate = getMaxAudioBitrate('aac', audioBitrate) 230 const audioBitrate = parsedAudio.bitrate
231 if (maxAudioBitrate !== -1 && audioBitrate > maxAudioBitrate) return false 231 if (!audioBitrate) return false
232 } 232
233 const maxAudioBitrate = getMaxAudioBitrate('aac', audioBitrate)
234 if (maxAudioBitrate !== -1 && audioBitrate > maxAudioBitrate) return false
233 235
234 return true 236 return true
235} 237}