]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/ffmpeg/ffmpeg-options.ts
64d7c417998390baa54e3ff7a5d988cd173e14f9
[github/Chocobozzz/PeerTube.git] / server / helpers / ffmpeg / ffmpeg-options.ts
1 import { logger } from '@server/helpers/logger'
2 import { CONFIG } from '@server/initializers/config'
3 import { FFMPEG_NICE } from '@server/initializers/constants'
4 import { FFmpegCommandWrapperOptions } from '@shared/ffmpeg'
5 import { AvailableEncoders } from '@shared/models'
6
7 type CommandType = 'live' | 'vod' | 'thumbnail'
8
9 export function getFFmpegCommandWrapperOptions (type: CommandType, availableEncoders?: AvailableEncoders): FFmpegCommandWrapperOptions {
10 return {
11 availableEncoders,
12 profile: getProfile(type),
13
14 niceness: FFMPEG_NICE[type.toUpperCase()],
15 tmpDirectory: CONFIG.STORAGE.TMP_DIR,
16 threads: getThreads(type),
17
18 logger: {
19 debug: logger.debug.bind(logger),
20 info: logger.info.bind(logger),
21 warn: logger.warn.bind(logger),
22 error: logger.error.bind(logger)
23 },
24 lTags: { tags: [ 'ffmpeg' ] }
25 }
26 }
27
28 // ---------------------------------------------------------------------------
29 // Private
30 // ---------------------------------------------------------------------------
31
32 function getThreads (type: CommandType) {
33 if (type === 'live') return CONFIG.LIVE.TRANSCODING.THREADS
34 if (type === 'vod') return CONFIG.TRANSCODING.THREADS
35
36 // Auto
37 return 0
38 }
39
40 function getProfile (type: CommandType) {
41 if (type === 'live') return CONFIG.LIVE.TRANSCODING.PROFILE
42 if (type === 'vod') return CONFIG.TRANSCODING.PROFILE
43
44 return undefined
45 }