From 46950fbcc89a3b0d68ca0dff899ffa956a209433 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Mar 2024 10:44:20 +0100 Subject: [PATCH] Fix encoder after transcoding profile deletion --- packages/ffmpeg/src/ffmpeg-command-wrapper.ts | 2 +- .../default-transcoding-profiles.ts | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/ffmpeg/src/ffmpeg-command-wrapper.ts b/packages/ffmpeg/src/ffmpeg-command-wrapper.ts index 4a3b04bf1..50e842f76 100644 --- a/packages/ffmpeg/src/ffmpeg-command-wrapper.ts +++ b/packages/ffmpeg/src/ffmpeg-command-wrapper.ts @@ -1,6 +1,6 @@ -import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg' import { pick, promisify0 } from '@peertube/peertube-core-utils' import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptionsBuilderParams, EncoderProfile } from '@peertube/peertube-models' +import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg' type FFmpegLogger = { info: (msg: string, obj?: any) => void diff --git a/server/core/lib/transcoding/default-transcoding-profiles.ts b/server/core/lib/transcoding/default-transcoding-profiles.ts index 639809be7..f1a2feaa2 100644 --- a/server/core/lib/transcoding/default-transcoding-profiles.ts +++ b/server/core/lib/transcoding/default-transcoding-profiles.ts @@ -70,18 +70,26 @@ class VideoTranscodingProfilesManager { const { type, encoder, profile } = options delete this.availableEncoders[type][encoder][profile] + this.buildAvailableProfiles() } addEncoderPriority (type: 'vod' | 'live', streamType: 'audio' | 'video', encoder: string, priority: number) { - this.encodersPriorities[type][streamType].push({ name: encoder, priority }) + this.encodersPriorities[type][streamType].push({ name: encoder, priority, isDefault: false }) FFmpegCommandWrapper.resetSupportedEncoders() } removeEncoderPriority (type: 'vod' | 'live', streamType: 'audio' | 'video', encoder: string, priority: number) { this.encodersPriorities[type][streamType] = this.encodersPriorities[type][streamType] - .filter(o => o.name !== encoder && o.priority !== priority) + .filter(o => { + // Don't remove default encoders + if (o.isDefault) return true + // Don't include this encoder anymore + if (o.name === encoder && o.priority === priority) return false + + return true + }) FFmpegCommandWrapper.resetSupportedEncoders() } @@ -118,14 +126,14 @@ class VideoTranscodingProfilesManager { private buildDefaultEncodersPriorities () { return { video: [ - { name: 'libx264', priority: 100 } + { name: 'libx264', priority: 100, isDefault: true } ], // Try the first one, if not available try the second one etc audio: [ // we favor VBR, if a good AAC encoder is available - { name: 'libfdk_aac', priority: 200 }, - { name: 'aac', priority: 100 } + { name: 'libfdk_aac', priority: 200, isDefault: true }, + { name: 'aac', priority: 100, isDefault: true } ] } }