]>
Commit | Line | Data |
---|---|---|
2aaa1a3f C |
1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' |
2 | registerTSPaths() | |
3 | ||
0c948c16 | 4 | import * as program from 'commander' |
0c948c16 C |
5 | import { VideoModel } from '../server/models/video/video' |
6 | import { initDatabaseModels } from '../server/initializers' | |
7 | import { JobQueue } from '../server/lib/job-queue' | |
536598cf | 8 | import { VideoTranscodingPayload } from '../server/lib/job-queue/handlers/video-transcoding' |
0c948c16 C |
9 | |
10 | program | |
11 | .option('-v, --video [videoUUID]', 'Video UUID') | |
05623b90 | 12 | .option('-r, --resolution [resolution]', 'Video resolution (integer)') |
0c948c16 C |
13 | .parse(process.argv) |
14 | ||
15 | if (program['video'] === undefined) { | |
16 | console.error('All parameters are mandatory.') | |
17 | process.exit(-1) | |
18 | } | |
19 | ||
05623b90 F |
20 | if (program.resolution !== undefined && Number.isNaN(+program.resolution)) { |
21 | console.error('The resolution must be an integer (example: 1080).') | |
22 | process.exit(-1) | |
23 | } | |
24 | ||
0c948c16 C |
25 | run() |
26 | .then(() => process.exit(0)) | |
27 | .catch(err => { | |
28 | console.error(err) | |
29 | process.exit(-1) | |
30 | }) | |
31 | ||
32 | async function run () { | |
33 | await initDatabaseModels(true) | |
34 | ||
e2600d8b | 35 | const video = await VideoModel.loadByUUID(program['video']) |
0c948c16 C |
36 | if (!video) throw new Error('Video not found.') |
37 | ||
536598cf C |
38 | const dataInput: VideoTranscodingPayload = program.resolution !== undefined |
39 | ? { type: 'new-resolution' as 'new-resolution', videoUUID: video.uuid, isNewVideo: false, resolution: program.resolution } | |
40 | : { type: 'optimize' as 'optimize', videoUUID: video.uuid, isNewVideo: false } | |
0c948c16 C |
41 | |
42 | await JobQueue.Instance.init() | |
a0327eed | 43 | await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }) |
0c948c16 C |
44 | console.log('Transcoding job for video %s created.', video.uuid) |
45 | } |