import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg'
+import { truncate } from 'lodash'
import { buildAbsoluteFixturePath, wait } from '@shared/core-utils'
+import { VideoDetails, VideoInclude, VideoPrivacy } from '@shared/models'
import { PeerTubeServer } from '../server/server'
function sendRTMPStream (options: {
command.outputOption('-c copy')
} else {
command.outputOption('-c:v libx264')
- command.outputOption('-g 50')
- command.outputOption('-keyint_min 2')
+ command.outputOption('-g 120')
+ command.outputOption('-x264-params "no-scenecut=1"')
command.outputOption('-r 60')
}
if (process.env.DEBUG) {
command.on('stderr', data => console.log(data))
+ command.on('stdout', data => console.log(data))
}
command.run()
let error: Error
try {
- await waitFfmpegUntilError(command, 35000)
+ await waitFfmpegUntilError(command, 45000)
} catch (err) {
error = err
}
}
}
-async function waitUntilLiveSavedOnAllServers (servers: PeerTubeServer[], videoId: string) {
+async function waitUntilLiveWaitingOnAllServers (servers: PeerTubeServer[], videoId: string) {
for (const server of servers) {
- await server.live.waitUntilSaved({ videoId })
+ await server.live.waitUntilWaiting({ videoId })
}
}
+async function waitUntilLiveReplacedByReplayOnAllServers (servers: PeerTubeServer[], videoId: string) {
+ for (const server of servers) {
+ await server.live.waitUntilReplacedByReplay({ videoId })
+ }
+}
+
+async function findExternalSavedVideo (server: PeerTubeServer, liveDetails: VideoDetails) {
+ const include = VideoInclude.BLACKLISTED
+ const privacyOneOf = [ VideoPrivacy.INTERNAL, VideoPrivacy.PRIVATE, VideoPrivacy.PUBLIC, VideoPrivacy.UNLISTED ]
+
+ const { data } = await server.videos.list({ token: server.accessToken, sort: '-publishedAt', include, privacyOneOf })
+
+ const videoNameSuffix = ` - ${new Date(liveDetails.publishedAt).toLocaleString()}`
+ const truncatedVideoName = truncate(liveDetails.name, {
+ length: 120 - videoNameSuffix.length
+ })
+ const toFind = truncatedVideoName + videoNameSuffix
+
+ return data.find(v => v.name === toFind)
+}
+
export {
sendRTMPStream,
waitFfmpegUntilError,
testFfmpegStreamError,
stopFfmpeg,
+
waitUntilLivePublishedOnAllServers,
- waitUntilLiveSavedOnAllServers
+ waitUntilLiveReplacedByReplayOnAllServers,
+ waitUntilLiveWaitingOnAllServers,
+
+ findExternalSavedVideo
}