X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fcreate-transcoding-job.ts;h=ca9e2a99ab3e41c91d345a687aec3cba4683ab55;hb=89613cb444b4e1601d202153d0ec8635392ec872;hp=67a270a8660ba88f5d5769a9fa24a0e616ac9bf5;hpb=2aaa1a3fdc49be77aec5309dab5507865c38d392;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/create-transcoding-job.ts b/scripts/create-transcoding-job.ts index 67a270a86..ca9e2a99a 100755 --- a/scripts/create-transcoding-job.ts +++ b/scripts/create-transcoding-job.ts @@ -3,13 +3,15 @@ registerTSPaths() import * as program from 'commander' import { VideoModel } from '../server/models/video/video' -import { initDatabaseModels } from '../server/initializers' +import { initDatabaseModels } from '../server/initializers/database' import { JobQueue } from '../server/lib/job-queue' -import { VideoTranscodingPayload } from '../server/lib/job-queue/handlers/video-transcoding' +import { computeResolutionsToTranscode } from '@server/helpers/ffprobe-utils' +import { VideoTranscodingPayload } from '@shared/models' program .option('-v, --video [videoUUID]', 'Video UUID') .option('-r, --resolution [resolution]', 'Video resolution (integer)') + .option('--generate-hls', 'Generate HLS playlist') .parse(process.argv) if (program['video'] === undefined) { @@ -32,14 +34,45 @@ run() async function run () { await initDatabaseModels(true) - const video = await VideoModel.loadByUUID(program['video']) + const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(program['video']) if (!video) throw new Error('Video not found.') - const dataInput: VideoTranscodingPayload = program.resolution !== undefined - ? { type: 'new-resolution' as 'new-resolution', videoUUID: video.uuid, isNewVideo: false, resolution: program.resolution } - : { type: 'optimize' as 'optimize', videoUUID: video.uuid, isNewVideo: false } + const dataInput: VideoTranscodingPayload[] = [] + const { videoFileResolution } = await video.getMaxQualityResolution() + + if (program.generateHls) { + const resolutionsEnabled = program.resolution + ? [ program.resolution ] + : computeResolutionsToTranscode(videoFileResolution, 'vod').concat([ videoFileResolution ]) + + for (const resolution of resolutionsEnabled) { + dataInput.push({ + type: 'new-resolution-to-hls', + videoUUID: video.uuid, + resolution, + isPortraitMode: false, + copyCodecs: false + }) + } + } else if (program.resolution !== undefined) { + dataInput.push({ + type: 'new-resolution-to-webtorrent', + videoUUID: video.uuid, + isNewVideo: false, + resolution: program.resolution + }) + } else { + dataInput.push({ + type: 'optimize-to-webtorrent', + videoUUID: video.uuid, + isNewVideo: false + }) + } await JobQueue.Instance.init() - await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }) - console.log('Transcoding job for video %s created.', video.uuid) + + for (const d of dataInput) { + await JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: d }) + console.log('Transcoding job for video %s created.', video.uuid) + } }