diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/transcoding.ts | 11 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-transcoding.ts | 8 | ||||
-rw-r--r-- | server/lib/live/live-manager.ts | 7 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test/main.js | 13 | ||||
-rw-r--r-- | server/tests/plugins/filter-hooks.ts | 13 |
5 files changed, 47 insertions, 5 deletions
diff --git a/server/controllers/api/videos/transcoding.ts b/server/controllers/api/videos/transcoding.ts index da3ea3c9c..a360a8b6a 100644 --- a/server/controllers/api/videos/transcoding.ts +++ b/server/controllers/api/videos/transcoding.ts | |||
@@ -4,6 +4,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger' | |||
4 | import { addTranscodingJob } from '@server/lib/video' | 4 | import { addTranscodingJob } from '@server/lib/video' |
5 | import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models' | 5 | import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models' |
6 | import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares' | 6 | import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares' |
7 | import { Hooks } from '@server/lib/plugins/hooks' | ||
7 | 8 | ||
8 | const lTags = loggerTagsFactory('api', 'video') | 9 | const lTags = loggerTagsFactory('api', 'video') |
9 | const transcodingRouter = express.Router() | 10 | const transcodingRouter = express.Router() |
@@ -30,7 +31,15 @@ async function createTranscoding (req: express.Request, res: express.Response) { | |||
30 | const body: VideoTranscodingCreate = req.body | 31 | const body: VideoTranscodingCreate = req.body |
31 | 32 | ||
32 | const { resolution: maxResolution, isPortraitMode, audioStream } = await video.probeMaxQualityFile() | 33 | const { resolution: maxResolution, isPortraitMode, audioStream } = await video.probeMaxQualityFile() |
33 | const resolutions = computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ]) | 34 | const resolutions = await Hooks.wrapObject( |
35 | computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ]), | ||
36 | 'filter:transcoding.manual.lower-resolutions-to-transcode.result', | ||
37 | body | ||
38 | ) | ||
39 | |||
40 | if (resolutions.length === 0) { | ||
41 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
42 | } | ||
34 | 43 | ||
35 | video.state = VideoState.TO_TRANSCODE | 44 | video.state = VideoState.TO_TRANSCODE |
36 | await video.save() | 45 | await video.save() |
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index 1b34ced14..d3fb7778b 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts | |||
@@ -26,6 +26,7 @@ import { | |||
26 | optimizeOriginalVideofile, | 26 | optimizeOriginalVideofile, |
27 | transcodeNewWebTorrentResolution | 27 | transcodeNewWebTorrentResolution |
28 | } from '../../transcoding/transcoding' | 28 | } from '../../transcoding/transcoding' |
29 | import { Hooks } from '@server/lib/plugins/hooks' | ||
29 | 30 | ||
30 | type HandlerFunction = (job: Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<void> | 31 | type HandlerFunction = (job: Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<void> |
31 | 32 | ||
@@ -269,7 +270,12 @@ async function createLowerResolutionsJobs (options: { | |||
269 | const { video, user, videoFileResolution, isPortraitMode, isNewVideo, hasAudio, type } = options | 270 | const { video, user, videoFileResolution, isPortraitMode, isNewVideo, hasAudio, type } = options |
270 | 271 | ||
271 | // Create transcoding jobs if there are enabled resolutions | 272 | // Create transcoding jobs if there are enabled resolutions |
272 | const resolutionsEnabled = computeLowerResolutionsToTranscode(videoFileResolution, 'vod') | 273 | const resolutionsEnabled = await Hooks.wrapObject( |
274 | computeLowerResolutionsToTranscode(videoFileResolution, 'vod'), | ||
275 | 'filter:transcoding.auto.lower-resolutions-to-transcode.result', | ||
276 | options | ||
277 | ) | ||
278 | |||
273 | const resolutionCreated: string[] = [] | 279 | const resolutionCreated: string[] = [] |
274 | 280 | ||
275 | for (const resolution of resolutionsEnabled) { | 281 | for (const resolution of resolutionsEnabled) { |
diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index 41f89a2a4..bd47b01f9 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts | |||
@@ -29,6 +29,7 @@ import { PeerTubeSocket } from '../peertube-socket' | |||
29 | import { LiveQuotaStore } from './live-quota-store' | 29 | import { LiveQuotaStore } from './live-quota-store' |
30 | import { cleanupPermanentLive } from './live-utils' | 30 | import { cleanupPermanentLive } from './live-utils' |
31 | import { MuxingSession } from './shared' | 31 | import { MuxingSession } from './shared' |
32 | import { Hooks } from '../plugins/hooks' | ||
32 | 33 | ||
33 | const NodeRtmpSession = require('node-media-server/src/node_rtmp_session') | 34 | const NodeRtmpSession = require('node-media-server/src/node_rtmp_session') |
34 | const context = require('node-media-server/src/node_core_ctx') | 35 | const context = require('node-media-server/src/node_core_ctx') |
@@ -242,7 +243,11 @@ class LiveManager { | |||
242 | inputUrl, Date.now() - now, bitrate, fps, resolution, lTags(sessionId, video.uuid) | 243 | inputUrl, Date.now() - now, bitrate, fps, resolution, lTags(sessionId, video.uuid) |
243 | ) | 244 | ) |
244 | 245 | ||
245 | const allResolutions = this.buildAllResolutionsToTranscode(resolution) | 246 | const allResolutions = await Hooks.wrapObject( |
247 | this.buildAllResolutionsToTranscode(resolution), | ||
248 | 'filter:transcoding.auto.lower-resolutions-to-transcode.result', | ||
249 | { video } | ||
250 | ) | ||
246 | 251 | ||
247 | logger.info( | 252 | logger.info( |
248 | 'Will mux/transcode live video of original resolution %d.', resolution, | 253 | 'Will mux/transcode live video of original resolution %d.', resolution, |
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index f62f6a435..c395ac7aa 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js | |||
@@ -256,8 +256,6 @@ async function register ({ registerHook, registerSetting, settingsManager, stora | |||
256 | registerHook({ | 256 | registerHook({ |
257 | target: 'filter:job-queue.process.params', | 257 | target: 'filter:job-queue.process.params', |
258 | handler: (object, context) => { | 258 | handler: (object, context) => { |
259 | peertubeHelpers.logger.debug('TOTO.', { object, context }) | ||
260 | |||
261 | if (context.type !== 'video-studio-edition') return object | 259 | if (context.type !== 'video-studio-edition') return object |
262 | 260 | ||
263 | object.data.tasks = [ | 261 | object.data.tasks = [ |
@@ -274,6 +272,17 @@ async function register ({ registerHook, registerSetting, settingsManager, stora | |||
274 | } | 272 | } |
275 | }) | 273 | }) |
276 | 274 | ||
275 | registerHook({ | ||
276 | target: 'filter:transcoding.auto.lower-resolutions-to-transcode.result', | ||
277 | handler: (object, context) => { | ||
278 | if (context.video.name.includes('transcode-filter')) { | ||
279 | object = [ 100 ] | ||
280 | } | ||
281 | |||
282 | return object | ||
283 | } | ||
284 | }) | ||
285 | |||
277 | // Upload/import/live attributes | 286 | // Upload/import/live attributes |
278 | for (const target of [ | 287 | for (const target of [ |
279 | 'filter:api.video.upload.video-attribute.result', | 288 | 'filter:api.video.upload.video-attribute.result', |
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 27b72cf7d..33feadab6 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -677,6 +677,19 @@ describe('Test plugin filter hooks', function () { | |||
677 | }) | 677 | }) |
678 | }) | 678 | }) |
679 | 679 | ||
680 | describe('Transcoding filters', async function () { | ||
681 | |||
682 | it('Should run filter:transcoding.auto.lower-resolutions-to-transcode.result', async function () { | ||
683 | const { uuid } = await servers[0].videos.quickUpload({ name: 'transcode-filter' }) | ||
684 | |||
685 | await waitJobs(servers) | ||
686 | |||
687 | const video = await servers[0].videos.get({ id: uuid }) | ||
688 | expect(video.files).to.have.lengthOf(2) | ||
689 | expect(video.files.find(f => f.resolution.id === 100 as any)).to.exist | ||
690 | }) | ||
691 | }) | ||
692 | |||
680 | after(async function () { | 693 | after(async function () { |
681 | await cleanupTests(servers) | 694 | await cleanupTests(servers) |
682 | }) | 695 | }) |