]>
Commit | Line | Data |
---|---|---|
1 | import { program } from 'commander' | |
2 | import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc' | |
3 | import { computeLowerResolutionsToTranscode } from '@server/helpers/ffmpeg' | |
4 | import { CONFIG } from '@server/initializers/config' | |
5 | import { addTranscodingJob } from '@server/lib/video' | |
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' | |
10 | ||
11 | program | |
12 | .option('-v, --video [videoUUID]', 'Video UUID') | |
13 | .option('-r, --resolution [resolution]', 'Video resolution (integer)') | |
14 | .option('--generate-hls', 'Generate HLS playlist') | |
15 | .parse(process.argv) | |
16 | ||
17 | const options = program.opts() | |
18 | ||
19 | if (options.video === undefined) { | |
20 | console.error('All parameters are mandatory.') | |
21 | process.exit(-1) | |
22 | } | |
23 | ||
24 | if (options.resolution !== undefined && Number.isNaN(+options.resolution)) { | |
25 | console.error('The resolution must be an integer (example: 1080).') | |
26 | process.exit(-1) | |
27 | } | |
28 | ||
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 | ||
39 | const uuid = toCompleteUUID(options.video) | |
40 | ||
41 | if (isUUIDValid(uuid) === false) { | |
42 | console.error('%s is not a valid video UUID.', options.video) | |
43 | return | |
44 | } | |
45 | ||
46 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(uuid) | |
47 | if (!video) throw new Error('Video not found.') | |
48 | ||
49 | const dataInput: VideoTranscodingPayload[] = [] | |
50 | const maxResolution = video.getMaxQualityFile().resolution | |
51 | ||
52 | // Generate HLS files | |
53 | if (options.generateHls || CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) { | |
54 | const resolutionsEnabled = options.resolution | |
55 | ? [ parseInt(options.resolution) ] | |
56 | : computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ]) | |
57 | ||
58 | for (const resolution of resolutionsEnabled) { | |
59 | dataInput.push({ | |
60 | type: 'new-resolution-to-hls', | |
61 | videoUUID: video.uuid, | |
62 | resolution, | |
63 | ||
64 | // FIXME: check the file has audio and is not in portrait mode | |
65 | isPortraitMode: false, | |
66 | hasAudio: true, | |
67 | ||
68 | copyCodecs: false, | |
69 | isNewVideo: false, | |
70 | isMaxQuality: maxResolution === resolution, | |
71 | autoDeleteWebTorrentIfNeeded: false | |
72 | }) | |
73 | } | |
74 | } else { | |
75 | if (options.resolution !== undefined) { | |
76 | dataInput.push({ | |
77 | type: 'new-resolution-to-webtorrent', | |
78 | videoUUID: video.uuid, | |
79 | ||
80 | createHLSIfNeeded: true, | |
81 | ||
82 | // FIXME: check the file has audio | |
83 | hasAudio: true, | |
84 | ||
85 | isNewVideo: false, | |
86 | resolution: parseInt(options.resolution) | |
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({ | |
95 | type: 'optimize-to-webtorrent', | |
96 | videoUUID: video.uuid, | |
97 | isNewVideo: false | |
98 | }) | |
99 | } | |
100 | } | |
101 | ||
102 | JobQueue.Instance.init(true) | |
103 | ||
104 | video.state = VideoState.TO_TRANSCODE | |
105 | await video.save() | |
106 | ||
107 | for (const d of dataInput) { | |
108 | await addTranscodingJob(d, {}) | |
109 | console.log('Transcoding job for video %s created.', video.uuid) | |
110 | } | |
111 | } |