Add plugin hook on transcoding resolutions building
This commit is contained in:
parent
22df69fdec
commit
ebb9e53ada
|
@ -4,6 +4,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
||||||
import { addTranscodingJob } from '@server/lib/video'
|
import { addTranscodingJob } from '@server/lib/video'
|
||||||
import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models'
|
import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models'
|
||||||
import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares'
|
import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares'
|
||||||
|
import { Hooks } from '@server/lib/plugins/hooks'
|
||||||
|
|
||||||
const lTags = loggerTagsFactory('api', 'video')
|
const lTags = loggerTagsFactory('api', 'video')
|
||||||
const transcodingRouter = express.Router()
|
const transcodingRouter = express.Router()
|
||||||
|
@ -30,7 +31,15 @@ async function createTranscoding (req: express.Request, res: express.Response) {
|
||||||
const body: VideoTranscodingCreate = req.body
|
const body: VideoTranscodingCreate = req.body
|
||||||
|
|
||||||
const { resolution: maxResolution, isPortraitMode, audioStream } = await video.probeMaxQualityFile()
|
const { resolution: maxResolution, isPortraitMode, audioStream } = await video.probeMaxQualityFile()
|
||||||
const resolutions = computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ])
|
const resolutions = await Hooks.wrapObject(
|
||||||
|
computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ]),
|
||||||
|
'filter:transcoding.manual.lower-resolutions-to-transcode.result',
|
||||||
|
body
|
||||||
|
)
|
||||||
|
|
||||||
|
if (resolutions.length === 0) {
|
||||||
|
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||||
|
}
|
||||||
|
|
||||||
video.state = VideoState.TO_TRANSCODE
|
video.state = VideoState.TO_TRANSCODE
|
||||||
await video.save()
|
await video.save()
|
||||||
|
|
|
@ -26,6 +26,7 @@ import {
|
||||||
optimizeOriginalVideofile,
|
optimizeOriginalVideofile,
|
||||||
transcodeNewWebTorrentResolution
|
transcodeNewWebTorrentResolution
|
||||||
} from '../../transcoding/transcoding'
|
} from '../../transcoding/transcoding'
|
||||||
|
import { Hooks } from '@server/lib/plugins/hooks'
|
||||||
|
|
||||||
type HandlerFunction = (job: Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<void>
|
type HandlerFunction = (job: Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<void>
|
||||||
|
|
||||||
|
@ -269,7 +270,12 @@ async function createLowerResolutionsJobs (options: {
|
||||||
const { video, user, videoFileResolution, isPortraitMode, isNewVideo, hasAudio, 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 = await Hooks.wrapObject(
|
||||||
|
computeLowerResolutionsToTranscode(videoFileResolution, 'vod'),
|
||||||
|
'filter:transcoding.auto.lower-resolutions-to-transcode.result',
|
||||||
|
options
|
||||||
|
)
|
||||||
|
|
||||||
const resolutionCreated: string[] = []
|
const resolutionCreated: string[] = []
|
||||||
|
|
||||||
for (const resolution of resolutionsEnabled) {
|
for (const resolution of resolutionsEnabled) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import { PeerTubeSocket } from '../peertube-socket'
|
||||||
import { LiveQuotaStore } from './live-quota-store'
|
import { LiveQuotaStore } from './live-quota-store'
|
||||||
import { cleanupPermanentLive } from './live-utils'
|
import { cleanupPermanentLive } from './live-utils'
|
||||||
import { MuxingSession } from './shared'
|
import { MuxingSession } from './shared'
|
||||||
|
import { Hooks } from '../plugins/hooks'
|
||||||
|
|
||||||
const NodeRtmpSession = require('node-media-server/src/node_rtmp_session')
|
const NodeRtmpSession = require('node-media-server/src/node_rtmp_session')
|
||||||
const context = require('node-media-server/src/node_core_ctx')
|
const context = require('node-media-server/src/node_core_ctx')
|
||||||
|
@ -242,7 +243,11 @@ class LiveManager {
|
||||||
inputUrl, Date.now() - now, bitrate, fps, resolution, lTags(sessionId, video.uuid)
|
inputUrl, Date.now() - now, bitrate, fps, resolution, lTags(sessionId, video.uuid)
|
||||||
)
|
)
|
||||||
|
|
||||||
const allResolutions = this.buildAllResolutionsToTranscode(resolution)
|
const allResolutions = await Hooks.wrapObject(
|
||||||
|
this.buildAllResolutionsToTranscode(resolution),
|
||||||
|
'filter:transcoding.auto.lower-resolutions-to-transcode.result',
|
||||||
|
{ video }
|
||||||
|
)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
'Will mux/transcode live video of original resolution %d.', resolution,
|
'Will mux/transcode live video of original resolution %d.', resolution,
|
||||||
|
|
|
@ -256,8 +256,6 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
|
||||||
registerHook({
|
registerHook({
|
||||||
target: 'filter:job-queue.process.params',
|
target: 'filter:job-queue.process.params',
|
||||||
handler: (object, context) => {
|
handler: (object, context) => {
|
||||||
peertubeHelpers.logger.debug('TOTO.', { object, context })
|
|
||||||
|
|
||||||
if (context.type !== 'video-studio-edition') return object
|
if (context.type !== 'video-studio-edition') return object
|
||||||
|
|
||||||
object.data.tasks = [
|
object.data.tasks = [
|
||||||
|
@ -274,6 +272,17 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
registerHook({
|
||||||
|
target: 'filter:transcoding.auto.lower-resolutions-to-transcode.result',
|
||||||
|
handler: (object, context) => {
|
||||||
|
if (context.video.name.includes('transcode-filter')) {
|
||||||
|
object = [ 100 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
return object
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Upload/import/live attributes
|
// Upload/import/live attributes
|
||||||
for (const target of [
|
for (const target of [
|
||||||
'filter:api.video.upload.video-attribute.result',
|
'filter:api.video.upload.video-attribute.result',
|
||||||
|
|
|
@ -677,6 +677,19 @@ describe('Test plugin filter hooks', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('Transcoding filters', async function () {
|
||||||
|
|
||||||
|
it('Should run filter:transcoding.auto.lower-resolutions-to-transcode.result', async function () {
|
||||||
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'transcode-filter' })
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
const video = await servers[0].videos.get({ id: uuid })
|
||||||
|
expect(video.files).to.have.lengthOf(2)
|
||||||
|
expect(video.files.find(f => f.resolution.id === 100 as any)).to.exist
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
after(async function () {
|
after(async function () {
|
||||||
await cleanupTests(servers)
|
await cleanupTests(servers)
|
||||||
})
|
})
|
||||||
|
|
|
@ -93,7 +93,10 @@ export const serverFilterHookObject = {
|
||||||
'filter:html.embed.video-playlist.allowed.result': true,
|
'filter:html.embed.video-playlist.allowed.result': true,
|
||||||
|
|
||||||
'filter:job-queue.process.params': true,
|
'filter:job-queue.process.params': true,
|
||||||
'filter:job-queue.process.result': true
|
'filter:job-queue.process.result': true,
|
||||||
|
|
||||||
|
'filter:transcoding.manual.lower-resolutions-to-transcode.result': true,
|
||||||
|
'filter:transcoding.auto.lower-resolutions-to-transcode.result': true
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ServerFilterHookName = keyof typeof serverFilterHookObject
|
export type ServerFilterHookName = keyof typeof serverFilterHookObject
|
||||||
|
|
Loading…
Reference in New Issue