ActivityPub-federated video streaming platform using P2P directly in your web browser
Correctly handle webp images
Chocobozzz260a6e5ec425
diff --git a/packages/ffmpeg/src/ffmpeg-images.ts b/packages/ffmpeg/src/ffmpeg-images.tsindex 2f6ecbff2a..c266988e5d 100644--- a/packages/ffmpeg/src/ffmpeg-images.ts+++ b/packages/ffmpeg/src/ffmpeg-images.ts@@ -10,19 +10,7 @@ export class FFmpegImage {this.commandWrapper = new FFmpegCommandWrapper(options)}- convertWebPToJPG (options: {- path: string- destination: string- }): Promise<void> {- const { path, destination } = options-- this.commandWrapper.buildCommand(path)- .output(destination)-- return this.commandWrapper.runCommand({ silent: true })- }-- processGIF (options: {+ processImage (options: {path: stringdestination: stringnewSize?: { width: number, height: number }@@ -35,7 +23,7 @@ export class FFmpegImage {command.output(destination)- return this.commandWrapper.runCommand()+ return this.commandWrapper.runCommand({ silent: true })}// ---------------------------------------------------------------------------diff --git a/server/core/helpers/ffmpeg/ffmpeg-image.ts b/server/core/helpers/ffmpeg/ffmpeg-image.tsindex 1f6c6a3c32..25cac50d79 100644--- a/server/core/helpers/ffmpeg/ffmpeg-image.ts+++ b/server/core/helpers/ffmpeg/ffmpeg-image.ts@@ -1,14 +1,10 @@import { FFmpegImage } from '@peertube/peertube-ffmpeg'import { getFFmpegCommandWrapperOptions } from './ffmpeg-options.js'-export function processGIF (options: Parameters<FFmpegImage['processGIF']>[0]) {- return new FFmpegImage(getFFmpegCommandWrapperOptions('thumbnail')).processGIF(options)+export function processImage (options: Parameters<FFmpegImage['processImage']>[0]) {+ return new FFmpegImage(getFFmpegCommandWrapperOptions('thumbnail')).processImage(options)}export function generateThumbnailFromVideo (options: Parameters<FFmpegImage['generateThumbnailFromVideo']>[0]) {return new FFmpegImage(getFFmpegCommandWrapperOptions('thumbnail')).generateThumbnailFromVideo(options)}--export function convertWebPToJPG (options: Parameters<FFmpegImage['convertWebPToJPG']>[0]) {- return new FFmpegImage(getFFmpegCommandWrapperOptions('thumbnail')).convertWebPToJPG(options)-}diff --git a/server/core/helpers/image-utils.ts b/server/core/helpers/image-utils.tsindex c36aa34de6..737ccbc9a1 100644--- a/server/core/helpers/image-utils.ts+++ b/server/core/helpers/image-utils.ts@@ -1,8 +1,8 @@-import { copy, remove } from 'fs-extra/esm'-import { readFile, rename } from 'fs/promises'import { ColorActionName } from '@jimp/plugin-color'import { buildUUID, getLowercaseExtension } from '@peertube/peertube-node-utils'-import { convertWebPToJPG, processGIF } from './ffmpeg/index.js'+import { copy, remove } from 'fs-extra/esm'+import { readFile } from 'fs/promises'+import { processImage as processImageByFFmpeg } from './ffmpeg/index.js'import { logger } from './logger.js'import type Jimp from 'jimp'@@ -28,8 +28,8 @@ export async function processImage (options: {logger.debug('Processing image %s to %s.', path, destination)// Use FFmpeg to process GIF- if (extension === '.gif') {- await processGIF({ path, destination, newSize })+ if (extension === '.gif' || extension === '.webp') {+ await processImageByFFmpeg({ path, destination, newSize })} else {await jimpProcessor({ path, destination, newSize, inputExt: extension })}@@ -65,30 +65,26 @@ async function jimpProcessor (options: {}inputExt: string}) {- const { path, destination, newSize, inputExt } = options+ const { path, newSize, inputExt, destination } = options- let sourceImage: Jimpconst inputBuffer = await readFile(path)const Jimp = await import('jimp')-- try {- sourceImage = await Jimp.default.read(inputBuffer)- } catch (err) {- logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', path, { err })-- const newName = path + '.jpg'- await convertWebPToJPG({ path, destination: newName })- await rename(newName, path)-- sourceImage = await Jimp.default.read(path)- }+ const sourceImage = await Jimp.default.read(inputBuffer)await remove(destination)// Optimization if the source file has the appropriate size- const outputExt = getLowercaseExtension(destination)- if (skipProcessing({ sourceImage, newSize, imageBytes: inputBuffer.byteLength, inputExt, outputExt })) {++ if (+ skipProcessing({+ sourceImage,+ newSize,+ imageBytes: inputBuffer.byteLength,+ inputExt,+ outputExt: getLowercaseExtension(destination)+ })+ ) {return copy(path, destination)}@@ -114,7 +110,7 @@ async function autoResize (options: {if (sourceIsPortrait && !destIsPortraitOrSquare) {const baseImage = sourceImage.cloneQuiet().cover(newSize.width, newSize.height)- .color([ { apply: ColorActionName.SHADE, params: [ 50 ] } ])+ .color([ { apply: ColorActionName.SHADE, params: [ 50 ] } ])const topImage = sourceImage.cloneQuiet().contain(newSize.width, newSize.height)@@ -156,5 +152,5 @@ function hasExif (image: Jimp) {}function removeExif (image: Jimp) {- (image.bitmap as any).exifBuffer = null+ ;(image.bitmap as any).exifBuffer = null}