]>
Commit | Line | Data |
---|---|---|
8cc61201 | 1 | import { program } from 'commander' |
f8360396 | 2 | import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc' |
84cae54e | 3 | import { computeResolutionsToTranscode } from '@server/helpers/ffmpeg' |
20eb3a5b | 4 | import { CONFIG } from '@server/initializers/config' |
b42c2c7e | 5 | import { buildTranscodingJob } from '@server/lib/video' |
f8360396 C |
6 | import { VideoState, VideoTranscodingPayload } from '@shared/models' |
7 | import { initDatabaseModels } from '../server/initializers/database' | |
8 | import { JobQueue } from '../server/lib/job-queue' | |
9 | import { VideoModel } from '../server/models/video/video' | |
0c948c16 C |
10 | |
11 | program | |
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 | ||
ba5a8d89 C |
17 | const options = program.opts() |
18 | ||
19 | if (options.video === undefined) { | |
0c948c16 C |
20 | console.error('All parameters are mandatory.') |
21 | process.exit(-1) | |
22 | } | |
23 | ||
ba5a8d89 | 24 | if (options.resolution !== undefined && Number.isNaN(+options.resolution)) { |
05623b90 F |
25 | console.error('The resolution must be an integer (example: 1080).') |
26 | process.exit(-1) | |
27 | } | |
28 | ||
0c948c16 C |
29 | run() |
30 | .then(() => process.exit(0)) | |
31 | .catch(err => { | |
32 | console.error(err) | |
33 | process.exit(-1) | |
34 | }) | |
35 | ||
36 | async function run () { | |
37 | await initDatabaseModels(true) | |
38 | ||
c186a67f C |
39 | const uuid = toCompleteUUID(options.video) |
40 | ||
41 | if (isUUIDValid(uuid) === false) { | |
9aeef9aa C |
42 | console.error('%s is not a valid video UUID.', options.video) |
43 | return | |
44 | } | |
45 | ||
4fae2b1f | 46 | const video = await VideoModel.loadFull(uuid) |
0c948c16 C |
47 | if (!video) throw new Error('Video not found.') |
48 | ||
dee6fe1e | 49 | const dataInput: VideoTranscodingPayload[] = [] |
ad5db104 | 50 | const maxResolution = video.getMaxQualityFile().resolution |
dee6fe1e | 51 | |
a32bf8cd C |
52 | // FIXME: check the file has audio |
53 | const hasAudio = true | |
54 | ||
20eb3a5b C |
55 | // Generate HLS files |
56 | if (options.generateHls || CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) { | |
ba5a8d89 | 57 | const resolutionsEnabled = options.resolution |
8aad7ae4 | 58 | ? [ parseInt(options.resolution) ] |
a32bf8cd | 59 | : computeResolutionsToTranscode({ input: maxResolution, type: 'vod', includeInput: true, strictLower: false, hasAudio }) |
dee6fe1e C |
60 | |
61 | for (const resolution of resolutionsEnabled) { | |
62 | dataInput.push({ | |
b42c2c7e | 63 | type: 'new-resolution-to-hls' as 'new-resolution-to-hls', |
dee6fe1e C |
64 | videoUUID: video.uuid, |
65 | resolution, | |
cbe2f36d | 66 | |
a32bf8cd | 67 | hasAudio, |
cbe2f36d | 68 | |
9129b769 | 69 | copyCodecs: false, |
0305db28 | 70 | isNewVideo: false, |
ad5db104 C |
71 | isMaxQuality: maxResolution === resolution, |
72 | autoDeleteWebTorrentIfNeeded: false | |
dee6fe1e C |
73 | }) |
74 | } | |
dee6fe1e | 75 | } else { |
20eb3a5b C |
76 | if (options.resolution !== undefined) { |
77 | dataInput.push({ | |
b42c2c7e | 78 | type: 'new-resolution-to-webtorrent' as 'new-resolution-to-webtorrent', |
20eb3a5b | 79 | videoUUID: video.uuid, |
cbe2f36d | 80 | |
0f11ec8d C |
81 | createHLSIfNeeded: true, |
82 | ||
a32bf8cd | 83 | hasAudio, |
cbe2f36d | 84 | |
20eb3a5b | 85 | isNewVideo: false, |
8aad7ae4 | 86 | resolution: parseInt(options.resolution) |
20eb3a5b C |
87 | }) |
88 | } else { | |
89 | if (video.VideoFiles.length === 0) { | |
90 | console.error('Cannot regenerate webtorrent files with a HLS only video.') | |
91 | return | |
92 | } | |
93 | ||
94 | dataInput.push({ | |
b42c2c7e | 95 | type: 'optimize-to-webtorrent' as 'optimize-to-webtorrent', |
20eb3a5b C |
96 | videoUUID: video.uuid, |
97 | isNewVideo: false | |
98 | }) | |
99 | } | |
dee6fe1e | 100 | } |
0c948c16 | 101 | |
4404a7c4 | 102 | JobQueue.Instance.init() |
0305db28 JB |
103 | |
104 | video.state = VideoState.TO_TRANSCODE | |
105 | await video.save() | |
dee6fe1e C |
106 | |
107 | for (const d of dataInput) { | |
b42c2c7e C |
108 | await JobQueue.Instance.createJob(await buildTranscodingJob(d)) |
109 | ||
dee6fe1e C |
110 | console.log('Transcoding job for video %s created.', video.uuid) |
111 | } | |
0c948c16 | 112 | } |