X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fcreate-transcoding-job.ts;h=ca9e2a99ab3e41c91d345a687aec3cba4683ab55;hb=89613cb444b4e1601d202153d0ec8635392ec872;hp=3ea30f98e642701d5bf85e60387308c1c0fa88c1;hpb=3aa5cea8fec998805e32c0480884906d8e4fd490;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/create-transcoding-job.ts b/scripts/create-transcoding-job.ts index 3ea30f98e..ca9e2a99a 100755 --- a/scripts/create-transcoding-job.ts +++ b/scripts/create-transcoding-job.ts @@ -1,11 +1,17 @@ +import { registerTSPaths } from '../server/helpers/register-ts-paths' +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 { 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) { @@ -28,20 +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 = { - videoUUID: video.uuid, - isNewVideo: false, - resolution: undefined - } + const dataInput: VideoTranscodingPayload[] = [] + const { videoFileResolution } = await video.getMaxQualityResolution() + + if (program.generateHls) { + const resolutionsEnabled = program.resolution + ? [ program.resolution ] + : computeResolutionsToTranscode(videoFileResolution, 'vod').concat([ videoFileResolution ]) - if (program.resolution !== undefined) { - dataInput.resolution = program.resolution + 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-file', 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) + } }