X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fplugins%2Fplugin-transcoding.ts;h=ca4d9f962eca2f9c0f4e4c094210a264b7baf4c3;hb=04aed76711909507e74905bde3a7fa024d3585c9;hp=96ff4c2fec3eb4aa5e0be5a8c2976a1c72eca033;hpb=1896bca09e088b0da9d5e845407ecebae330618c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index 96ff4c2fe..ca4d9f962 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -4,24 +4,20 @@ import 'mocha' import { expect } from 'chai' import { join } from 'path' import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' -import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models' import { buildServerDirectory, - createLive, - getConfig, - getPluginTestPath, + cleanupTests, + flushAndRunServer, getVideo, - installPlugin, - sendRTMPStreamInVideo, + PluginsCommand, + ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uninstallPlugin, - updateCustomSubConfig, + testFfmpegStreamError, uploadVideoAndGetId, - waitJobs, - waitUntilLivePublished -} from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' + waitJobs +} from '@shared/extra-utils' +import { VideoDetails, VideoPrivacy } from '@shared/models' async function createLiveWrapper (server: ServerInfo) { const liveAttributes = { @@ -30,26 +26,41 @@ async function createLiveWrapper (server: ServerInfo) { privacy: VideoPrivacy.PUBLIC } - const res = await createLive(server.url, server.accessToken, liveAttributes) - return res.body.video.uuid + const { uuid } = await server.liveCommand.create({ fields: liveAttributes }) + + return uuid } function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) { - return updateCustomSubConfig(server.url, server.accessToken, { - transcoding: { - enabled: true, - profile: vodProfile, - hls: { - enabled: true - }, - webtorrent: { - enabled: true - } - }, - live: { + return server.configCommand.updateCustomSubConfig({ + newConfig: { transcoding: { - profile: liveProfile, - enabled: true + enabled: true, + profile: vodProfile, + hls: { + enabled: true + }, + webtorrent: { + enabled: true + }, + resolutions: { + '240p': true, + '360p': false, + '480p': false, + '720p': true + } + }, + live: { + transcoding: { + profile: liveProfile, + enabled: true, + resolutions: { + '240p': true, + '360p': false, + '480p': false, + '720p': true + } + } } } }) @@ -96,23 +107,18 @@ describe('Test transcoding plugins', function () { } before(async function () { - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-transcoding-one') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-one') }) }) it('Should have the appropriate available profiles', async function () { - const res = await getConfig(server.url) - const config = res.body as ServerConfig + const config = await server.configCommand.getConfig() - expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod' ]) - expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live' ]) + expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ]) + expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live', 'input-options-live', 'bad-scale-live' ]) }) it('Should not use the plugin profile if not chosen by the admin', async function () { - this.timeout(120000) + this.timeout(240000) const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid await waitJobs([ server ]) @@ -121,7 +127,7 @@ describe('Test transcoding plugins', function () { }) it('Should use the vod profile', async function () { - this.timeout(120000) + this.timeout(240000) await updateConf(server, 'low-vod', 'default') @@ -131,39 +137,90 @@ describe('Test transcoding plugins', function () { await checkVideoFPS(videoUUID, 'below', 12) }) + it('Should apply input options in vod profile', async function () { + this.timeout(240000) + + await updateConf(server, 'input-options-vod', 'default') + + const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + await waitJobs([ server ]) + + await checkVideoFPS(videoUUID, 'below', 6) + }) + + it('Should apply the scale filter in vod profile', async function () { + this.timeout(240000) + + await updateConf(server, 'bad-scale-vod', 'default') + + const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + await waitJobs([ server ]) + + // Transcoding failed + const res = await getVideo(server.url, videoUUID) + const video: VideoDetails = res.body + + expect(video.files).to.have.lengthOf(1) + expect(video.streamingPlaylists).to.have.lengthOf(0) + }) + it('Should not use the plugin profile if not chosen by the admin', async function () { - this.timeout(120000) + this.timeout(240000) const liveVideoId = await createLiveWrapper(server) - await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) + await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'above', 20) }) it('Should use the live profile', async function () { - this.timeout(120000) + this.timeout(240000) await updateConf(server, 'low-vod', 'low-live') const liveVideoId = await createLiveWrapper(server) - await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) + await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'below', 12) }) + it('Should apply the input options on live profile', async function () { + this.timeout(240000) + + await updateConf(server, 'low-vod', 'input-options-live') + + const liveVideoId = await createLiveWrapper(server) + + await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) + await waitJobs([ server ]) + + await checkLiveFPS(liveVideoId, 'below', 6) + }) + + it('Should apply the scale filter name on live profile', async function () { + this.timeout(240000) + + await updateConf(server, 'low-vod', 'bad-scale-live') + + const liveVideoId = await createLiveWrapper(server) + + const command = await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await testFfmpegStreamError(command, true) + }) + it('Should default to the default profile if the specified profile does not exist', async function () { - this.timeout(120000) + this.timeout(240000) - await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-transcoding-one' }) + await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' }) - const res = await getConfig(server.url) - const config = res.body as ServerConfig + const config = await server.configCommand.getConfig() expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) @@ -179,11 +236,7 @@ describe('Test transcoding plugins', function () { describe('When using a plugin adding new encoders', function () { before(async function () { - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-transcoding-two') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') }) await updateConf(server, 'test-vod-profile', 'test-live-profile') }) @@ -191,10 +244,10 @@ describe('Test transcoding plugins', function () { it('Should use the new vod encoders', async function () { this.timeout(240000) - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid await waitJobs([ server ]) - const path = buildServerDirectory(server, join('videos', videoUUID + '-720.mp4')) + const path = buildServerDirectory(server, join('videos', videoUUID + '-240.mp4')) const audioProbe = await getAudioStream(path) expect(audioProbe.audioStream.codec_name).to.equal('opus') @@ -203,12 +256,12 @@ describe('Test transcoding plugins', function () { }) it('Should use the new live encoders', async function () { - this.timeout(120000) + this.timeout(240000) const liveVideoId = await createLiveWrapper(server) - await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) + await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8`