aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/create-transcoding-job.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-11-22 10:45:03 +0100
committerChocobozzz <me@florianbigard.com>2019-11-25 10:59:47 +0100
commitdee6fe1e4f5c024fd387e8c2b306c174b24aa8b3 (patch)
tree50e5a19fc99b30c0d230829d20d8185e0d0f4069 /scripts/create-transcoding-job.ts
parent5a71acd2547c098657ae6e0e31e0862094585088 (diff)
downloadPeerTube-dee6fe1e4f5c024fd387e8c2b306c174b24aa8b3.tar.gz
PeerTube-dee6fe1e4f5c024fd387e8c2b306c174b24aa8b3.tar.zst
PeerTube-dee6fe1e4f5c024fd387e8c2b306c174b24aa8b3.zip
Add ability to generate HLS in CLI
Diffstat (limited to 'scripts/create-transcoding-job.ts')
-rwxr-xr-xscripts/create-transcoding-job.ts45
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'
6import { initDatabaseModels } from '../server/initializers' 6import { initDatabaseModels } from '../server/initializers'
7import { JobQueue } from '../server/lib/job-queue' 7import { JobQueue } from '../server/lib/job-queue'
8import { VideoTranscodingPayload } from '../server/lib/job-queue/handlers/video-transcoding' 8import { VideoTranscodingPayload } from '../server/lib/job-queue/handlers/video-transcoding'
9import { computeResolutionsToTranscode } from '@server/helpers/ffmpeg-utils'
9 10
10program 11program
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
15if (program['video'] === undefined) { 17if (program['video'] === undefined) {
@@ -32,14 +34,45 @@ run()
32async function run () { 34async 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}