]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/create-transcoding-job.ts
Add missing live config validators
[github/Chocobozzz/PeerTube.git] / scripts / create-transcoding-job.ts
CommitLineData
2aaa1a3f
C
1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths()
3
0c948c16 4import * as program from 'commander'
0c948c16 5import { VideoModel } from '../server/models/video/video'
80fdaf06 6import { initDatabaseModels } from '../server/initializers/database'
0c948c16 7import { JobQueue } from '../server/lib/job-queue'
daf6e480 8import { computeResolutionsToTranscode } from '@server/helpers/ffprobe-utils'
8dc8a34e 9import { VideoTranscodingPayload } from '@shared/models'
0c948c16
C
10
11program
12 .option('-v, --video [videoUUID]', 'Video UUID')
05623b90 13 .option('-r, --resolution [resolution]', 'Video resolution (integer)')
dee6fe1e 14 .option('--generate-hls', 'Generate HLS playlist')
0c948c16
C
15 .parse(process.argv)
16
ba5a8d89
C
17const options = program.opts()
18
19if (options.video === undefined) {
0c948c16
C
20 console.error('All parameters are mandatory.')
21 process.exit(-1)
22}
23
ba5a8d89 24if (options.resolution !== undefined && Number.isNaN(+options.resolution)) {
05623b90
F
25 console.error('The resolution must be an integer (example: 1080).')
26 process.exit(-1)
27}
28
0c948c16
C
29run()
30 .then(() => process.exit(0))
31 .catch(err => {
32 console.error(err)
33 process.exit(-1)
34 })
35
36async function run () {
37 await initDatabaseModels(true)
38
ba5a8d89 39 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(options.video)
0c948c16
C
40 if (!video) throw new Error('Video not found.')
41
dee6fe1e
C
42 const dataInput: VideoTranscodingPayload[] = []
43 const { videoFileResolution } = await video.getMaxQualityResolution()
44
ba5a8d89
C
45 if (options.generateHls) {
46 const resolutionsEnabled = options.resolution
47 ? [ options.resolution ]
c6c0fa6c 48 : computeResolutionsToTranscode(videoFileResolution, 'vod').concat([ videoFileResolution ])
dee6fe1e
C
49
50 for (const resolution of resolutionsEnabled) {
51 dataInput.push({
24516aa2 52 type: 'new-resolution-to-hls',
dee6fe1e
C
53 videoUUID: video.uuid,
54 resolution,
55 isPortraitMode: false,
9129b769
C
56 copyCodecs: false,
57 isMaxQuality: false
dee6fe1e
C
58 })
59 }
ba5a8d89 60 } else if (options.resolution !== undefined) {
dee6fe1e 61 dataInput.push({
24516aa2 62 type: 'new-resolution-to-webtorrent',
dee6fe1e
C
63 videoUUID: video.uuid,
64 isNewVideo: false,
ba5a8d89 65 resolution: options.resolution
dee6fe1e
C
66 })
67 } else {
68 dataInput.push({
24516aa2 69 type: 'optimize-to-webtorrent',
dee6fe1e
C
70 videoUUID: video.uuid,
71 isNewVideo: false
72 })
73 }
0c948c16
C
74
75 await JobQueue.Instance.init()
dee6fe1e
C
76
77 for (const d of dataInput) {
a1587156 78 await JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: d })
dee6fe1e
C
79 console.log('Transcoding job for video %s created.', video.uuid)
80 }
0c948c16 81}