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