/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { expect } from 'chai'
-import * as ffmpeg from 'fluent-ffmpeg'
+import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg'
import { pathExists, readdir } from 'fs-extra'
import { join } from 'path'
import { buildAbsoluteFixturePath, wait } from '../miscs'
import { PeerTubeServer } from '../server/server'
-function sendRTMPStream (rtmpBaseUrl: string, streamKey: string, fixtureName = 'video_short.mp4') {
+function sendRTMPStream (options: {
+ rtmpBaseUrl: string
+ streamKey: string
+ fixtureName?: string // default video_short.mp4
+ copyCodecs?: boolean // default false
+}) {
+ const { rtmpBaseUrl, streamKey, fixtureName = 'video_short.mp4', copyCodecs = false } = options
+
const fixture = buildAbsoluteFixturePath(fixtureName)
const command = ffmpeg(fixture)
command.inputOption('-stream_loop -1')
command.inputOption('-re')
- command.outputOption('-c:v libx264')
- command.outputOption('-g 50')
- command.outputOption('-keyint_min 2')
- command.outputOption('-r 60')
+
+ if (copyCodecs) {
+ command.outputOption('-c copy')
+ } else {
+ command.outputOption('-c:v libx264')
+ command.outputOption('-g 50')
+ command.outputOption('-keyint_min 2')
+ command.outputOption('-r 60')
+ }
+
command.outputOption('-f flv')
const rtmpUrl = rtmpBaseUrl + '/' + streamKey
return command
}
-function waitFfmpegUntilError (command: ffmpeg.FfmpegCommand, successAfterMS = 10000) {
+function waitFfmpegUntilError (command: FfmpegCommand, successAfterMS = 10000) {
return new Promise<void>((res, rej) => {
command.on('error', err => {
return rej(err)
})
}
-async function testFfmpegStreamError (command: ffmpeg.FfmpegCommand, shouldHaveError: boolean) {
+async function testFfmpegStreamError (command: FfmpegCommand, shouldHaveError: boolean) {
let error: Error
try {
if (!shouldHaveError && error) throw error
}
-async function stopFfmpeg (command: ffmpeg.FfmpegCommand) {
+async function stopFfmpeg (command: FfmpegCommand) {
command.kill('SIGINT')
await wait(500)
}
}
+async function waitUntilLiveSavedOnAllServers (servers: PeerTubeServer[], videoId: string) {
+ for (const server of servers) {
+ await server.live.waitUntilSaved({ videoId })
+ }
+}
+
async function checkLiveCleanupAfterSave (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) {
const basePath = server.servers.buildDirectory('streaming-playlists')
const hlsPath = join(basePath, 'hls', videoUUID)
testFfmpegStreamError,
stopFfmpeg,
waitUntilLivePublishedOnAllServers,
+ waitUntilLiveSavedOnAllServers,
checkLiveCleanupAfterSave
}