PeerTube/server/tests/cli/optimize-old-videos.ts

104 lines
3.2 KiB
TypeScript
Raw Normal View History

2020-01-31 09:56:52 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2018-10-18 09:53:52 -05:00
import 'mocha'
import * as chai from 'chai'
2020-11-20 10:16:55 -06:00
import { join } from 'path'
2018-10-18 09:53:52 -05:00
import {
2019-04-24 08:10:37 -05:00
cleanupTests,
2018-10-18 09:53:52 -05:00
doubleFollow,
flushAndRunMultipleServers,
generateHighBitrateVideo,
2018-10-18 09:53:52 -05:00
ServerInfo,
setAccessTokensToServers,
2021-07-15 03:02:54 -05:00
wait,
waitJobs
} from '@shared/extra-utils'
import { getMaxBitrate, VideoResolution } from '@shared/models'
2020-11-20 10:16:55 -06:00
import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils'
import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
2018-10-18 09:53:52 -05:00
const expect = chai.expect
describe('Test optimize old videos', function () {
let servers: ServerInfo[] = []
before(async function () {
this.timeout(200000)
// Run server 2 to have transcoding enabled
servers = await flushAndRunMultipleServers(2)
await setAccessTokensToServers(servers)
await doubleFollow(servers[0], servers[1])
let tempFixturePath: string
{
tempFixturePath = await generateHighBitrateVideo()
const bitrate = await getVideoFileBitrate(tempFixturePath)
2019-12-06 02:55:36 -06:00
expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
2018-10-18 09:53:52 -05:00
}
// Upload two videos for our needs
2021-07-15 03:02:54 -05:00
await servers[0].videosCommand.upload({ attributes: { name: 'video1', fixture: tempFixturePath } })
await servers[0].videosCommand.upload({ attributes: { name: 'video2', fixture: tempFixturePath } })
2018-10-18 09:53:52 -05:00
await waitJobs(servers)
})
it('Should have two video files on each server', async function () {
this.timeout(30000)
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const { data } = await server.videosCommand.list()
expect(data).to.have.lengthOf(2)
for (const video of data) {
const videoDetails = await server.videosCommand.get({ id: video.uuid })
expect(videoDetails.files).to.have.lengthOf(1)
2018-10-18 09:53:52 -05:00
}
}
})
it('Should run optimize script', async function () {
2019-07-23 05:04:15 -05:00
this.timeout(200000)
2018-10-18 09:53:52 -05:00
2021-07-05 09:37:50 -05:00
await servers[0].cliCommand.execWithEnv('npm run optimize-old-videos')
2018-10-18 09:53:52 -05:00
await waitJobs(servers)
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const { data } = await server.videosCommand.list()
expect(data).to.have.lengthOf(2)
2018-10-18 09:53:52 -05:00
2021-07-15 03:02:54 -05:00
for (const video of data) {
await server.videosCommand.view({ id: video.uuid })
2018-10-18 09:53:52 -05:00
// Refresh video
await waitJobs(servers)
await wait(5000)
await waitJobs(servers)
2021-07-15 03:02:54 -05:00
const videoDetails = await server.videosCommand.get({ id: video.uuid })
2018-10-18 09:53:52 -05:00
2021-07-15 03:02:54 -05:00
expect(videoDetails.files).to.have.lengthOf(1)
const file = videoDetails.files[0]
2018-10-18 09:53:52 -05:00
2019-12-06 02:55:36 -06:00
expect(file.size).to.be.below(8000000)
2018-10-18 09:53:52 -05:00
2021-07-13 02:43:59 -05:00
const path = servers[0].serversCommand.buildDirectory(join('videos', video.uuid + '-' + file.resolution.id + '.mp4'))
2018-10-18 09:53:52 -05:00
const bitrate = await getVideoFileBitrate(path)
const fps = await getVideoFileFPS(path)
const resolution = await getVideoFileResolution(path)
expect(resolution.videoFileResolution).to.equal(file.resolution.id)
expect(bitrate).to.be.below(getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS))
}
}
})
2019-04-24 08:10:37 -05:00
after(async function () {
await cleanupTests(servers)
2018-10-18 09:53:52 -05:00
})
})