2022-08-08 04:42:08 -04:00
|
|
|
import { Job } from 'bullmq'
|
2022-02-11 04:51:33 -05:00
|
|
|
import { TranscodeVODOptionsType } from '@server/helpers/ffmpeg'
|
2022-08-05 04:36:19 -04:00
|
|
|
import { Hooks } from '@server/lib/plugins/hooks'
|
2022-08-09 03:09:31 -04:00
|
|
|
import { buildTranscodingJob, getTranscodingJobPriority } from '@server/lib/video'
|
2021-08-17 02:26:20 -04:00
|
|
|
import { VideoPathManager } from '@server/lib/video-path-manager'
|
2021-11-09 05:52:41 -05:00
|
|
|
import { moveToFailedTranscodingState, moveToNextState } from '@server/lib/video-state'
|
2021-05-11 05:15:29 -04:00
|
|
|
import { UserModel } from '@server/models/user/user'
|
2021-08-17 02:26:20 -04:00
|
|
|
import { VideoJobInfoModel } from '@server/models/video/video-job-info'
|
|
|
|
import { MUser, MUserId, MVideo, MVideoFullLight, MVideoWithFile } from '@server/types/models'
|
2022-01-06 11:55:37 -05:00
|
|
|
import { pick } from '@shared/core-utils'
|
2020-04-23 03:32:53 -04:00
|
|
|
import {
|
2021-01-21 09:58:17 -05:00
|
|
|
HLSTranscodingPayload,
|
2020-04-23 03:32:53 -04:00
|
|
|
MergeAudioTranscodingPayload,
|
2022-02-01 05:16:45 -05:00
|
|
|
NewWebTorrentResolutionTranscodingPayload,
|
2020-04-23 03:32:53 -04:00
|
|
|
OptimizeTranscodingPayload,
|
2022-01-06 11:55:37 -05:00
|
|
|
VideoResolution,
|
2020-04-23 03:32:53 -04:00
|
|
|
VideoTranscodingPayload
|
2021-12-24 04:14:47 -05:00
|
|
|
} from '@shared/models'
|
2020-10-26 11:44:23 -04:00
|
|
|
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
2022-08-05 04:36:19 -04:00
|
|
|
import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg'
|
2021-08-26 03:18:57 -04:00
|
|
|
import { logger, loggerTagsFactory } from '../../../helpers/logger'
|
2020-10-26 11:44:23 -04:00
|
|
|
import { CONFIG } from '../../../initializers/config'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2021-01-21 09:58:17 -05:00
|
|
|
import {
|
|
|
|
generateHlsPlaylistResolution,
|
|
|
|
mergeAudioVideofile,
|
|
|
|
optimizeOriginalVideofile,
|
|
|
|
transcodeNewWebTorrentResolution
|
2022-02-11 04:51:33 -05:00
|
|
|
} from '../../transcoding/transcoding'
|
2022-08-09 03:09:31 -04:00
|
|
|
import { JobQueue } from '../job-queue'
|
2021-01-21 09:58:17 -05:00
|
|
|
|
2021-08-27 08:32:44 -04:00
|
|
|
type HandlerFunction = (job: Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<void>
|
2021-01-21 10:57:21 -05:00
|
|
|
|
2021-08-05 08:29:44 -04:00
|
|
|
const handlers: { [ id in VideoTranscodingPayload['type'] ]: HandlerFunction } = {
|
2021-01-21 09:58:17 -05:00
|
|
|
'new-resolution-to-hls': handleHLSJob,
|
|
|
|
'new-resolution-to-webtorrent': handleNewWebTorrentResolutionJob,
|
|
|
|
'merge-audio-to-webtorrent': handleWebTorrentMergeAudioJob,
|
|
|
|
'optimize-to-webtorrent': handleWebTorrentOptimizeJob
|
|
|
|
}
|
2017-10-02 06:20:26 -04:00
|
|
|
|
2021-08-26 03:18:57 -04:00
|
|
|
const lTags = loggerTagsFactory('transcoding')
|
|
|
|
|
2021-08-27 08:32:44 -04:00
|
|
|
async function processVideoTranscoding (job: Job) {
|
2019-03-19 12:00:08 -04:00
|
|
|
const payload = job.data as VideoTranscodingPayload
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('Processing transcoding job %d.', job.id, lTags(payload.videoUUID))
|
2018-01-25 09:05:18 -05:00
|
|
|
|
2022-06-28 08:57:51 -04:00
|
|
|
const video = await VideoModel.loadFull(payload.videoUUID)
|
2017-10-25 10:03:33 -04:00
|
|
|
// No video, maybe deleted?
|
|
|
|
if (!video) {
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('Do not process job %d, video does not exist.', job.id, lTags(payload.videoUUID))
|
2017-10-25 10:03:33 -04:00
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
2021-01-21 10:57:21 -05:00
|
|
|
const user = await UserModel.loadByChannelActorId(video.VideoChannel.actorId)
|
|
|
|
|
2021-01-21 09:58:17 -05:00
|
|
|
const handler = handlers[payload.type]
|
2020-10-26 11:44:23 -04:00
|
|
|
|
2021-01-21 09:58:17 -05:00
|
|
|
if (!handler) {
|
2021-11-09 05:52:41 -05:00
|
|
|
await moveToFailedTranscodingState(video)
|
2021-12-03 08:40:29 -05:00
|
|
|
await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
|
2021-11-09 05:52:41 -05:00
|
|
|
|
2021-01-21 09:58:17 -05:00
|
|
|
throw new Error('Cannot find transcoding handler for ' + payload.type)
|
|
|
|
}
|
2020-10-26 11:44:23 -04:00
|
|
|
|
2021-11-07 22:20:04 -05:00
|
|
|
try {
|
|
|
|
await handler(job, payload, video, user)
|
|
|
|
} catch (error) {
|
2021-11-09 05:52:41 -05:00
|
|
|
await moveToFailedTranscodingState(video)
|
2021-11-07 22:20:04 -05:00
|
|
|
|
2021-12-03 08:40:29 -05:00
|
|
|
await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
|
|
|
|
|
2021-11-07 22:20:04 -05:00
|
|
|
throw error
|
|
|
|
}
|
2021-01-21 09:58:17 -05:00
|
|
|
|
|
|
|
return video
|
|
|
|
}
|
2019-01-29 02:37:25 -05:00
|
|
|
|
2021-12-03 08:40:29 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
processVideoTranscoding
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:58:17 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Job handlers
|
|
|
|
// ---------------------------------------------------------------------------
|
2018-06-12 14:04:58 -04:00
|
|
|
|
2021-08-27 08:32:44 -04:00
|
|
|
async function handleHLSJob (job: Job, payload: HLSTranscodingPayload, video: MVideoFullLight, user: MUser) {
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('Handling HLS transcoding job for %s.', video.uuid, lTags(video.uuid))
|
|
|
|
|
2021-01-21 09:58:17 -05:00
|
|
|
const videoFileInput = payload.copyCodecs
|
|
|
|
? video.getWebTorrentFile(payload.resolution)
|
|
|
|
: video.getMaxQualityFile()
|
|
|
|
|
|
|
|
const videoOrStreamingPlaylist = videoFileInput.getVideoOrStreamingPlaylist()
|
|
|
|
|
2021-11-18 08:35:08 -05:00
|
|
|
await VideoPathManager.Instance.makeAvailableVideoFile(videoFileInput.withVideoOrPlaylist(videoOrStreamingPlaylist), videoInputPath => {
|
2021-08-17 02:26:20 -04:00
|
|
|
return generateHlsPlaylistResolution({
|
|
|
|
video,
|
|
|
|
videoInputPath,
|
|
|
|
resolution: payload.resolution,
|
|
|
|
copyCodecs: payload.copyCodecs,
|
|
|
|
job
|
|
|
|
})
|
2021-01-21 09:58:17 -05:00
|
|
|
})
|
2019-05-16 10:55:34 -04:00
|
|
|
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('HLS transcoding job for %s ended.', video.uuid, lTags(video.uuid))
|
|
|
|
|
2021-11-29 05:20:17 -05:00
|
|
|
await onHlsPlaylistGeneration(video, user, payload)
|
2021-01-21 09:58:17 -05:00
|
|
|
}
|
2018-06-12 14:04:58 -04:00
|
|
|
|
2021-01-21 10:57:21 -05:00
|
|
|
async function handleNewWebTorrentResolutionJob (
|
2021-08-27 08:32:44 -04:00
|
|
|
job: Job,
|
2022-02-01 05:16:45 -05:00
|
|
|
payload: NewWebTorrentResolutionTranscodingPayload,
|
2021-01-21 10:57:21 -05:00
|
|
|
video: MVideoFullLight,
|
|
|
|
user: MUserId
|
|
|
|
) {
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('Handling WebTorrent transcoding job for %s.', video.uuid, lTags(video.uuid))
|
|
|
|
|
2022-08-05 04:36:19 -04:00
|
|
|
await transcodeNewWebTorrentResolution({ video, resolution: payload.resolution, job })
|
2017-10-17 09:37:40 -04:00
|
|
|
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('WebTorrent transcoding job for %s ended.', video.uuid, lTags(video.uuid))
|
|
|
|
|
2021-11-29 05:20:17 -05:00
|
|
|
await onNewWebTorrentFileResolution(video, user, payload)
|
2021-01-21 09:58:17 -05:00
|
|
|
}
|
|
|
|
|
2021-08-27 08:32:44 -04:00
|
|
|
async function handleWebTorrentMergeAudioJob (job: Job, payload: MergeAudioTranscodingPayload, video: MVideoFullLight, user: MUserId) {
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('Handling merge audio transcoding job for %s.', video.uuid, lTags(video.uuid))
|
|
|
|
|
2022-08-05 04:36:19 -04:00
|
|
|
await mergeAudioVideofile({ video, resolution: payload.resolution, job })
|
2021-01-21 09:58:17 -05:00
|
|
|
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('Merge audio transcoding job for %s ended.', video.uuid, lTags(video.uuid))
|
|
|
|
|
2021-12-03 08:40:29 -05:00
|
|
|
await onVideoFirstWebTorrentTranscoding(video, payload, 'video', user)
|
2017-10-02 06:20:26 -04:00
|
|
|
}
|
|
|
|
|
2021-08-27 08:32:44 -04:00
|
|
|
async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodingPayload, video: MVideoFullLight, user: MUserId) {
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('Handling optimize transcoding job for %s.', video.uuid, lTags(video.uuid))
|
|
|
|
|
2022-08-05 04:36:19 -04:00
|
|
|
const { transcodeType } = await optimizeOriginalVideofile({ video, inputVideoFile: video.getMaxQualityFile(), job })
|
2021-01-21 09:58:17 -05:00
|
|
|
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('Optimize transcoding job for %s ended.', video.uuid, lTags(video.uuid))
|
|
|
|
|
2021-12-03 08:40:29 -05:00
|
|
|
await onVideoFirstWebTorrentTranscoding(video, payload, transcodeType, user)
|
2021-01-21 09:58:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-02-08 04:51:10 -05:00
|
|
|
async function onHlsPlaylistGeneration (video: MVideoFullLight, user: MUser, payload: HLSTranscodingPayload) {
|
2021-11-18 08:35:08 -05:00
|
|
|
if (payload.isMaxQuality && payload.autoDeleteWebTorrentIfNeeded && CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) {
|
2021-02-08 04:51:10 -05:00
|
|
|
// Remove webtorrent files if not enabled
|
2019-11-15 09:06:03 -05:00
|
|
|
for (const file of video.VideoFiles) {
|
2022-07-29 08:50:41 -04:00
|
|
|
await video.removeWebTorrentFile(file)
|
2019-11-15 09:06:03 -05:00
|
|
|
await file.destroy()
|
2018-06-28 10:58:15 -04:00
|
|
|
}
|
2018-06-12 14:04:58 -04:00
|
|
|
|
2019-11-15 09:06:03 -05:00
|
|
|
video.VideoFiles = []
|
2021-02-08 04:51:10 -05:00
|
|
|
|
|
|
|
// Create HLS new resolution jobs
|
2021-08-17 02:26:20 -04:00
|
|
|
await createLowerResolutionsJobs({
|
|
|
|
video,
|
|
|
|
user,
|
|
|
|
videoFileResolution: payload.resolution,
|
2022-01-06 11:55:37 -05:00
|
|
|
hasAudio: payload.hasAudio,
|
2021-08-17 02:26:20 -04:00
|
|
|
isNewVideo: payload.isNewVideo ?? true,
|
|
|
|
type: 'hls'
|
|
|
|
})
|
2019-11-15 09:06:03 -05:00
|
|
|
}
|
2018-01-25 09:05:18 -05:00
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
|
2022-03-22 09:35:04 -04:00
|
|
|
await retryTransactionWrapper(moveToNextState, { video, isNewVideo: payload.isNewVideo })
|
2019-11-15 09:06:03 -05:00
|
|
|
}
|
2018-12-28 07:47:17 -05:00
|
|
|
|
2021-12-03 08:40:29 -05:00
|
|
|
async function onVideoFirstWebTorrentTranscoding (
|
2020-12-22 09:42:02 -05:00
|
|
|
videoArg: MVideoWithFile,
|
2021-02-08 04:51:10 -05:00
|
|
|
payload: OptimizeTranscodingPayload | MergeAudioTranscodingPayload,
|
2022-02-11 04:51:33 -05:00
|
|
|
transcodeType: TranscodeVODOptionsType,
|
2021-01-21 10:57:21 -05:00
|
|
|
user: MUserId
|
2020-12-22 09:42:02 -05:00
|
|
|
) {
|
2022-08-05 04:36:19 -04:00
|
|
|
const { resolution, audioStream } = await videoArg.probeMaxQualityFile()
|
2018-06-12 14:04:58 -04:00
|
|
|
|
2021-06-15 03:17:19 -04:00
|
|
|
// Maybe the video changed in database, refresh it
|
2022-06-28 08:57:51 -04:00
|
|
|
const videoDatabase = await VideoModel.loadFull(videoArg.uuid)
|
2021-06-15 03:17:19 -04:00
|
|
|
// Video does not exist anymore
|
|
|
|
if (!videoDatabase) return undefined
|
|
|
|
|
|
|
|
// Generate HLS version of the original file
|
2021-08-17 02:26:20 -04:00
|
|
|
const originalFileHLSPayload = {
|
|
|
|
...payload,
|
|
|
|
|
2022-01-06 11:55:37 -05:00
|
|
|
hasAudio: !!audioStream,
|
2021-06-15 03:17:19 -04:00
|
|
|
resolution: videoDatabase.getMaxQualityFile().resolution,
|
|
|
|
// If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues
|
|
|
|
copyCodecs: transcodeType !== 'quick-transcode',
|
|
|
|
isMaxQuality: true
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|
2021-06-15 03:17:19 -04:00
|
|
|
const hasHls = await createHlsJobIfEnabled(user, originalFileHLSPayload)
|
2021-08-17 02:26:20 -04:00
|
|
|
const hasNewResolutions = await createLowerResolutionsJobs({
|
|
|
|
video: videoDatabase,
|
|
|
|
user,
|
|
|
|
videoFileResolution: resolution,
|
2022-01-06 11:55:37 -05:00
|
|
|
hasAudio: !!audioStream,
|
2021-08-17 02:26:20 -04:00
|
|
|
type: 'webtorrent',
|
|
|
|
isNewVideo: payload.isNewVideo ?? true
|
|
|
|
})
|
2018-03-19 10:02:36 -04:00
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
await VideoJobInfoModel.decrease(videoDatabase.uuid, 'pendingTranscode')
|
2018-12-28 07:47:17 -05:00
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
// Move to next state if there are no other resolutions to generate
|
2021-06-15 03:17:19 -04:00
|
|
|
if (!hasHls && !hasNewResolutions) {
|
2022-03-22 09:35:04 -04:00
|
|
|
await retryTransactionWrapper(moveToNextState, { video: videoDatabase, isNewVideo: payload.isNewVideo })
|
2021-06-15 03:17:19 -04:00
|
|
|
}
|
2017-10-02 06:20:26 -04:00
|
|
|
}
|
|
|
|
|
2021-01-21 09:58:17 -05:00
|
|
|
async function onNewWebTorrentFileResolution (
|
2021-08-17 02:26:20 -04:00
|
|
|
video: MVideo,
|
2021-01-21 10:57:21 -05:00
|
|
|
user: MUserId,
|
2022-02-01 05:16:45 -05:00
|
|
|
payload: NewWebTorrentResolutionTranscodingPayload | MergeAudioTranscodingPayload
|
2021-01-21 09:58:17 -05:00
|
|
|
) {
|
2022-02-01 05:16:45 -05:00
|
|
|
if (payload.createHLSIfNeeded) {
|
|
|
|
await createHlsJobIfEnabled(user, { hasAudio: true, copyCodecs: true, isMaxQuality: false, ...payload })
|
|
|
|
}
|
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
|
2021-01-21 09:58:17 -05:00
|
|
|
|
2022-03-22 09:35:04 -04:00
|
|
|
await retryTransactionWrapper(moveToNextState, { video, isNewVideo: payload.isNewVideo })
|
2021-01-21 09:58:17 -05:00
|
|
|
}
|
|
|
|
|
2021-12-03 08:40:29 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-01-21 10:57:21 -05:00
|
|
|
async function createHlsJobIfEnabled (user: MUserId, payload: {
|
|
|
|
videoUUID: string
|
|
|
|
resolution: number
|
2022-01-06 11:55:37 -05:00
|
|
|
hasAudio: boolean
|
2021-01-21 10:57:21 -05:00
|
|
|
copyCodecs: boolean
|
2021-02-08 04:51:10 -05:00
|
|
|
isMaxQuality: boolean
|
2021-08-17 02:26:20 -04:00
|
|
|
isNewVideo?: boolean
|
2021-01-21 10:57:21 -05:00
|
|
|
}) {
|
2021-08-17 02:26:20 -04:00
|
|
|
if (!payload || CONFIG.TRANSCODING.ENABLED !== true || CONFIG.TRANSCODING.HLS.ENABLED !== true) return false
|
2021-01-21 10:57:21 -05:00
|
|
|
|
|
|
|
const jobOptions = {
|
2021-05-05 03:25:11 -04:00
|
|
|
priority: await getTranscodingJobPriority(user)
|
2021-01-21 10:57:21 -05:00
|
|
|
}
|
2019-01-29 02:37:25 -05:00
|
|
|
|
2021-01-21 10:57:21 -05:00
|
|
|
const hlsTranscodingPayload: HLSTranscodingPayload = {
|
|
|
|
type: 'new-resolution-to-hls',
|
2021-11-18 08:35:08 -05:00
|
|
|
autoDeleteWebTorrentIfNeeded: true,
|
2022-01-06 11:55:37 -05:00
|
|
|
|
2022-08-05 04:36:19 -04:00
|
|
|
...pick(payload, [ 'videoUUID', 'resolution', 'copyCodecs', 'isMaxQuality', 'isNewVideo', 'hasAudio' ])
|
2019-01-29 02:37:25 -05:00
|
|
|
}
|
2021-01-21 10:57:21 -05:00
|
|
|
|
2022-08-09 03:09:31 -04:00
|
|
|
await JobQueue.Instance.createJob(await buildTranscodingJob(hlsTranscodingPayload, jobOptions))
|
2021-02-22 04:33:33 -05:00
|
|
|
|
|
|
|
return true
|
2019-01-29 02:37:25 -05:00
|
|
|
}
|
2021-01-21 09:58:17 -05:00
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
async function createLowerResolutionsJobs (options: {
|
|
|
|
video: MVideoFullLight
|
|
|
|
user: MUserId
|
|
|
|
videoFileResolution: number
|
2022-01-06 11:55:37 -05:00
|
|
|
hasAudio: boolean
|
2021-08-17 02:26:20 -04:00
|
|
|
isNewVideo: boolean
|
2021-02-08 04:51:10 -05:00
|
|
|
type: 'hls' | 'webtorrent'
|
2021-08-17 02:26:20 -04:00
|
|
|
}) {
|
2022-08-05 04:36:19 -04:00
|
|
|
const { video, user, videoFileResolution, isNewVideo, hasAudio, type } = options
|
2021-08-17 02:26:20 -04:00
|
|
|
|
2021-01-21 09:58:17 -05:00
|
|
|
// Create transcoding jobs if there are enabled resolutions
|
2022-08-02 10:05:44 -04:00
|
|
|
const resolutionsEnabled = await Hooks.wrapObject(
|
2022-08-05 09:05:20 -04:00
|
|
|
computeResolutionsToTranscode({ input: videoFileResolution, type: 'vod', includeInput: false, strictLower: true }),
|
2022-08-05 07:40:56 -04:00
|
|
|
'filter:transcoding.auto.resolutions-to-transcode.result',
|
2022-08-02 10:05:44 -04:00
|
|
|
options
|
|
|
|
)
|
|
|
|
|
2021-08-26 03:18:57 -04:00
|
|
|
const resolutionCreated: string[] = []
|
2021-01-21 09:58:17 -05:00
|
|
|
|
|
|
|
for (const resolution of resolutionsEnabled) {
|
2022-01-06 11:55:37 -05:00
|
|
|
if (resolution === VideoResolution.H_NOVIDEO && hasAudio === false) continue
|
|
|
|
|
2021-01-21 09:58:17 -05:00
|
|
|
let dataInput: VideoTranscodingPayload
|
|
|
|
|
2021-02-08 04:51:10 -05:00
|
|
|
if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED && type === 'webtorrent') {
|
2021-01-21 09:58:17 -05:00
|
|
|
// WebTorrent will create subsequent HLS job
|
|
|
|
dataInput = {
|
|
|
|
type: 'new-resolution-to-webtorrent',
|
|
|
|
videoUUID: video.uuid,
|
|
|
|
resolution,
|
2022-01-06 11:55:37 -05:00
|
|
|
hasAudio,
|
2022-02-01 05:16:45 -05:00
|
|
|
createHLSIfNeeded: true,
|
2021-08-17 02:26:20 -04:00
|
|
|
isNewVideo
|
2021-01-21 09:58:17 -05:00
|
|
|
}
|
2021-08-26 03:18:57 -04:00
|
|
|
|
|
|
|
resolutionCreated.push('webtorrent-' + resolution)
|
2021-02-08 04:51:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CONFIG.TRANSCODING.HLS.ENABLED && type === 'hls') {
|
2021-01-21 09:58:17 -05:00
|
|
|
dataInput = {
|
|
|
|
type: 'new-resolution-to-hls',
|
|
|
|
videoUUID: video.uuid,
|
|
|
|
resolution,
|
2022-01-06 11:55:37 -05:00
|
|
|
hasAudio,
|
2021-02-08 04:51:10 -05:00
|
|
|
copyCodecs: false,
|
2021-08-17 02:26:20 -04:00
|
|
|
isMaxQuality: false,
|
2021-11-18 08:35:08 -05:00
|
|
|
autoDeleteWebTorrentIfNeeded: true,
|
2021-08-17 02:26:20 -04:00
|
|
|
isNewVideo
|
2021-01-21 09:58:17 -05:00
|
|
|
}
|
2021-08-26 03:18:57 -04:00
|
|
|
|
|
|
|
resolutionCreated.push('hls-' + resolution)
|
2021-01-21 09:58:17 -05:00
|
|
|
}
|
|
|
|
|
2021-02-22 04:33:33 -05:00
|
|
|
if (!dataInput) continue
|
|
|
|
|
2021-01-21 10:57:21 -05:00
|
|
|
const jobOptions = {
|
2021-05-05 03:25:11 -04:00
|
|
|
priority: await getTranscodingJobPriority(user)
|
2021-01-21 10:57:21 -05:00
|
|
|
}
|
|
|
|
|
2022-08-09 03:09:31 -04:00
|
|
|
await JobQueue.Instance.createJob(await buildTranscodingJob(dataInput, jobOptions))
|
2021-01-21 09:58:17 -05:00
|
|
|
}
|
|
|
|
|
2021-02-22 04:33:33 -05:00
|
|
|
if (resolutionCreated.length === 0) {
|
2021-08-26 03:18:57 -04:00
|
|
|
logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid, lTags(video.uuid))
|
2021-02-22 04:33:33 -05:00
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
'New resolutions %s transcoding jobs created for video %s and origin file resolution of %d.', type, video.uuid, videoFileResolution,
|
2021-08-26 03:18:57 -04:00
|
|
|
{ resolutionCreated, ...lTags(video.uuid) }
|
2021-02-22 04:33:33 -05:00
|
|
|
)
|
2021-01-21 09:58:17 -05:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|