]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/create-transcoding-job.ts
Bind expanded rows to item ids instead of row number
[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
C
5import { VideoModel } from '../server/models/video/video'
6import { initDatabaseModels } from '../server/initializers'
7import { JobQueue } from '../server/lib/job-queue'
536598cf 8import { VideoTranscodingPayload } from '../server/lib/job-queue/handlers/video-transcoding'
dee6fe1e 9import { computeResolutionsToTranscode } from '@server/helpers/ffmpeg-utils'
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
17if (program['video'] === undefined) {
18 console.error('All parameters are mandatory.')
19 process.exit(-1)
20}
21
05623b90
F
22if (program.resolution !== undefined && Number.isNaN(+program.resolution)) {
23 console.error('The resolution must be an integer (example: 1080).')
24 process.exit(-1)
25}
26
0c948c16
C
27run()
28 .then(() => process.exit(0))
29 .catch(err => {
30 console.error(err)
31 process.exit(-1)
32 })
33
34async function run () {
35 await initDatabaseModels(true)
36
dee6fe1e 37 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(program['video'])
0c948c16
C
38 if (!video) throw new Error('Video not found.')
39
dee6fe1e
C
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).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 }
0c948c16
C
71
72 await JobQueue.Instance.init()
dee6fe1e
C
73
74 for (const d of dataInput) {
a1587156 75 await JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: d })
dee6fe1e
C
76 console.log('Transcoding job for video %s created.', video.uuid)
77 }
0c948c16 78}