]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/print-transcode-command.ts
Fix bitrate tests
[github/Chocobozzz/PeerTube.git] / server / tests / cli / print-transcode-command.ts
CommitLineData
7185dab3
RK
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
329619b3 5import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils'
679c12e6
C
6import { getMaxBitrate } from '@shared/core-utils'
7import { buildAbsoluteFixturePath, CLICommand } from '@shared/extra-utils'
8import { VideoResolution } from '../../../shared/models/videos'
7185dab3
RK
9
10const expect = chai.expect
11
9f430a53 12describe('Test print transcode jobs', function () {
329619b3 13
7185dab3 14 it('Should print the correct command for each resolution', async function () {
679c12e6 15 const fixturePath = buildAbsoluteFixturePath('video_short.webm')
7185dab3
RK
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 ]) {
329619b3 23 const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`)
9f430a53 24 const targetBitrate = Math.min(getMaxBitrate({ resolution, fps, ratio: 16 / 9 }), bitrate + (bitrate * 0.3))
7185dab3 25
21c917b3
C
26 expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`)
27 expect(command).to.includes(`-y -acodec aac -vcodec libx264`)
7185dab3
RK
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})