]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
add test for script printing command
authorRigel Kent <sendmemail@rigelk.eu>
Sat, 9 Jan 2021 21:07:22 +0000 (22:07 +0100)
committerChocobozzz <chocobozzz@cpy.re>
Wed, 13 Jan 2021 08:13:31 +0000 (09:13 +0100)
server/tests/cli/index.ts
server/tests/cli/print-transcode-command.ts [new file with mode: 0644]

index 029cd5196a5adbd22442cf8a71fa8ac9d9c5cc16..242589010910ab6315b5524f6e9437d9231d031a 100644 (file)
@@ -4,6 +4,7 @@ import './create-transcoding-job'
 import './optimize-old-videos'
 import './peertube'
 import './plugins'
 import './optimize-old-videos'
 import './peertube'
 import './plugins'
+import './print-transcode-command'
 import './prune-storage'
 import './reset-password'
 import './update-host'
 import './prune-storage'
 import './reset-password'
 import './update-host'
diff --git a/server/tests/cli/print-transcode-command.ts b/server/tests/cli/print-transcode-command.ts
new file mode 100644 (file)
index 0000000..4a7988d
--- /dev/null
@@ -0,0 +1,36 @@
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+
+import 'mocha'
+import * as chai from 'chai'
+import { execCLI } from '../../../shared/extra-utils'
+import { getTargetBitrate, VideoResolution } from '../../../shared/models/videos'
+import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
+import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils'
+
+const expect = chai.expect
+
+describe('Test create transcoding jobs', function () {
+  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
+    ]) {
+      const command = await execCLI(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`)
+      const targetBitrate = Math.min(getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS), bitrate)
+
+      expect(command).to.includes(`-y -acodec aac -vcodec libx264 -filter:v scale=w=trunc(oh*a/2)*2:h=${resolution}`)
+      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}`)
+    }
+  })
+})