+ })
+
+ it('Should not transcode to an higher bitrate than the original file but above our low limit', async function () {
+ this.timeout(160_000)
+
+ const newConfig = {
+ transcoding: {
+ enabled: true,
+ resolutions: {
+ '144p': true,
+ '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 bitrate = await getVideoFileBitrate(path)
+
+ const inputBitrate = 60_000
+ const limit = getMinLimitBitrate({ fps: 10, ratio: 1, resolution: r })
+ let belowValue = Math.max(inputBitrate, limit)
+ belowValue += belowValue * 0.20 // Apply 20% margin because bitrate control is not very precise
+
+ expect(bitrate, `${path} not below ${limit}`).to.be.below(belowValue)
+ }
+ })
+ })
+
+ 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(10)
+
+ 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(16)
+
+ 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(8)
+ expect(webtorrentJobs).to.have.lengthOf(7)
+ 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)
+ }
+ })