+ 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 path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4'))
+ const fps = await getVideoFileFPS(path)
+
+ expect(fps).to.be.below(31)
+ }
+
+ const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4'))
+ 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 video = data.find(v => v.name === attributes.name)
+
+ {
+ const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4'))
+ const fps = await getVideoFileFPS(path)
+ expect(fps).to.be.equal(25)
+ }
+
+ {
+ const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4'))
+ 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)
+
+ let tempFixturePath: string
+
+ {
+ tempFixturePath = await generateHighBitrateVideo()
+
+ const bitrate = await getVideoFileBitrate(tempFixturePath)
+ expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
+ }
+
+ 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 video = data.find(v => v.name === attributes.name)
+
+ for (const resolution of [ '240', '360', '480', '720', '1080' ]) {
+ const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4'))
+
+ const bitrate = await getVideoFileBitrate(path)
+ const fps = await getVideoFileFPS(path)
+ const resolution2 = await getVideoFileResolution(path)
+
+ expect(resolution2.videoFileResolution.toString()).to.equal(resolution)
+ expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS))
+ }
+ }
+ })
+
+ 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 { uuid } = await servers[1].videos.upload({ attributes })
+
+ await waitJobs(servers)
+
+ const resolutions = [ 240, 360, 480, 720, 1080 ]
+ for (const r of resolutions) {
+ const path = `videos/${uuid}-${r}.mp4`
+ const size = await servers[1].servers.getServerFileSize(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 path = servers[1].servers.buildDirectory(join('videos', videoUUID + '-240.mp4'))
+ 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.getJobsList({
+ 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)
+ }
+ })