2021-01-09 15:07:22 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import * as chai from 'chai'
|
2021-07-05 09:37:50 -05:00
|
|
|
import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils'
|
|
|
|
import { CLICommand } from '@shared/extra-utils'
|
2021-01-09 15:07:22 -06:00
|
|
|
import { getTargetBitrate, VideoResolution } from '../../../shared/models/videos'
|
|
|
|
import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
|
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test create transcoding jobs', function () {
|
2021-07-05 09:37:50 -05:00
|
|
|
|
2021-01-09 15:07:22 -06:00
|
|
|
it('Should print the correct command for each resolution', async function () {
|
|
|
|
const fixturePath = 'server/tests/fixtures/video_short.webm'
|
|
|
|
const fps = await getVideoFileFPS(fixturePath)
|
|
|
|
const bitrate = await getVideoFileBitrate(fixturePath)
|
|
|
|
|
|
|
|
for (const resolution of [
|
|
|
|
VideoResolution.H_720P,
|
|
|
|
VideoResolution.H_1080P
|
|
|
|
]) {
|
2021-07-05 09:37:50 -05:00
|
|
|
const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`)
|
2021-01-09 15:07:22 -06:00
|
|
|
const targetBitrate = Math.min(getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS), bitrate)
|
|
|
|
|
2021-04-09 08:51:15 -05:00
|
|
|
expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`)
|
|
|
|
expect(command).to.includes(`-y -acodec aac -vcodec libx264`)
|
2021-01-09 15:07:22 -06:00
|
|
|
expect(command).to.includes('-f mp4')
|
|
|
|
expect(command).to.includes('-movflags faststart')
|
|
|
|
expect(command).to.includes('-b:a 256k')
|
|
|
|
expect(command).to.includes('-r 25')
|
|
|
|
expect(command).to.includes('-level:v 3.1')
|
|
|
|
expect(command).to.includes('-g:v 50')
|
|
|
|
expect(command).to.includes(`-maxrate ${targetBitrate}`)
|
|
|
|
expect(command).to.includes(`-bufsize ${targetBitrate * 2}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|