- 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 maxResolution = video.getMaxQualityFile().resolution
+
+ // Generate HLS files
+ if (options.generateHls || CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) {
+ const resolutionsEnabled = options.resolution
+ ? [ parseInt(options.resolution) ]
+ : computeResolutionsToTranscode({ input: maxResolution, type: 'vod', includeInput: true, strictLower: false })
+
+ for (const resolution of resolutionsEnabled) {
+ dataInput.push({
+ type: 'new-resolution-to-hls' as 'new-resolution-to-hls',
+ videoUUID: video.uuid,
+ resolution,
+
+ hasAudio: true,
+
+ copyCodecs: false,
+ isNewVideo: false,
+ isMaxQuality: maxResolution === resolution,
+ autoDeleteWebTorrentIfNeeded: false
+ })
+ }
+ } else {
+ if (options.resolution !== undefined) {
+ dataInput.push({
+ type: 'new-resolution-to-webtorrent' as 'new-resolution-to-webtorrent',
+ videoUUID: video.uuid,
+
+ createHLSIfNeeded: true,
+
+ // FIXME: check the file has audio
+ hasAudio: true,
+
+ isNewVideo: false,
+ resolution: parseInt(options.resolution)
+ })
+ } else {
+ if (video.VideoFiles.length === 0) {
+ console.error('Cannot regenerate webtorrent files with a HLS only video.')
+ return
+ }
+
+ dataInput.push({
+ type: 'optimize-to-webtorrent' as 'optimize-to-webtorrent',
+ videoUUID: video.uuid,
+ isNewVideo: false
+ })
+ }
+ }
+
+ JobQueue.Instance.init(true)
+
+ video.state = VideoState.TO_TRANSCODE
+ await video.save()
+
+ for (const d of dataInput) {
+ await JobQueue.Instance.createJob(await buildTranscodingJob(d))