Fix audio transcoding with video only file

This commit is contained in:
Chocobozzz 2022-01-06 17:55:37 +01:00
parent 78a5dd9c69
commit cbe2f36d93
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 46 additions and 16 deletions

View File

@ -60,7 +60,11 @@ async function run () {
type: 'new-resolution-to-hls', type: 'new-resolution-to-hls',
videoUUID: video.uuid, videoUUID: video.uuid,
resolution, resolution,
// FIXME: check the file has audio and is not in portrait mode
isPortraitMode: false, isPortraitMode: false,
hasAudio: true,
copyCodecs: false, copyCodecs: false,
isNewVideo: false, isNewVideo: false,
isMaxQuality: maxResolution === resolution, isMaxQuality: maxResolution === resolution,
@ -72,6 +76,10 @@ async function run () {
dataInput.push({ dataInput.push({
type: 'new-resolution-to-webtorrent', type: 'new-resolution-to-webtorrent',
videoUUID: video.uuid, videoUUID: video.uuid,
// FIXME: check the file has audio
hasAudio: true,
isNewVideo: false, isNewVideo: false,
resolution: parseInt(options.resolution) resolution: parseInt(options.resolution)
}) })

View File

@ -29,7 +29,7 @@ async function createTranscoding (req: express.Request, res: express.Response) {
const body: VideoTranscodingCreate = req.body const body: VideoTranscodingCreate = req.body
const { resolution: maxResolution, isPortraitMode } = await video.getMaxQualityResolution() const { resolution: maxResolution, isPortraitMode, audioStream } = await video.getMaxQualityFileInfo()
const resolutions = computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ]) const resolutions = computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ])
video.state = VideoState.TO_TRANSCODE video.state = VideoState.TO_TRANSCODE
@ -42,6 +42,7 @@ async function createTranscoding (req: express.Request, res: express.Response) {
videoUUID: video.uuid, videoUUID: video.uuid,
resolution, resolution,
isPortraitMode, isPortraitMode,
hasAudio: !!audioStream,
copyCodecs: false, copyCodecs: false,
isNewVideo: false, isNewVideo: false,
autoDeleteWebTorrentIfNeeded: false, autoDeleteWebTorrentIfNeeded: false,
@ -53,6 +54,7 @@ async function createTranscoding (req: express.Request, res: express.Response) {
videoUUID: video.uuid, videoUUID: video.uuid,
isNewVideo: false, isNewVideo: false,
resolution: resolution, resolution: resolution,
hasAudio: !!audioStream,
isPortraitMode isPortraitMode
}) })
} }

View File

