]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/transcoding/transcoding-quick-transcode.ts
Implement remote runner jobs in server
[github/Chocobozzz/PeerTube.git] / server / lib / transcoding / transcoding-quick-transcode.ts
CommitLineData
0c9668f7
C
1import { FfprobeData } from 'fluent-ffmpeg'
2import { CONFIG } from '@server/initializers/config'
3import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants'
4import { getMaxBitrate } from '@shared/core-utils'
5import {
6 ffprobePromise,
7 getAudioStream,
8 getMaxAudioBitrate,
9 getVideoStream,
10 getVideoStreamBitrate,
11 getVideoStreamDimensionsInfo,
12 getVideoStreamFPS
13} from '@shared/ffmpeg'
14
15export async function canDoQuickTranscode (path: string, existingProbe?: FfprobeData): Promise<boolean> {
16 if (CONFIG.TRANSCODING.PROFILE !== 'default') return false
17
18 const probe = existingProbe || await ffprobePromise(path)
19
20 return await canDoQuickVideoTranscode(path, probe) &&
21 await canDoQuickAudioTranscode(path, probe)
22}
23
24export async function canDoQuickAudioTranscode (path: string, probe?: FfprobeData): Promise<boolean> {
25 const parsedAudio = await getAudioStream(path, probe)
26
27 if (!parsedAudio.audioStream) return true
28
29 if (parsedAudio.audioStream['codec_name'] !== 'aac') return false
30
31 const audioBitrate = parsedAudio.bitrate
32 if (!audioBitrate) return false
33
34 const maxAudioBitrate = getMaxAudioBitrate('aac', audioBitrate)
35 if (maxAudioBitrate !== -1 && audioBitrate > maxAudioBitrate) return false
36
37 const channelLayout = parsedAudio.audioStream['channel_layout']
38 // Causes playback issues with Chrome
39 if (!channelLayout || channelLayout === 'unknown' || channelLayout === 'quad') return false
40
41 return true
42}
43
44export async function canDoQuickVideoTranscode (path: string, probe?: FfprobeData): Promise<boolean> {
45 const videoStream = await getVideoStream(path, probe)
46 const fps = await getVideoStreamFPS(path, probe)
47 const bitRate = await getVideoStreamBitrate(path, probe)
48 const resolutionData = await getVideoStreamDimensionsInfo(path, probe)
49
50 // If ffprobe did not manage to guess the bitrate
51 if (!bitRate) return false
52
53 // check video params
54 if (!videoStream) return false
55 if (videoStream['codec_name'] !== 'h264') return false
56 if (videoStream['pix_fmt'] !== 'yuv420p') return false
57 if (fps < VIDEO_TRANSCODING_FPS.MIN || fps > VIDEO_TRANSCODING_FPS.MAX) return false
58 if (bitRate > getMaxBitrate({ ...resolutionData, fps })) return false
59
60 return true
61}