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