@ -6,11 +6,13 @@ import { moveToFailedTranscodingState, moveToNextState } from '@server/lib/video
import { UserModel } from '@server/models/user/user' import { UserModel } from '@server/models/user/user'
import { VideoJobInfoModel } from '@server/models/video/video-job-info' import { VideoJobInfoModel } from '@server/models/video/video-job-info'
import { MUser, MUserId, MVideo, MVideoFullLight, MVideoWithFile } from '@server/types/models' import { MUser, MUserId, MVideo, MVideoFullLight, MVideoWithFile } from '@server/types/models'
import { pick } from '@shared/core-utils'
import { import {
HLSTranscodingPayload, HLSTranscodingPayload,
MergeAudioTranscodingPayload, MergeAudioTranscodingPayload,
NewResolutionTranscodingPayload, NewResolutionTranscodingPayload,
OptimizeTranscodingPayload, OptimizeTranscodingPayload,
VideoResolution,
VideoTranscodingPayload VideoTranscodingPayload
} from '@shared/models' } from '@shared/models'
import { retryTransactionWrapper } from '../../../helpers/database-utils' import { retryTransactionWrapper } from '../../../helpers/database-utils'
@ -159,6 +161,7 @@ async function onHlsPlaylistGeneration (video: MVideoFullLight, user: MUser, pay
user, user,
videoFileResolution: payload.resolution, videoFileResolution: payload.resolution,
isPortraitMode: payload.isPortraitMode, isPortraitMode: payload.isPortraitMode,
hasAudio: payload.hasAudio,
isNewVideo: payload.isNewVideo ?? true, isNewVideo: payload.isNewVideo ?? true,
type: 'hls' type: 'hls'
}) })
@ -174,7 +177,7 @@ async function onVideoFirstWebTorrentTranscoding (
transcodeType: TranscodeOptionsType, transcodeType: TranscodeOptionsType,
user: MUserId user: MUserId
) { ) {
const { resolution, isPortraitMode } = await videoArg.getMaxQualityResolution() const { resolution, isPortraitMode, audioStream } = await videoArg.getMaxQualityFileInfo()
// Maybe the video changed in database, refresh it // Maybe the video changed in database, refresh it
const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid) const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid)
@ -186,6 +189,7 @@ async function onVideoFirstWebTorrentTranscoding (
...payload, ...payload,
isPortraitMode, isPortraitMode,
hasAudio: !!audioStream,
resolution: videoDatabase.getMaxQualityFile().resolution, resolution: videoDatabase.getMaxQualityFile().resolution,
// If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues // If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues
copyCodecs: transcodeType !== 'quick-transcode', copyCodecs: transcodeType !== 'quick-transcode',
@ -196,6 +200,7 @@ async function onVideoFirstWebTorrentTranscoding (
video: videoDatabase, video: videoDatabase,
user, user,
videoFileResolution: resolution, videoFileResolution: resolution,
hasAudio: !!audioStream,
isPortraitMode, isPortraitMode,
type: 'webtorrent', type: 'webtorrent',
isNewVideo: payload.isNewVideo ?? true isNewVideo: payload.isNewVideo ?? true
@ -214,7 +219,7 @@ async function onNewWebTorrentFileResolution (
user: MUserId, user: MUserId,
payload: NewResolutionTranscodingPayload | MergeAudioTranscodingPayload 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 VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
await retryTransactionWrapper(moveToNextState, video, payload.isNewVideo) await retryTransactionWrapper(moveToNextState, video, payload.isNewVideo)
@ -225,6 +230,7 @@ async function onNewWebTorrentFileResolution (
async function createHlsJobIfEnabled (user: MUserId, payload: { async function createHlsJobIfEnabled (user: MUserId, payload: {
videoUUID: string videoUUID: string
resolution: number resolution: number
hasAudio: boolean
isPortraitMode?: boolean isPortraitMode?: boolean
copyCodecs: boolean copyCodecs: boolean
isMaxQuality: boolean isMaxQuality: boolean
@ -238,13 +244,9 @@ async function createHlsJobIfEnabled (user: MUserId, payload: {
const hlsTranscodingPayload: HLSTranscodingPayload = { const hlsTranscodingPayload: HLSTranscodingPayload = {
type: 'new-resolution-to-hls', type: 'new-resolution-to-hls',
videoUUID: payload.videoUUID,
resolution: payload.resolution,
isPortraitMode: payload.isPortraitMode,
copyCodecs: payload.copyCodecs,
isMaxQuality: payload.isMaxQuality,
autoDeleteWebTorrentIfNeeded: true, autoDeleteWebTorrentIfNeeded: true,
isNewVideo: payload.isNewVideo
...pick(payload, [ 'videoUUID', 'resolution', 'isPortraitMode', 'copyCodecs', 'isMaxQuality', 'isNewVideo', 'hasAudio' ])
} }
await addTranscodingJob(hlsTranscodingPayload, jobOptions) await addTranscodingJob(hlsTranscodingPayload, jobOptions)
@ -257,16 +259,19 @@ async function createLowerResolutionsJobs (options: {
user: MUserId user: MUserId
videoFileResolution: number videoFileResolution: number
isPortraitMode: boolean isPortraitMode: boolean
hasAudio: boolean
isNewVideo: boolean isNewVideo: boolean
type: 'hls' | 'webtorrent' 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 // Create transcoding jobs if there are enabled resolutions
const resolutionsEnabled = computeLowerResolutionsToTranscode(videoFileResolution, 'vod') const resolutionsEnabled = computeLowerResolutionsToTranscode(videoFileResolution, 'vod')
const resolutionCreated: string[] = [] const resolutionCreated: string[] = []
for (const resolution of resolutionsEnabled) { for (const resolution of resolutionsEnabled) {
if (resolution === VideoResolution.H_NOVIDEO && hasAudio === false) continue
let dataInput: VideoTranscodingPayload let dataInput: VideoTranscodingPayload
if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED && type === 'webtorrent') { if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED && type === 'webtorrent') {
@ -276,6 +281,7 @@ async function createLowerResolutionsJobs (options: {
videoUUID: video.uuid, videoUUID: video.uuid,
resolution, resolution,
isPortraitMode, isPortraitMode,
hasAudio,
isNewVideo isNewVideo
} }
@ -288,6 +294,7 @@ async function createLowerResolutionsJobs (options: {
videoUUID: video.uuid, videoUUID: video.uuid,
resolution, resolution,
isPortraitMode, isPortraitMode,
hasAudio,
copyCodecs: false, copyCodecs: false,
isMaxQuality: false, isMaxQuality: false,
autoDeleteWebTorrentIfNeeded: true, autoDeleteWebTorrentIfNeeded: true,

View File

@ -33,7 +33,7 @@ import { VideoPathManager } from '@server/lib/video-path-manager'
import { getServerActor } from '@server/models/application/application' import { getServerActor } from '@server/models/application/application'
import { ModelCache } from '@server/models/model-cache' import { ModelCache } from '@server/models/model-cache'
import { buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils' import { buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils'
import { uuidToShort } from '@shared/extra-utils' import { ffprobePromise, getAudioStream, uuidToShort } from '@shared/extra-utils'
import { import {
ResultList, ResultList,
ThumbnailType, ThumbnailType,
@ -1678,12 +1678,20 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
return peertubeTruncate(this.description, { length: maxLength }) return peertubeTruncate(this.description, { length: maxLength })
} }
getMaxQualityResolution () { getMaxQualityFileInfo () {
const file = this.getMaxQualityFile() const file = this.getMaxQualityFile()
const videoOrPlaylist = file.getVideoOrStreamingPlaylist() const videoOrPlaylist = file.getVideoOrStreamingPlaylist()
return VideoPathManager.Instance.makeAvailableVideoFile(file.withVideoOrPlaylist(videoOrPlaylist), originalFilePath => { return VideoPathManager.Instance.makeAvailableVideoFile(file.withVideoOrPlaylist(videoOrPlaylist), async originalFilePath => {
return getVideoFileResolution(originalFilePath) const probe = await ffprobePromise(originalFilePath)
const { audioStream } = await getAudioStream(originalFilePath, probe)
return {
audioStream,
...await getVideoFileResolution(originalFilePath, probe)
}
}) })
} }

View File

@ -103,18 +103,23 @@ interface BaseTranscodingPayload {
export interface HLSTranscodingPayload extends BaseTranscodingPayload { export interface HLSTranscodingPayload extends BaseTranscodingPayload {
type: 'new-resolution-to-hls' type: 'new-resolution-to-hls'
isPortraitMode?: boolean
resolution: VideoResolution resolution: VideoResolution
copyCodecs: boolean copyCodecs: boolean
hasAudio: boolean
isPortraitMode?: boolean
autoDeleteWebTorrentIfNeeded: boolean autoDeleteWebTorrentIfNeeded: boolean
isMaxQuality: boolean isMaxQuality: boolean
} }
export interface NewResolutionTranscodingPayload extends BaseTranscodingPayload { export interface NewResolutionTranscodingPayload extends BaseTranscodingPayload {
type: 'new-resolution-to-webtorrent' type: 'new-resolution-to-webtorrent'
isPortraitMode?: boolean
resolution: VideoResolution resolution: VideoResolution
hasAudio: boolean
isPortraitMode?: boolean
} }
export interface MergeAudioTranscodingPayload extends BaseTranscodingPayload { export interface MergeAudioTranscodingPayload extends BaseTranscodingPayload {