aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffprobe-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-24 14:08:23 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 10:07:51 +0100
commit5a547f69d5dc5867e253f7721513479c754b4f15 (patch)
tree5ccad0e07d04e24d7a4c0b624a46d3b5a93ebce5 /server/helpers/ffprobe-utils.ts
parent9252a33d115bba85adcfbc18ab3725924642871c (diff)
downloadPeerTube-5a547f69d5dc5867e253f7721513479c754b4f15.tar.gz
PeerTube-5a547f69d5dc5867e253f7721513479c754b4f15.tar.zst
PeerTube-5a547f69d5dc5867e253f7721513479c754b4f15.zip
Support encoding profiles
Diffstat (limited to 'server/helpers/ffprobe-utils.ts')
-rw-r--r--server/helpers/ffprobe-utils.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/server/helpers/ffprobe-utils.ts b/server/helpers/ffprobe-utils.ts
index 6159d3963..5545ddbbf 100644
--- a/server/helpers/ffprobe-utils.ts
+++ b/server/helpers/ffprobe-utils.ts
@@ -198,9 +198,12 @@ function computeResolutionsToTranscode (videoFileResolution: number, type: 'vod'
198async function canDoQuickTranscode (path: string): Promise<boolean> { 198async function canDoQuickTranscode (path: string): Promise<boolean> {
199 const probe = await ffprobePromise(path) 199 const probe = await ffprobePromise(path)
200 200
201 // NOTE: This could be optimized by running ffprobe only once (but it runs fast anyway) 201 return await canDoQuickVideoTranscode(path, probe) &&
202 await canDoQuickAudioTranscode(path, probe)
203}
204
205async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> {
202 const videoStream = await getVideoStreamFromFile(path, probe) 206 const videoStream = await getVideoStreamFromFile(path, probe)
203 const parsedAudio = await getAudioStream(path, probe)
204 const fps = await getVideoFileFPS(path, probe) 207 const fps = await getVideoFileFPS(path, probe)
205 const bitRate = await getVideoFileBitrate(path, probe) 208 const bitRate = await getVideoFileBitrate(path, probe)
206 const resolution = await getVideoFileResolution(path, probe) 209 const resolution = await getVideoFileResolution(path, probe)
@@ -212,6 +215,12 @@ async function canDoQuickTranscode (path: string): Promise<boolean> {
212 if (fps < VIDEO_TRANSCODING_FPS.MIN || fps > VIDEO_TRANSCODING_FPS.MAX) return false 215 if (fps < VIDEO_TRANSCODING_FPS.MIN || fps > VIDEO_TRANSCODING_FPS.MAX) return false
213 if (bitRate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) return false 216 if (bitRate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) return false
214 217
218 return true
219}
220
221async function canDoQuickAudioTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> {
222 const parsedAudio = await getAudioStream(path, probe)
223
215 // check audio params (if audio stream exists) 224 // check audio params (if audio stream exists)
216 if (parsedAudio.audioStream) { 225 if (parsedAudio.audioStream) {
217 if (parsedAudio.audioStream['codec_name'] !== 'aac') return false 226 if (parsedAudio.audioStream['codec_name'] !== 'aac') return false
@@ -239,11 +248,15 @@ export {
239 getVideoFileResolution, 248 getVideoFileResolution,
240 getMetadataFromFile, 249 getMetadataFromFile,
241 getMaxAudioBitrate, 250 getMaxAudioBitrate,
251 getVideoStreamFromFile,
242 getDurationFromVideoFile, 252 getDurationFromVideoFile,
243 getAudioStream, 253 getAudioStream,
244 getVideoFileFPS, 254 getVideoFileFPS,
255 ffprobePromise,
245 getClosestFramerateStandard, 256 getClosestFramerateStandard,
246 computeResolutionsToTranscode, 257 computeResolutionsToTranscode,
247 getVideoFileBitrate, 258 getVideoFileBitrate,
248 canDoQuickTranscode 259 canDoQuickTranscode,
260 canDoQuickVideoTranscode,
261 canDoQuickAudioTranscode
249} 262}