Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Don't block video update on storyboard generation

Chocobozzz8ab6f23a00a0
diff --git a/packages/ffmpeg/src/ffmpeg-command-wrapper.ts b/packages/ffmpeg/src/ffmpeg-command-wrapper.ts
index 9dd867299c..2d1ab11dbe 100644
--- a/packages/ffmpeg/src/ffmpeg-command-wrapper.ts
+++ b/packages/ffmpeg/src/ffmpeg-command-wrapper.ts
@@ -6,6 +6,7 @@ import {
EncoderProfile,
SimpleLogger
} from '@peertube/peertube-models'
+import { MutexInterface } from 'async-mutex'
import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg'
export interface FFmpegCommandWrapperOptions {
@@ -82,7 +83,7 @@ export class FFmpegCommandWrapper {
this.command = undefined
}
- buildCommand (input: string) {
+ buildCommand (input: string, inputFileMutexReleaser?: MutexInterface.Releaser) {
if (this.command) throw new Error('Command is already built')
// We set cwd explicitly because ffmpeg appears to create temporary files when trancoding which fails in read-only file systems
@@ -96,6 +97,12 @@ export class FFmpegCommandWrapper {
this.command.outputOption('-threads ' + this.threads)
}
+ if (inputFileMutexReleaser) {
+ this.command.on('start', () => {
+ setTimeout(() => inputFileMutexReleaser(), 1000)
+ })
+ }
+
return this.command
}
diff --git a/packages/ffmpeg/src/ffmpeg-images.ts b/packages/ffmpeg/src/ffmpeg-images.ts
index b34e22f5e0..73d30bd900 100644
--- a/packages/ffmpeg/src/ffmpeg-images.ts
+++ b/packages/ffmpeg/src/ffmpeg-images.ts
@@ -1,3 +1,4 @@
+import { MutexInterface } from 'async-mutex'
import { FfprobeData } from 'fluent-ffmpeg'
import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper.js'
import { getVideoStreamDuration } from './ffprobe.js'
@@ -100,6 +101,9 @@ export class FFmpegImage {
path: string
destination: string
+ // Will be released after the ffmpeg started
+ inputFileMutexReleaser: MutexInterface.Releaser
+
sprites: {
size: {
width: number
diff --git a/packages/ffmpeg/src/ffmpeg-vod.ts b/packages/ffmpeg/src/ffmpeg-vod.ts
index aec8888cbd..ba537c39ce 100644
--- a/packages/ffmpeg/src/ffmpeg-vod.ts
+++ b/packages/ffmpeg/src/ffmpeg-vod.ts
@@ -88,19 +88,11 @@ export class FFmpegVOD {
this.commandWrapper.debugLog('Will run transcode.', { options })
- const command = this.commandWrapper.buildCommand(options.inputPath)
+ this.commandWrapper.buildCommand(options.inputPath, options.inputFileMutexReleaser)
.output(options.outputPath)
await builders[options.type](options)
- command.on('start', () => {
- setTimeout(() => {
- if (options.inputFileMutexReleaser) {
- options.inputFileMutexReleaser()
- }
- }, 1000)
- })
-
await this.commandWrapper.runCommand()
await this.fixHLSPlaylistIfNeeded(options)
diff --git a/server/core/lib/job-queue/handlers/generate-storyboard.ts b/server/core/lib/job-queue/handlers/generate-storyboard.ts
index 119d7fbab6..b6f069c01f 100644
--- a/server/core/lib/job-queue/handlers/generate-storyboard.ts
+++ b/server/core/lib/job-queue/handlers/generate-storyboard.ts
@@ -81,6 +81,7 @@ async function processGenerateStoryboard (job: Job): Promise<void> {
await ffmpeg.generateStoryboardFromVideo({
destination,
path: videoPath,
+ inputFileMutexReleaser,
sprites: {
size: {
height: spriteHeight,