mirror of https://github.com/Chocobozzz/PeerTube
Handle webp images from youtube-dl
parent
72493e44e9
commit
1878224214
|
@ -338,11 +338,29 @@ function getClosestFramerateStandard (fps: number, type: 'HD_STANDARD' | 'STANDA
|
||||||
.sort((a, b) => fps % a - fps % b)[0]
|
.sort((a, b) => fps % a - fps % b)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function convertWebPToJPG (path: string, destination: string): Promise<void> {
|
||||||
|
return new Promise<void>(async (res, rej) => {
|
||||||
|
try {
|
||||||
|
const command = ffmpeg(path).output(destination)
|
||||||
|
|
||||||
|
command.on('error', (err, stdout, stderr) => {
|
||||||
|
logger.error('Error in ffmpeg webp convert process.', { stdout, stderr })
|
||||||
|
return rej(err)
|
||||||
|
})
|
||||||
|
.on('end', () => res())
|
||||||
|
.run()
|
||||||
|
} catch (err) {
|
||||||
|
return rej(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getVideoStreamCodec,
|
getVideoStreamCodec,
|
||||||
getAudioStreamCodec,
|
getAudioStreamCodec,
|
||||||
|
convertWebPToJPG,
|
||||||
getVideoStreamSize,
|
getVideoStreamSize,
|
||||||
getVideoFileResolution,
|
getVideoFileResolution,
|
||||||
getMetadataFromFile,
|
getMetadataFromFile,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'multer'
|
import { remove, rename } from 'fs-extra'
|
||||||
import { readFile, remove } from 'fs-extra'
|
import { convertWebPToJPG } from './ffmpeg-utils'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
|
|
||||||
const Jimp = require('jimp')
|
const Jimp = require('jimp')
|
||||||
|
|
||||||
async function processImage (
|
async function processImage (
|
||||||
|
@ -15,9 +16,19 @@ async function processImage (
|
||||||
|
|
||||||
logger.debug('Processing image %s to %s.', path, destination)
|
logger.debug('Processing image %s to %s.', path, destination)
|
||||||
|
|
||||||
// Avoid sharp cache
|
let jimpInstance: any
|
||||||
const buf = await readFile(path)
|
|
||||||
const jimpInstance = await Jimp.read(buf)
|
try {
|
||||||
|
jimpInstance = await Jimp.read(path)
|
||||||
|
} catch (err) {
|
||||||
|
logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', { err })
|
||||||
|
|
||||||
|
const newName = path + '.jpg'
|
||||||
|
await convertWebPToJPG(path, newName)
|
||||||
|
await rename(newName, path)
|
||||||
|
|
||||||
|
jimpInstance = await Jimp.read(path)
|
||||||
|
}
|
||||||
|
|
||||||
await remove(destination)
|
await remove(destination)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue