]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/print-transcode-command.ts
Fix bitrate tests
[github/Chocobozzz/PeerTube.git] / server / tests / cli / print-transcode-command.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils'
6 import { getMaxBitrate } from '@shared/core-utils'
7 import { buildAbsoluteFixturePath, CLICommand } from '@shared/extra-utils'
8 import { VideoResolution } from '../../../shared/models/videos'
9
10 const expect = chai.expect
11
12 describe('Test print transcode jobs', function () {
13
14 it('Should print the correct command for each resolution', async function () {
15 const fixturePath = buildAbsoluteFixturePath('video_short.webm')
16 const fps = await getVideoFileFPS(fixturePath)
17 const bitrate = await getVideoFileBitrate(fixturePath)
18
19 for (const resolution of [
20 VideoResolution.H_720P,
21 VideoResolution.H_1080P
22 ]) {
23 const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`)
24 const targetBitrate = Math.min(getMaxBitrate({ resolution, fps, ratio: 16 / 9 }), bitrate + (bitrate * 0.3))
25
26 expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`)
27 expect(command).to.includes(`-y -acodec aac -vcodec libx264`)
28 expect(command).to.includes('-f mp4')
29 expect(command).to.includes('-movflags faststart')
30 expect(command).to.includes('-b:a 256k')
31 expect(command).to.includes('-r 25')
32 expect(command).to.includes('-level:v 3.1')
33 expect(command).to.includes('-g:v 50')
34 expect(command).to.includes(`-maxrate ${targetBitrate}`)
35 expect(command).to.includes(`-bufsize ${targetBitrate * 2}`)
36 }
37 })
38 })