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,
OptimizeTranscodingPayload,
+ VideoResolution,
VideoTranscodingPayload
} from '@shared/models'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
user,
videoFileResolution: payload.resolution,
isPortraitMode: payload.isPortraitMode,
+ hasAudio: payload.hasAudio,
isNewVideo: payload.isNewVideo ?? true,
type: 'hls'
})
transcodeType: TranscodeOptionsType,
user: MUserId
) {
- const { resolution, isPortraitMode } = await videoArg.getMaxQualityResolution()
+ const { resolution, isPortraitMode, audioStream } = await videoArg.getMaxQualityFileInfo()
// 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
user: MUserId,
payload: NewResolutionTranscodingPayload | MergeAudioTranscodingPayload
) {
- await createHlsJobIfEnabled(user, { ...payload, copyCodecs: true, isMaxQuality: false })
+ await createHlsJobIfEnabled(user, { hasAudio: true, copyCodecs: true, isMaxQuality: false, ...payload })
await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
await retryTransactionWrapper(moveToNextState, video, 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,
isNewVideo
}
videoUUID: video.uuid,
resolution,
isPortraitMode,
+ hasAudio,
copyCodecs: false,
isMaxQuality: false,
autoDeleteWebTorrentIfNeeded: true,
import { getServerActor } from '@server/models/application/application'
import { ModelCache } from '@server/models/model-cache'
import { buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils'
-import { uuidToShort } from '@shared/extra-utils'
+import { ffprobePromise, getAudioStream, uuidToShort } from '@shared/extra-utils'
import {
ResultList,
ThumbnailType,
return peertubeTruncate(this.description, { length: maxLength })
}
- getMaxQualityResolution () {
+ getMaxQualityFileInfo () {
const file = this.getMaxQualityFile()
const videoOrPlaylist = file.getVideoOrStreamingPlaylist()
- return VideoPathManager.Instance.makeAvailableVideoFile(file.withVideoOrPlaylist(videoOrPlaylist), originalFilePath => {
- return getVideoFileResolution(originalFilePath)
+ return VideoPathManager.Instance.makeAvailableVideoFile(file.withVideoOrPlaylist(videoOrPlaylist), async originalFilePath => {
+ const probe = await ffprobePromise(originalFilePath)
+
+ const { audioStream } = await getAudioStream(originalFilePath, probe)
+
+ return {
+ audioStream,
+
+ ...await getVideoFileResolution(originalFilePath, probe)
+ }
})
}