Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix audio transcoding with runner jobs

Chocobozzz763b822a587f
diff --git a/packages/tests/src/peertube-runner/vod-transcoding.ts b/packages/tests/src/peertube-runner/vod-transcoding.ts
index b0e5ac5356..14f45632a0 100644
--- a/packages/tests/src/peertube-runner/vod-transcoding.ts
+++ b/packages/tests/src/peertube-runner/vod-transcoding.ts
@@ -1,6 +1,11 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { getAllFiles, wait } from '@peertube/peertube-core-utils'
-import { VideoPrivacy, VideoResolution } from '@peertube/peertube-models'
+import {
+ RunnerJobVODHLSTranscodingPayload,
+ RunnerJobVODWebVideoTranscodingPayload,
+ VideoPrivacy,
+ VideoResolution
+} from '@peertube/peertube-models'
import { areMockObjectStorageTestsDisabled } from '@peertube/peertube-node-utils'
import {
cleanupTests,
@@ -279,6 +284,22 @@ describe('Test VOD transcoding in peertube-runner program', function () {
resolutions
})
})
+
+ it('Should use the appropriate input file URL', async function () {
+ const { data } = await servers[0].runnerJobs.list({ start: 0, count: 100 })
+
+ for (const job of data) {
+ if (job.type === 'vod-web-video-transcoding' || job.type === 'vod-hls-transcoding') {
+ const payload = job.payload as RunnerJobVODHLSTranscodingPayload | RunnerJobVODWebVideoTranscodingPayload
+
+ if (payload.output.resolution === 0) {
+ expect(payload.input.videoFileUrl).to.match(new RegExp(`/max-quality/audio$`))
+ } else {
+ expect(payload.input.videoFileUrl).to.match(new RegExp(`/max-quality$`))
+ }
+ }
+ }
+ })
}
before(async function () {
diff --git a/server/core/controllers/api/runners/jobs-files.ts b/server/core/controllers/api/runners/jobs-files.ts
index c849f762f8..804b8e265d 100644
--- a/server/core/controllers/api/runners/jobs-files.ts
+++ b/server/core/controllers/api/runners/jobs-files.ts
@@ -21,7 +21,7 @@ runnerJobFilesRouter.post(
apiRateLimiter,
asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
- asyncMiddleware(getMaxQualitySeparatedAudioFile)
+ asyncMiddleware(getMaxQualityAudioFile)
)
runnerJobFilesRouter.post(
@@ -57,7 +57,7 @@ export {
// ---------------------------------------------------------------------------
-async function getMaxQualitySeparatedAudioFile (req: express.Request, res: express.Response) {
+async function getMaxQualityAudioFile (req: express.Request, res: express.Response) {
const runnerJob = res.locals.runnerJob
const runner = runnerJob.Runner
const video = res.locals.videoAll
diff --git a/server/core/lib/runners/job-handlers/transcription-job-handler.ts b/server/core/lib/runners/job-handlers/transcription-job-handler.ts
index cba7b5d48a..79965e6cdd 100644
--- a/server/core/lib/runners/job-handlers/transcription-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/transcription-job-handler.ts
@@ -12,7 +12,7 @@ import { onTranscriptionEnded } from '@server/lib/video-captions.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { MVideoUUID } from '@server/types/models/index.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
-import { generateRunnerTranscodingAudioInputFileUrl } from '../runner-urls.js'
+import { generateRunnerTranscodingInputFileUrl } from '../runner-urls.js'
import { AbstractJobHandler } from './abstract-job-handler.js'
import { loadRunnerVideo } from './shared/utils.js'
@@ -58,7 +58,7 @@ export class TranscriptionJobHandler extends AbstractJobHandler<CreateOptions, R
const jobUUID = buildUUID()
const payload: RunnerJobTranscriptionPayload = {
input: {
- videoFileUrl: generateRunnerTranscodingAudioInputFileUrl(jobUUID, video.uuid)
+ videoFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' })
},
output: {}
}
diff --git a/server/core/lib/runners/job-handlers/video-storyboard-job-handler.ts b/server/core/lib/runners/job-handlers/video-storyboard-job-handler.ts
index b86656dc66..56d26151c6 100644
--- a/server/core/lib/runners/job-handlers/video-storyboard-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/video-storyboard-job-handler.ts
@@ -16,7 +16,7 @@ import { MRunnerJob } from '@server/types/models/runners/index.js'
import { move } from 'fs-extra/esm'
import { join } from 'path'
import { buildSpriteSize, buildTotalSprites, findGridSize, insertStoryboardInDatabase } from '../../storyboard.js'
-import { generateRunnerTranscodingVideoInputFileUrl } from '../runner-urls.js'
+import { generateRunnerTranscodingInputFileUrl } from '../runner-urls.js'
import { AbstractJobHandler } from './abstract-job-handler.js'
const lTagsBase = loggerTagsFactory('storyboard', 'runners')
@@ -48,7 +48,7 @@ export class VideoStoryboardJobHandler extends AbstractJobHandler<CreateOptions,
const payload: RunnerJobGenerateStoryboardPayload = {
input: {
- videoFileUrl: generateRunnerTranscodingVideoInputFileUrl(jobUUID, videoUUID)
+ videoFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID, type: 'video' })
},
sprites: {
size: { height: spriteHeight, width: spriteWidth },
diff --git a/server/core/lib/runners/job-handlers/video-studio-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/video-studio-transcoding-job-handler.ts
index 027fde2a2a..6682b2af98 100644
--- a/server/core/lib/runners/job-handlers/video-studio-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/video-studio-transcoding-job-handler.ts
@@ -13,18 +13,14 @@ import {
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
import { logger } from '@server/helpers/logger.js'
+import { sequelizeTypescript } from '@server/initializers/database.js'
import { onVideoStudioEnded, safeCleanupStudioTMPFiles } from '@server/lib/video-studio.js'
import { MVideoWithFile } from '@server/types/models/index.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
import { basename } from 'path'
-import {
- generateRunnerEditionTranscodingVideoInputFileUrl,
- generateRunnerTranscodingAudioInputFileUrl,
- generateRunnerTranscodingVideoInputFileUrl
-} from '../runner-urls.js'
+import { generateRunnerEditionTranscodingVideoInputFileUrl, generateRunnerTranscodingInputFileUrl } from '../runner-urls.js'
import { AbstractJobHandler } from './abstract-job-handler.js'
import { loadRunnerVideo } from './shared/utils.js'
-import { sequelizeTypescript } from '@server/initializers/database.js'
type CreateOptions = {
video: MVideoWithFile
@@ -44,10 +40,10 @@ export class VideoStudioTranscodingJobHandler
const payload: RunnerJobStudioTranscodingPayload = {
input: {
- videoFileUrl: generateRunnerTranscodingVideoInputFileUrl(jobUUID, video.uuid),
+ videoFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'video' }),
separatedAudioFileUrl: separatedAudioFile
- ? [ generateRunnerTranscodingAudioInputFileUrl(jobUUID, video.uuid) ]
+ ? [ generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }) ]
: []
},
output: {},
diff --git a/server/core/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts
index 095d9e72db..b2bab5b6e4 100644
--- a/server/core/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts
@@ -10,7 +10,7 @@ import { logger } from '@server/helpers/logger.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { MVideo } from '@server/types/models/index.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
-import { generateRunnerTranscodingVideoInputFileUrl, generateRunnerTranscodingVideoThumbnailFileUrl } from '../runner-urls.js'
+import { generateRunnerTranscodingInputFileUrl, generateRunnerTranscodingVideoThumbnailFileUrl } from '../runner-urls.js'
import { AbstractVODTranscodingJobHandler } from './abstract-vod-transcoding-job-handler.js'
import { loadRunnerVideo, onVODWebVideoOrAudioMergeTranscodingJob } from './shared/utils.js'
@@ -35,7 +35,7 @@ export class VODAudioMergeTranscodingJobHandler
const jobUUID = buildUUID()
const payload: RunnerJobVODAudioMergeTranscodingPayload = {
input: {
- audioFileUrl: generateRunnerTranscodingVideoInputFileUrl(jobUUID, video.uuid),
+ audioFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }),
previewFileUrl: generateRunnerTranscodingVideoThumbnailFileUrl(jobUUID, video.uuid)
},
output: {
diff --git a/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
index 8cebf992e0..312047d542 100644
--- a/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
@@ -16,7 +16,7 @@ import { removeAllWebVideoFiles } from '@server/lib/video-file.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { MVideoWithFile } from '@server/types/models/index.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
-import { generateRunnerTranscodingAudioInputFileUrl, generateRunnerTranscodingVideoInputFileUrl } from '../runner-urls.js'
+import { generateRunnerTranscodingInputFileUrl } from '../runner-urls.js'
import { AbstractVODTranscodingJobHandler } from './abstract-vod-transcoding-job-handler.js'
import { hasMissingHLSStreams, loadRunnerVideo } from './shared/utils.js'
@@ -49,10 +49,16 @@ export class VODHLSTranscodingJobHandler
const payload: RunnerJobVODHLSTranscodingPayload = {
input: {
- videoFileUrl: generateRunnerTranscodingVideoInputFileUrl(jobUUID, video.uuid),
+ videoFileUrl: generateRunnerTranscodingInputFileUrl({
+ jobUUID,
+ videoUUID: video.uuid,
+ type: resolution === VideoResolution.H_NOVIDEO
+ ? 'audio'
+ : 'video'
+ }),
separatedAudioFileUrl: separatedAudioFile
- ? [ generateRunnerTranscodingAudioInputFileUrl(jobUUID, video.uuid) ]
+ ? [ generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }) ]
: []
},
output: {
diff --git a/server/core/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts
index 881c31a065..bb3a545db4 100644
--- a/server/core/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts
@@ -3,6 +3,7 @@ import {
RunnerJobUpdatePayload,
RunnerJobVODWebVideoTranscodingPayload,
RunnerJobVODWebVideoTranscodingPrivatePayload,
+ VideoResolution,
VODWebVideoTranscodingSuccess
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
@@ -10,7 +11,7 @@ import { logger } from '@server/helpers/logger.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { MVideoWithFile } from '@server/types/models/index.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
-import { generateRunnerTranscodingAudioInputFileUrl, generateRunnerTranscodingVideoInputFileUrl } from '../runner-urls.js'
+import { generateRunnerTranscodingInputFileUrl } from '../runner-urls.js'
import { AbstractVODTranscodingJobHandler } from './abstract-vod-transcoding-job-handler.js'
import { loadRunnerVideo, onVODWebVideoOrAudioMergeTranscodingJob } from './shared/utils.js'
@@ -37,10 +38,16 @@ export class VODWebVideoTranscodingJobHandler
const payload: RunnerJobVODWebVideoTranscodingPayload = {
input: {
- videoFileUrl: generateRunnerTranscodingVideoInputFileUrl(jobUUID, video.uuid),
+ videoFileUrl: generateRunnerTranscodingInputFileUrl({
+ jobUUID,
+ videoUUID: video.uuid,
+ type: resolution === VideoResolution.H_NOVIDEO
+ ? 'audio'
+ : 'video'
+ }),
separatedAudioFileUrl: separatedAudioFile
- ? [ generateRunnerTranscodingAudioInputFileUrl(jobUUID, video.uuid) ]
+ ? [ generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }) ]
: []
},
output: {
diff --git a/server/core/lib/runners/runner-urls.ts b/server/core/lib/runners/runner-urls.ts
index 695488277a..ce6643b3ec 100644
--- a/server/core/lib/runners/runner-urls.ts
+++ b/server/core/lib/runners/runner-urls.ts
@@ -1,13 +1,22 @@
import { WEBSERVER } from '@server/initializers/constants.js'
-export function generateRunnerTranscodingVideoInputFileUrl (jobUUID: string, videoUUID: string) {
- return WEBSERVER.URL + '/api/v1/runners/jobs/' + jobUUID + '/files/videos/' + videoUUID + '/max-quality'
-}
+export function generateRunnerTranscodingInputFileUrl (options: {
+ jobUUID: string
+ videoUUID: string
+ type: 'video' | 'audio'
+}) {
+ const { jobUUID, videoUUID, type } = options
+
+ if (type === 'video') {
+ return WEBSERVER.URL + '/api/v1/runners/jobs/' + jobUUID + '/files/videos/' + videoUUID + '/max-quality'
+ }
-export function generateRunnerTranscodingAudioInputFileUrl (jobUUID: string, videoUUID: string) {
+ // Audio
return WEBSERVER.URL + '/api/v1/runners/jobs/' + jobUUID + '/files/videos/' + videoUUID + '/max-quality/audio'
}
+// ---------------------------------------------------------------------------
+
export function generateRunnerTranscodingVideoThumbnailFileUrl (jobUUID: string, videoUUID: string) {
return WEBSERVER.URL + '/api/v1/runners/jobs/' + jobUUID + '/files/videos/' + videoUUID + '/thumbnails/max-quality'
}
diff --git a/server/core/lib/video-state.ts b/server/core/lib/video-state.ts
index edc4238043..302ba5e2ca 100644
--- a/server/core/lib/video-state.ts
+++ b/server/core/lib/video-state.ts
@@ -74,6 +74,11 @@ export function moveToNextState (options: {
return true
}
+ // Keep video in failed transcoding state
+ if (videoDatabase.state === VideoState.TRANSCODING_FAILED) {
+ return true
+ }
+
throw new Error('Unknown next state for video ' + videoDatabase.uuid + ': ' + newState)
})
})