1 import { registerTSPaths } from '../server/helpers/register-ts-paths'
4 import * as 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 { computeResolutionsToTranscode } from '@server/helpers/ffprobe-utils'
9 import { VideoTranscodingPayload } from '@shared/models'
12 .option('-v, --video [videoUUID]', 'Video UUID')
13 .option('-r, --resolution [resolution]', 'Video resolution (integer)')
14 .option('--generate-hls', 'Generate HLS playlist')
17 const options = program.opts()
19 if (options.video === undefined) {
20 console.error('All parameters are mandatory.')
24 if (options.resolution !== undefined && Number.isNaN(+options.resolution)) {
25 console.error('The resolution must be an integer (example: 1080).')
30 .then(() => process.exit(0))
36 async function run () {
37 await initDatabaseModels(true)
39 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(options.video)
40 if (!video) throw new Error('Video not found.')
42 const dataInput: VideoTranscodingPayload[] = []
43 const { videoFileResolution } = await video.getMaxQualityResolution()
45 if (options.generateHls) {
46 const resolutionsEnabled = options.resolution
47 ? [ options.resolution ]
48 : computeResolutionsToTranscode(videoFileResolution, 'vod').concat([ videoFileResolution ])
50 for (const resolution of resolutionsEnabled) {
52 type: 'new-resolution-to-hls',
53 videoUUID: video.uuid,
55 isPortraitMode: false,
60 } else if (options.resolution !== undefined) {
62 type: 'new-resolution-to-webtorrent',
63 videoUUID: video.uuid,
65 resolution: options.resolution
69 type: 'optimize-to-webtorrent',
70 videoUUID: video.uuid,
75 await JobQueue.Instance.init()
77 for (const d of dataInput) {
78 await JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: d })
79 console.log('Transcoding job for video %s created.', video.uuid)