X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fplugins%2Fplugin-transcoding.ts;h=ce1047388383176290e3133bfeaee3ebb898f418;hb=b1dbb9fefc870a90b25f5c0153589f45c9e75e3e;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..ce1047388 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -1,67 +1,73 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -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 { getAudioStream, getVideoStreamFPS, getVideoStream } from '@server/helpers/ffmpeg' +import { VideoPrivacy } from '@shared/models' import { - buildServerDirectory, - createLive, - getConfig, - getPluginTestPath, - getVideo, - installPlugin, - sendRTMPStreamInVideo, + cleanupTests, + createSingleServer, + PeerTubeServer, + PluginsCommand, setAccessTokensToServers, setDefaultVideoChannel, - uninstallPlugin, - updateCustomSubConfig, - uploadVideoAndGetId, - waitJobs, - waitUntilLivePublished -} from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' - -async function createLiveWrapper (server: ServerInfo) { + testFfmpegStreamError, + waitJobs +} from '@shared/server-commands' + +async function createLiveWrapper (server: PeerTubeServer) { const liveAttributes = { name: 'live video', - channelId: server.videoChannel.id, + channelId: server.store.channel.id, privacy: VideoPrivacy.PUBLIC } - const res = await createLive(server.url, server.accessToken, liveAttributes) - return res.body.video.uuid + const { uuid } = await server.live.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: { +function updateConf (server: PeerTubeServer, vodProfile: string, liveProfile: string) { + return server.config.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 + } + } } } }) } describe('Test transcoding plugins', function () { - let server: ServerInfo + let server: PeerTubeServer before(async function () { this.timeout(60000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) @@ -71,8 +77,7 @@ describe('Test transcoding plugins', function () { describe('When using a plugin adding profiles to existing encoders', function () { async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) { - const res = await getVideo(server.url, uuid) - const video = res.body as VideoDetails + const video = await server.videos.get({ id: uuid }) const files = video.files.concat(...video.streamingPlaylists.map(p => p.files)) for (const file of files) { @@ -86,7 +91,7 @@ describe('Test transcoding plugins', function () { async function checkLiveFPS (uuid: string, type: 'above' | 'below', fps: number) { const playlistUrl = `${server.url}/static/streaming-playlists/hls/${uuid}/0.m3u8` - const videoFPS = await getVideoFileFPS(playlistUrl) + const videoFPS = await getVideoStreamFPS(playlistUrl) if (type === 'above') { expect(videoFPS).to.be.above(fps) @@ -96,82 +101,132 @@ describe('Test transcoding plugins', function () { } before(async function () { - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-transcoding-one') - }) + await server.plugins.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.config.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', 'high-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) + describe('VOD', function () { - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid - await waitJobs([ server ]) + it('Should not use the plugin profile if not chosen by the admin', async function () { + this.timeout(240000) - await checkVideoFPS(videoUUID, 'above', 20) - }) + const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid + await waitJobs([ server ]) - it('Should use the vod profile', async function () { - this.timeout(120000) + await checkVideoFPS(videoUUID, 'above', 20) + }) - await updateConf(server, 'low-vod', 'default') + it('Should use the vod profile', async function () { + this.timeout(240000) - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid - await waitJobs([ server ]) + await updateConf(server, 'low-vod', 'default') - await checkVideoFPS(videoUUID, 'below', 12) - }) + const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid + await waitJobs([ server ]) - it('Should not use the plugin profile if not chosen by the admin', async function () { - this.timeout(120000) + await checkVideoFPS(videoUUID, 'below', 12) + }) - const liveVideoId = await createLiveWrapper(server) + it('Should apply input options in vod profile', async function () { + this.timeout(240000) - await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) - await waitJobs([ server ]) + await updateConf(server, 'input-options-vod', 'default') - await checkLiveFPS(liveVideoId, 'above', 20) - }) + const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid + await waitJobs([ server ]) - it('Should use the live profile', async function () { - this.timeout(120000) + await checkVideoFPS(videoUUID, 'below', 6) + }) - await updateConf(server, 'low-vod', 'low-live') + it('Should apply the scale filter in vod profile', async function () { + this.timeout(240000) - const liveVideoId = await createLiveWrapper(server) + await updateConf(server, 'bad-scale-vod', 'default') - await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) - await waitJobs([ server ]) + const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid + await waitJobs([ server ]) - await checkLiveFPS(liveVideoId, 'below', 12) + // Transcoding failed + const video = await server.videos.get({ id: videoUUID }) + expect(video.files).to.have.lengthOf(1) + expect(video.streamingPlaylists).to.have.lengthOf(0) + }) }) - it('Should default to the default profile if the specified profile does not exist', async function () { - this.timeout(120000) + describe('Live', function () { - await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-transcoding-one' }) + it('Should not use the plugin profile if not chosen by the admin', async function () { + this.timeout(240000) - const res = await getConfig(server.url) - const config = res.body as ServerConfig + const liveVideoId = await createLiveWrapper(server) - expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) - expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) + await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' }) + await server.live.waitUntilPublished({ videoId: liveVideoId }) + await waitJobs([ server ]) - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid - await waitJobs([ server ]) + await checkLiveFPS(liveVideoId, 'above', 20) + }) + + it('Should use the live profile', async function () { + this.timeout(240000) + + await updateConf(server, 'low-vod', 'high-live') - await checkVideoFPS(videoUUID, 'above', 20) + const liveVideoId = await createLiveWrapper(server) + + await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' }) + await server.live.waitUntilPublished({ videoId: liveVideoId }) + await waitJobs([ server ]) + + await checkLiveFPS(liveVideoId, 'above', 45) + }) + + 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.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' }) + await server.live.waitUntilPublished({ videoId: liveVideoId }) + await waitJobs([ server ]) + + await checkLiveFPS(liveVideoId, 'above', 45) + }) + + 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.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' }) + await testFfmpegStreamError(command, true) + }) + + it('Should default to the default profile if the specified profile does not exist', async function () { + this.timeout(240000) + + await server.plugins.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' }) + + const config = await server.config.getConfig() + + expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) + expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) + + const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_very_short_240p.mp4' })).uuid + await waitJobs([ server ]) + + await checkVideoFPS(videoUUID, 'above', 20) + }) }) }) @@ -179,11 +234,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.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') }) await updateConf(server, 'test-vod-profile', 'test-live-profile') }) @@ -191,31 +242,33 @@ 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 server.videos.quickUpload({ name: 'video', fixture: 'video_very_short_240p.mp4' })).uuid await waitJobs([ server ]) - const path = buildServerDirectory(server, join('videos', videoUUID + '-720.mp4')) + const video = await server.videos.get({ id: videoUUID }) + + const path = server.servers.buildWebTorrentFilePath(video.files[0].fileUrl) const audioProbe = await getAudioStream(path) expect(audioProbe.audioStream.codec_name).to.equal('opus') - const videoProbe = await getVideoStreamFromFile(path) + const videoProbe = await getVideoStream(path) expect(videoProbe.codec_name).to.equal('vp9') }) 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.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.live.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8` const audioProbe = await getAudioStream(playlistUrl) expect(audioProbe.audioStream.codec_name).to.equal('opus') - const videoProbe = await getVideoStreamFromFile(playlistUrl) + const videoProbe = await getVideoStream(playlistUrl) expect(videoProbe.codec_name).to.equal('h264') }) })