1 import { registerTSPaths } from '../server/helpers/register-ts-paths'
4 import { program } from 'commander'
5 import { VideoModel } from '../server/models/video/video'
6 import { initDatabaseModels } from '../server/initializers/database'
7 import { JobQueue } from '../server/lib/job-queue'
8 import { computeLowerResolutionsToTranscode } from '@server/helpers/ffprobe-utils'
9 import { VideoState, VideoTranscodingPayload } from '@shared/models'
10 import { CONFIG } from '@server/initializers/config'
11 import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc'
12 import { addTranscodingJob } from '@server/lib/video'
15 .option('-v, --video [videoUUID]', 'Video UUID')
16 .option('-r, --resolution [resolution]', 'Video resolution (integer)')
17 .option('--generate-hls', 'Generate HLS playlist')
20 const options = program.opts()
22 if (options.video === undefined) {
23 console.error('All parameters are mandatory.')
27 if (options.resolution !== undefined && Number.isNaN(+options.resolution)) {
28 console.error('The resolution must be an integer (example: 1080).')
33 .then(() => process.exit(0))
39 async function run () {
40 await initDatabaseModels(true)
42 const uuid = toCompleteUUID(options.video)
44 if (isUUIDValid(uuid) === false) {
45 console.error('%s is not a valid video UUID.', options.video)
49 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(uuid)
50 if (!video) throw new Error('Video not found.')
52 const dataInput: VideoTranscodingPayload[] = []
53 const maxResolution = video.getMaxQualityFile().resolution
56 if (options.generateHls || CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) {
57 const resolutionsEnabled = options.resolution
58 ? [ parseInt(options.resolution) ]
59 : computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ])
61 for (const resolution of resolutionsEnabled) {
63 type: 'new-resolution-to-hls',
64 videoUUID: video.uuid,
66 isPortraitMode: false,
69 isMaxQuality: maxResolution === resolution,
70 autoDeleteWebTorrentIfNeeded: false
74 if (options.resolution !== undefined) {
76 type: 'new-resolution-to-webtorrent',
77 videoUUID: video.uuid,
79 resolution: parseInt(options.resolution)
82 if (video.VideoFiles.length === 0) {
83 console.error('Cannot regenerate webtorrent files with a HLS only video.')
88 type: 'optimize-to-webtorrent',
89 videoUUID: video.uuid,
95 JobQueue.Instance.init(true)
97 video.state = VideoState.TO_TRANSCODE
100 for (const d of dataInput) {
101 await addTranscodingJob(d, {})
102 console.log('Transcoding job for video %s created.', video.uuid)