2021-01-28 08:52:44 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import { expect } from 'chai'
|
|
|
|
import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
|
|
|
|
import {
|
2021-07-07 03:33:49 -05:00
|
|
|
cleanupTests,
|
2021-07-16 02:47:51 -05:00
|
|
|
createSingleServer,
|
|
|
|
PeerTubeServer,
|
2021-07-16 07:27:30 -05:00
|
|
|
PluginsCommand,
|
2021-01-28 08:52:44 -06:00
|
|
|
setAccessTokensToServers,
|
|
|
|
setDefaultVideoChannel,
|
2021-04-09 03:36:21 -05:00
|
|
|
testFfmpegStreamError,
|
2021-07-08 03:18:40 -05:00
|
|
|
waitJobs
|
2021-12-17 02:29:23 -06:00
|
|
|
} from '@shared/server-commands'
|
2021-07-15 03:02:54 -05:00
|
|
|
import { VideoPrivacy } from '@shared/models'
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-16 02:47:51 -05:00
|
|
|
async function createLiveWrapper (server: PeerTubeServer) {
|
2021-01-28 08:52:44 -06:00
|
|
|
const liveAttributes = {
|
|
|
|
name: 'live video',
|
2021-07-16 02:04:35 -05:00
|
|
|
channelId: server.store.channel.id,
|
2021-01-28 08:52:44 -06:00
|
|
|
privacy: VideoPrivacy.PUBLIC
|
|
|
|
}
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
const { uuid } = await server.live.create({ fields: liveAttributes })
|
2021-07-08 03:18:40 -05:00
|
|
|
|
|
|
|
return uuid
|
2021-01-28 08:52:44 -06:00
|
|
|
}
|
|
|
|
|
2021-07-16 02:47:51 -05:00
|
|
|
function updateConf (server: PeerTubeServer, vodProfile: string, liveProfile: string) {
|
2021-07-16 02:04:35 -05:00
|
|
|
return server.config.updateCustomSubConfig({
|
2021-07-07 04:51:09 -05:00
|
|
|
newConfig: {
|
2021-01-28 08:52:44 -06:00
|
|
|
transcoding: {
|
2021-01-29 01:43:53 -06:00
|
|
|
enabled: true,
|
2021-07-07 04:51:09 -05:00
|
|
|
profile: vodProfile,
|
|
|
|
hls: {
|
|
|
|
enabled: true
|
|
|
|
},
|
|
|
|
webtorrent: {
|
|
|
|
enabled: true
|
|
|
|
},
|
2021-01-29 01:43:53 -06:00
|
|
|
resolutions: {
|
|
|
|
'240p': true,
|
|
|
|
'360p': false,
|
|
|
|
'480p': false,
|
|
|
|
'720p': true
|
|
|
|
}
|
2021-07-07 04:51:09 -05:00
|
|
|
},
|
|
|
|
live: {
|
|
|
|
transcoding: {
|
|
|
|
profile: liveProfile,
|
|
|
|
enabled: true,
|
|
|
|
resolutions: {
|
|
|
|
'240p': true,
|
|
|
|
'360p': false,
|
|
|
|
'480p': false,
|
|
|
|
'720p': true
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 08:52:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Test transcoding plugins', function () {
|
2021-07-16 02:47:51 -05:00
|
|
|
let server: PeerTubeServer
|
2021-01-28 08:52:44 -06:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
2021-07-16 02:47:51 -05:00
|
|
|
server = await createSingleServer(1)
|
2021-01-28 08:52:44 -06:00
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
await setDefaultVideoChannel([ server ])
|
|
|
|
|
|
|
|
await updateConf(server, 'default', 'default')
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When using a plugin adding profiles to existing encoders', function () {
|
|
|
|
|
|
|
|
async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) {
|
2021-07-16 02:04:35 -05:00
|
|
|
const video = await server.videos.get({ id: uuid })
|
2021-01-28 08:52:44 -06:00
|
|
|
const files = video.files.concat(...video.streamingPlaylists.map(p => p.files))
|
|
|
|
|
|
|
|
for (const file of files) {
|
|
|
|
if (type === 'above') {
|
|
|
|
expect(file.fps).to.be.above(fps)
|
|
|
|
} else {
|
|
|
|
expect(file.fps).to.be.below(fps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
if (type === 'above') {
|
|
|
|
expect(videoFPS).to.be.above(fps)
|
|
|
|
} else {
|
|
|
|
expect(videoFPS).to.be.below(fps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
before(async function () {
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-one') })
|
2021-01-28 08:52:44 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have the appropriate available profiles', async function () {
|
2021-07-16 02:04:35 -05:00
|
|
|
const config = await server.config.getConfig()
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-04-09 03:36:21 -05:00
|
|
|
expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ])
|
2021-07-22 01:46:55 -05:00
|
|
|
expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'high-live', 'input-options-live', 'bad-scale-live' ])
|
2021-01-28 08:52:44 -06:00
|
|
|
})
|
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
describe('VOD', function () {
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
it('Should not use the plugin profile if not chosen by the admin', async function () {
|
|
|
|
this.timeout(240000)
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
|
|
|
|
await waitJobs([ server ])
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await checkVideoFPS(videoUUID, 'above', 20)
|
|
|
|
})
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
it('Should use the vod profile', async function () {
|
|
|
|
this.timeout(240000)
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await updateConf(server, 'low-vod', 'default')
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
|
|
|
|
await waitJobs([ server ])
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await checkVideoFPS(videoUUID, 'below', 12)
|
|
|
|
})
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
it('Should apply input options in vod profile', async function () {
|
|
|
|
this.timeout(240000)
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await updateConf(server, 'input-options-vod', 'default')
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
|
|
|
|
await waitJobs([ server ])
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await checkVideoFPS(videoUUID, 'below', 6)
|
|
|
|
})
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
it('Should apply the scale filter in vod profile', async function () {
|
|
|
|
this.timeout(240000)
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await updateConf(server, 'bad-scale-vod', 'default')
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
|
|
|
|
await waitJobs([ server ])
|
|
|
|
|
|
|
|
// Transcoding failed
|
|
|
|
const video = await server.videos.get({ id: videoUUID })
|
|
|
|
expect(video.files).to.have.lengthOf(1)
|
|
|
|
expect(video.streamingPlaylists).to.have.lengthOf(0)
|
|
|
|
})
|
2021-04-06 08:12:38 -05:00
|
|
|
})
|
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
describe('Live', function () {
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
it('Should not use the plugin profile if not chosen by the admin', async function () {
|
|
|
|
this.timeout(240000)
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const liveVideoId = await createLiveWrapper(server)
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' })
|
|
|
|
await server.live.waitUntilPublished({ videoId: liveVideoId })
|
|
|
|
await waitJobs([ server ])
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await checkLiveFPS(liveVideoId, 'above', 20)
|
|
|
|
})
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
it('Should use the live profile', async function () {
|
|
|
|
this.timeout(240000)
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await updateConf(server, 'low-vod', 'high-live')
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const liveVideoId = await createLiveWrapper(server)
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' })
|
|
|
|
await server.live.waitUntilPublished({ videoId: liveVideoId })
|
|
|
|
await waitJobs([ server ])
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await checkLiveFPS(liveVideoId, 'above', 45)
|
|
|
|
})
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
it('Should apply the input options on live profile', async function () {
|
|
|
|
this.timeout(240000)
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await updateConf(server, 'low-vod', 'input-options-live')
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const liveVideoId = await createLiveWrapper(server)
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' })
|
|
|
|
await server.live.waitUntilPublished({ videoId: liveVideoId })
|
|
|
|
await waitJobs([ server ])
|
2021-04-06 08:12:38 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await checkLiveFPS(liveVideoId, 'above', 45)
|
|
|
|
})
|
2021-04-09 03:36:21 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
it('Should apply the scale filter name on live profile', async function () {
|
|
|
|
this.timeout(240000)
|
2021-04-09 03:36:21 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await updateConf(server, 'low-vod', 'bad-scale-live')
|
2021-04-09 03:36:21 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const liveVideoId = await createLiveWrapper(server)
|
2021-04-09 03:36:21 -05:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const command = await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' })
|
|
|
|
await testFfmpegStreamError(command, true)
|
|
|
|
})
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
it('Should default to the default profile if the specified profile does not exist', async function () {
|
|
|
|
this.timeout(240000)
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await server.plugins.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' })
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const config = await server.config.getConfig()
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
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 ])
|
2021-01-28 08:52:44 -06:00
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
await checkVideoFPS(videoUUID, 'above', 20)
|
|
|
|
})
|
2021-01-28 08:52:44 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When using a plugin adding new encoders', function () {
|
|
|
|
|
|
|
|
before(async function () {
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') })
|
2021-01-28 08:52:44 -06:00
|
|
|
|
|
|
|
await updateConf(server, 'test-vod-profile', 'test-live-profile')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should use the new vod encoders', async function () {
|
|
|
|
this.timeout(240000)
|
|
|
|
|
2021-07-22 01:46:55 -05:00
|
|
|
const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_very_short_240p.mp4' })).uuid
|
2021-01-28 08:52:44 -06:00
|
|
|
await waitJobs([ server ])
|
|
|
|
|
2021-07-23 04:20:00 -05:00
|
|
|
const video = await server.videos.get({ id: videoUUID })
|
|
|
|
|
|
|
|
const path = server.servers.buildWebTorrentFilePath(video.files[0].fileUrl)
|
2021-01-28 08:52:44 -06:00
|
|
|
const audioProbe = await getAudioStream(path)
|
|
|
|
expect(audioProbe.audioStream.codec_name).to.equal('opus')
|
|
|
|
|
|
|
|
const videoProbe = await getVideoStreamFromFile(path)
|
|
|
|
expect(videoProbe.codec_name).to.equal('vp9')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should use the new live encoders', async function () {
|
2021-05-25 06:14:05 -05:00
|
|
|
this.timeout(240000)
|
2021-01-28 08:52:44 -06:00
|
|
|
|
|
|
|
const liveVideoId = await createLiveWrapper(server)
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
|
|
|
|
await server.live.waitUntilPublished({ videoId: liveVideoId })
|
2021-01-28 08:52:44 -06:00
|
|
|
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)
|
|
|
|
expect(videoProbe.codec_name).to.equal('h264')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|