diff options
Diffstat (limited to 'scripts/create-transcoding-job.ts')
-rwxr-xr-x | scripts/create-transcoding-job.ts | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/scripts/create-transcoding-job.ts b/scripts/create-transcoding-job.ts index 67a270a86..27170299d 100755 --- a/scripts/create-transcoding-job.ts +++ b/scripts/create-transcoding-job.ts | |||
@@ -6,10 +6,12 @@ import { VideoModel } from '../server/models/video/video' | |||
6 | import { initDatabaseModels } from '../server/initializers' | 6 | import { initDatabaseModels } from '../server/initializers' |
7 | import { JobQueue } from '../server/lib/job-queue' | 7 | import { JobQueue } from '../server/lib/job-queue' |
8 | import { VideoTranscodingPayload } from '../server/lib/job-queue/handlers/video-transcoding' | 8 | import { VideoTranscodingPayload } from '../server/lib/job-queue/handlers/video-transcoding' |
9 | import { computeResolutionsToTranscode } from '@server/helpers/ffmpeg-utils' | ||
9 | 10 | ||
10 | program | 11 | program |
11 | .option('-v, --video [videoUUID]', 'Video UUID') | 12 | .option('-v, --video [videoUUID]', 'Video UUID') |
12 | .option('-r, --resolution [resolution]', 'Video resolution (integer)') | 13 | .option('-r, --resolution [resolution]', 'Video resolution (integer)') |
14 | .option('--generate-hls', 'Generate HLS playlist') | ||
13 | .parse(process.argv) | 15 | .parse(process.argv) |
14 | 16 | ||
15 | if (program['video'] === undefined) { | 17 | if (program['video'] === undefined) { |
@@ -32,14 +34,45 @@ run() | |||
32 | async function run () { | 34 | async function run () { |
33 | await initDatabaseModels(true) | 35 | await initDatabaseModels(true) |
34 | 36 | ||
35 | const video = await VideoModel.loadByUUID(program['video']) | 37 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(program['video']) |
36 | if (!video) throw new Error('Video not found.') | 38 | if (!video) throw new Error('Video not found.') |
37 | 39 | ||
38 | const dataInput: VideoTranscodingPayload = program.resolution !== undefined | 40 | const dataInput: VideoTranscodingPayload[] = [] |
39 | ? { type: 'new-resolution' as 'new-resolution', videoUUID: video.uuid, isNewVideo: false, resolution: program.resolution } | 41 | const { videoFileResolution } = await video.getMaxQualityResolution() |
40 | : { type: 'optimize' as 'optimize', videoUUID: video.uuid, isNewVideo: false } | 42 | |
43 | if (program.generateHls) { | ||
44 | const resolutionsEnabled = program.resolution | ||
45 | ? [ program.resolution ] | ||
46 | : computeResolutionsToTranscode(videoFileResolution).concat([ videoFileResolution ]) | ||
47 | |||
48 | for (const resolution of resolutionsEnabled) { | ||
49 | dataInput.push({ | ||
50 | type: 'hls', | ||
51 | videoUUID: video.uuid, | ||
52 | resolution, | ||
53 | isPortraitMode: false, | ||
54 | copyCodecs: false | ||
55 | }) | ||
56 | } | ||
57 | } else if (program.resolution !== undefined) { | ||
58 | dataInput.push({ | ||
59 | type: 'new-resolution' as 'new-resolution', | ||
60 | videoUUID: video.uuid, | ||
61 | isNewVideo: false, | ||
62 | resolution: program.resolution | ||
63 | }) | ||
64 | } else { | ||
65 | dataInput.push({ | ||
66 | type: 'optimize' as 'optimize', | ||
67 | videoUUID: video.uuid, | ||
68 | isNewVideo: false | ||
69 | }) | ||
70 | } | ||
41 | 71 | ||
42 | await JobQueue.Instance.init() | 72 | await JobQueue.Instance.init() |
43 | await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }) | 73 | |
44 | console.log('Transcoding job for video %s created.', video.uuid) | 74 | for (const d of dataInput) { |
75 | await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: d }) | ||
76 | console.log('Transcoding job for video %s created.', video.uuid) | ||
77 | } | ||
45 | } | 78 | } |