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