import { Job } from 'bull'
-import { TranscodeOptionsType } from '@server/helpers/ffmpeg-utils'
+import { TranscodeVODOptionsType } from '@server/helpers/ffmpeg'
import { addTranscodingJob, getTranscodingJobPriority } from '@server/lib/video'
import { VideoPathManager } from '@server/lib/video-path-manager'
import { moveToFailedTranscodingState, moveToNextState } from '@server/lib/video-state'
import { UserModel } from '@server/models/user/user'
import { VideoJobInfoModel } from '@server/models/video/video-job-info'
import { MUser, MUserId, MVideo, MVideoFullLight, MVideoWithFile } from '@server/types/models'
+import { pick } from '@shared/core-utils'
import {
HLSTranscodingPayload,
MergeAudioTranscodingPayload,
- NewResolutionTranscodingPayload,
+ NewWebTorrentResolutionTranscodingPayload,
OptimizeTranscodingPayload,
+ VideoResolution,
VideoTranscodingPayload
} from '@shared/models'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
-import { computeLowerResolutionsToTranscode } from '../../../helpers/ffprobe-utils'
+import { computeLowerResolutionsToTranscode } from '../../../helpers/ffmpeg'
import { logger, loggerTagsFactory } from '../../../helpers/logger'
import { CONFIG } from '../../../initializers/config'
import { VideoModel } from '../../../models/video/video'
mergeAudioVideofile,
optimizeOriginalVideofile,
transcodeNewWebTorrentResolution
-} from '../../transcoding/video-transcoding'
+} from '../../transcoding/transcoding'
type HandlerFunction = (job: Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<void>
async function handleNewWebTorrentResolutionJob (
job: Job,
- payload: NewResolutionTranscodingPayload,
+ payload: NewWebTorrentResolutionTranscodingPayload,
video: MVideoFullLight,
user: MUserId
) {
user,
videoFileResolution: payload.resolution,
isPortraitMode: payload.isPortraitMode,
+ hasAudio: payload.hasAudio,
isNewVideo: payload.isNewVideo ?? true,
type: 'hls'
})
}
await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
- await retryTransactionWrapper(moveToNextState, video, payload.isNewVideo)
+ await retryTransactionWrapper(moveToNextState, { video, isNewVideo: payload.isNewVideo })
}
async function onVideoFirstWebTorrentTranscoding (
videoArg: MVideoWithFile,
payload: OptimizeTranscodingPayload | MergeAudioTranscodingPayload,
- transcodeType: TranscodeOptionsType,
+ transcodeType: TranscodeVODOptionsType,
user: MUserId
) {
- const { resolution, isPortraitMode } = await videoArg.getMaxQualityResolution()
+ const { resolution, isPortraitMode, audioStream } = await videoArg.probeMaxQualityFile()
// Maybe the video changed in database, refresh it
const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid)
...payload,
isPortraitMode,
+ hasAudio: !!audioStream,
resolution: videoDatabase.getMaxQualityFile().resolution,
// If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues
copyCodecs: transcodeType !== 'quick-transcode',
video: videoDatabase,
user,
videoFileResolution: resolution,
+ hasAudio: !!audioStream,
isPortraitMode,
type: 'webtorrent',
isNewVideo: payload.isNewVideo ?? true
// Move to next state if there are no other resolutions to generate
if (!hasHls && !hasNewResolutions) {
- await retryTransactionWrapper(moveToNextState, videoDatabase, payload.isNewVideo)
+ await retryTransactionWrapper(moveToNextState, { video: videoDatabase, isNewVideo: payload.isNewVideo })
}
}
async function onNewWebTorrentFileResolution (
video: MVideo,
user: MUserId,
- payload: NewResolutionTranscodingPayload | MergeAudioTranscodingPayload
+ payload: NewWebTorrentResolutionTranscodingPayload | MergeAudioTranscodingPayload
) {
- await createHlsJobIfEnabled(user, { ...payload, copyCodecs: true, isMaxQuality: false })
+ if (payload.createHLSIfNeeded) {
+ await createHlsJobIfEnabled(user, { hasAudio: true, copyCodecs: true, isMaxQuality: false, ...payload })
+ }
+
await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
- await retryTransactionWrapper(moveToNextState, video, payload.isNewVideo)
+ await retryTransactionWrapper(moveToNextState, { video, isNewVideo: payload.isNewVideo })
}
// ---------------------------------------------------------------------------
async function createHlsJobIfEnabled (user: MUserId, payload: {
videoUUID: string
resolution: number
+ hasAudio: boolean
isPortraitMode?: boolean
copyCodecs: boolean
isMaxQuality: boolean
const hlsTranscodingPayload: HLSTranscodingPayload = {
type: 'new-resolution-to-hls',
- videoUUID: payload.videoUUID,
- resolution: payload.resolution,
- isPortraitMode: payload.isPortraitMode,
- copyCodecs: payload.copyCodecs,
- isMaxQuality: payload.isMaxQuality,
autoDeleteWebTorrentIfNeeded: true,
- isNewVideo: payload.isNewVideo
+
+ ...pick(payload, [ 'videoUUID', 'resolution', 'isPortraitMode', 'copyCodecs', 'isMaxQuality', 'isNewVideo', 'hasAudio' ])
}
await addTranscodingJob(hlsTranscodingPayload, jobOptions)
user: MUserId
videoFileResolution: number
isPortraitMode: boolean
+ hasAudio: boolean
isNewVideo: boolean
type: 'hls' | 'webtorrent'
}) {
- const { video, user, videoFileResolution, isPortraitMode, isNewVideo, type } = options
+ const { video, user, videoFileResolution, isPortraitMode, isNewVideo, hasAudio, type } = options
// Create transcoding jobs if there are enabled resolutions
const resolutionsEnabled = computeLowerResolutionsToTranscode(videoFileResolution, 'vod')
const resolutionCreated: string[] = []
for (const resolution of resolutionsEnabled) {
+ if (resolution === VideoResolution.H_NOVIDEO && hasAudio === false) continue
+
let dataInput: VideoTranscodingPayload
if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED && type === 'webtorrent') {
videoUUID: video.uuid,
resolution,
isPortraitMode,
+ hasAudio,
+ createHLSIfNeeded: true,
isNewVideo
}
videoUUID: video.uuid,
resolution,
isPortraitMode,
+ hasAudio,
copyCodecs: false,
isMaxQuality: false,
autoDeleteWebTorrentIfNeeded: true,