+ it('Should transcode a 60 FPS video', async function () {
+ this.timeout(60_000)
+
+ const attributes = {
+ name: 'my super 30fps name for server 2',
+ description: 'my super 30fps description for server 2',
+ fixture: '60fps_720p_small.mp4'
+ }
+ await servers[1].videos.upload({ attributes })
+
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const { data } = await server.videos.list()
+
+ const video = data.find(v => v.name === attributes.name)
+ const videoDetails = await server.videos.get({ id: video.id })
+
+ expect(videoDetails.files).to.have.lengthOf(4)
+ expect(videoDetails.files[0].fps).to.be.above(58).and.below(62)
+ expect(videoDetails.files[1].fps).to.be.below(31)
+ expect(videoDetails.files[2].fps).to.be.below(31)
+ expect(videoDetails.files[3].fps).to.be.below(31)
+
+ for (const resolution of [ 240, 360, 480 ]) {
+ const file = videoDetails.files.find(f => f.resolution.id === resolution)
+ const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
+ const fps = await getVideoFileFPS(path)
+
+ expect(fps).to.be.below(31)
+ }
+
+ const file = videoDetails.files.find(f => f.resolution.id === 720)
+ const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
+ const fps = await getVideoFileFPS(path)
+
+ expect(fps).to.be.above(58).and.below(62)
+ }
+ })
+
+ it('Should downscale to the closest divisor standard framerate', async function () {
+ this.timeout(200_000)
+
+ let tempFixturePath: string
+
+ {
+ tempFixturePath = await generateVideoWithFramerate(59)
+
+ const fps = await getVideoFileFPS(tempFixturePath)
+ expect(fps).to.be.equal(59)
+ }
+
+ const attributes = {
+ name: '59fps video',
+ description: '59fps video',
+ fixture: tempFixturePath
+ }
+
+ await servers[1].videos.upload({ attributes })
+
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const { data } = await server.videos.list()
+
+ const { id } = data.find(v => v.name === attributes.name)
+ const video = await server.videos.get({ id })
+
+ {
+ const file = video.files.find(f => f.resolution.id === 240)
+ const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
+ const fps = await getVideoFileFPS(path)
+ expect(fps).to.be.equal(25)
+ }
+
+ {
+ const file = video.files.find(f => f.resolution.id === 720)
+ const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
+ const fps = await getVideoFileFPS(path)
+ expect(fps).to.be.equal(59)
+ }
+ }
+ })
+ })
+
+ describe('Bitrate control', function () {
+
+ it('Should respect maximum bitrate values', async function () {
+ this.timeout(160_000)
+
+ const tempFixturePath = await generateHighBitrateVideo()
+
+ const attributes = {
+ name: 'high bitrate video',
+ description: 'high bitrate video',
+ fixture: tempFixturePath
+ }
+
+ await servers[1].videos.upload({ attributes })
+
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const { data } = await server.videos.list()
+
+ const { id } = data.find(v => v.name === attributes.name)
+ const video = await server.videos.get({ id })
+
+ for (const resolution of [ 240, 360, 480, 720, 1080 ]) {
+ const file = video.files.find(f => f.resolution.id === resolution)
+ const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
+
+ const bitrate = await getVideoFileBitrate(path)
+ const fps = await getVideoFileFPS(path)
+ const dataResolution = await getVideoFileResolution(path)
+
+ expect(resolution).to.equal(resolution)
+
+ const maxBitrate = getMaxBitrate({ ...dataResolution, fps })
+ expect(bitrate).to.be.below(maxBitrate)
+ }
+ }
+ })
+
+ it('Should not transcode to an higher bitrate than the original file', async function () {
+ this.timeout(160_000)
+
+ const newConfig = {
+ transcoding: {
+ enabled: true,
+ resolutions: {
+ '240p': true,
+ '360p': true,
+ '480p': true,
+ '720p': true,
+ '1080p': true,
+ '1440p': true,
+ '2160p': true
+ },
+ webtorrent: { enabled: true },
+ hls: { enabled: true }
+ }
+ }
+ await servers[1].config.updateCustomSubConfig({ newConfig })
+
+ const attributes = {
+ name: 'low bitrate',
+ fixture: 'low-bitrate.mp4'
+ }
+
+ const { id } = await servers[1].videos.upload({ attributes })
+
+ await waitJobs(servers)
+
+ const video = await servers[1].videos.get({ id })
+
+ const resolutions = [ 240, 360, 480, 720, 1080 ]
+ for (const r of resolutions) {
+ const file = video.files.find(f => f.resolution.id === r)
+
+ const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
+ const size = await getFileSize(path)
+ expect(size, `${path} not below ${60_000}`).to.be.below(60_000)
+ }
+ })
+ })
+
+ describe('FFprobe', function () {
+
+ it('Should provide valid ffprobe data', async function () {
+ this.timeout(160_000)
+
+ const videoUUID = (await servers[1].videos.quickUpload({ name: 'ffprobe data' })).uuid
+ await waitJobs(servers)
+
+ {
+ const video = await servers[1].videos.get({ id: videoUUID })
+ const file = video.files.find(f => f.resolution.id === 240)
+ const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
+ const metadata = await getMetadataFromFile(path)
+
+ // expected format properties
+ for (const p of [
+ 'tags.encoder',
+ 'format_long_name',
+ 'size',
+ 'bit_rate'
+ ]) {
+ expect(metadata.format).to.have.nested.property(p)
+ }
+
+ // expected stream properties
+ for (const p of [
+ 'codec_long_name',
+ 'profile',
+ 'width',
+ 'height',
+ 'display_aspect_ratio',
+ 'avg_frame_rate',
+ 'pix_fmt'
+ ]) {
+ expect(metadata.streams[0]).to.have.nested.property(p)
+ }
+
+ expect(metadata).to.not.have.nested.property('format.filename')
+ }
+
+ for (const server of servers) {
+ const videoDetails = await server.videos.get({ id: videoUUID })
+
+ const videoFiles = videoDetails.files
+ .concat(videoDetails.streamingPlaylists[0].files)
+ expect(videoFiles).to.have.lengthOf(8)
+
+ for (const file of videoFiles) {
+ expect(file.metadata).to.be.undefined
+ expect(file.metadataUrl).to.exist
+ expect(file.metadataUrl).to.contain(servers[1].url)
+ expect(file.metadataUrl).to.contain(videoUUID)
+
+ const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl })
+ expect(metadata).to.have.nested.property('format.size')
+ }
+ }
+ })
+
+ it('Should correctly detect if quick transcode is possible', async function () {
+ this.timeout(10_000)
+
+ expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true
+ expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false
+ })
+ })
+
+ describe('Transcoding job queue', function () {
+
+ it('Should have the appropriate priorities for transcoding jobs', async function () {
+ const body = await servers[1].jobs.list({
+ start: 0,
+ count: 100,
+ sort: '-createdAt',
+ jobType: 'video-transcoding'
+ })
+
+ const jobs = body.data
+ const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k)
+
+ expect(transcodingJobs).to.have.lengthOf(14)
+
+ const hlsJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-hls')
+ const webtorrentJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-webtorrent')
+ const optimizeJobs = transcodingJobs.filter(j => j.data.type === 'optimize-to-webtorrent')
+
+ expect(hlsJobs).to.have.lengthOf(7)
+ expect(webtorrentJobs).to.have.lengthOf(6)
+ expect(optimizeJobs).to.have.lengthOf(1)
+
+ for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) {
+ expect(j.priority).to.be.greaterThan(100)
+ expect(j.priority).to.be.lessThan(150)
+ }
+ })
+ })
+
+ after(async function () {
+ await cleanupTests(servers)