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'
7 import { JobQueue } from '../server/lib/job-queue'
8 import { VideoTranscodingPayload } from '../server/lib/job-queue/handlers/video-transcoding'
9 import { computeResolutionsToTranscode } from '@server/helpers/ffmpeg-utils'
12 .option('-v, --video [videoUUID]', 'Video UUID')
13 .option('-r, --resolution [resolution]', 'Video resolution (integer)')
14 .option('--generate-hls', 'Generate HLS playlist')
17 if (program['video'] === undefined) {
18 console.error('All parameters are mandatory.')
22 if (program.resolution !== undefined && Number.isNaN(+program.resolution)) {
23 console.error('The resolution must be an integer (example: 1080).')
28 .then(() => process.exit(0))
34 async function run () {
35 await initDatabaseModels(true)
37 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(program['video'])
38 if (!video) throw new Error('Video not found.')
40 const dataInput: VideoTranscodingPayload[] = []
41 const { videoFileResolution } = await video.getMaxQualityResolution()
43 if (program.generateHls) {
44 const resolutionsEnabled = program.resolution
45 ? [ program.resolution ]
46 : computeResolutionsToTranscode(videoFileResolution).concat([ videoFileResolution ])
48 for (const resolution of resolutionsEnabled) {
51 videoUUID: video.uuid,
53 isPortraitMode: false,
57 } else if (program.resolution !== undefined) {
59 type: 'new-resolution' as 'new-resolution',
60 videoUUID: video.uuid,
62 resolution: program.resolution
66 type: 'optimize' as 'optimize',
67 videoUUID: video.uuid,
72 await JobQueue.Instance.init()
74 for (const d of dataInput) {
75 await JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: d })
76 console.log('Transcoding job for video %s created.', video.uuid)