mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-01-21 18:39:38 +00:00
Remove sharp in favor of ffmpeg, fallback to cover
This commit is contained in:
parent
9452d0eca9
commit
d6ae50f89a
5 changed files with 42 additions and 34 deletions
|
|
@ -92,4 +92,29 @@ async function extractCoverArt(filepath, outputpath) {
|
|||
ffmpeg.run()
|
||||
})
|
||||
}
|
||||
module.exports.extractCoverArt = extractCoverArt
|
||||
module.exports.extractCoverArt = extractCoverArt
|
||||
|
||||
//This should convert based on the output file extension as well
|
||||
async function resizeImage(filePath, outputPath, width, height) {
|
||||
var dirname = Path.dirname(outputPath);
|
||||
await fs.ensureDir(dirname);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
var ffmpeg = Ffmpeg(filePath)
|
||||
ffmpeg.addOption(['-vf', `scale=${width || -1}:${height || -1}`])
|
||||
ffmpeg.addOutput(outputPath)
|
||||
ffmpeg.on('start', (cmd) => {
|
||||
Logger.debug(`[FfmpegHelpers] Resize Image Cmd: ${cmd}`)
|
||||
})
|
||||
ffmpeg.on('error', (err, stdout, stderr) => {
|
||||
Logger.error(`[FfmpegHelpers] Resize Image Error ${err}`)
|
||||
resolve(false)
|
||||
})
|
||||
ffmpeg.on('end', () => {
|
||||
Logger.debug(`[FfmpegHelpers] Image resized Successfully`)
|
||||
resolve(outputPath)
|
||||
})
|
||||
ffmpeg.run()
|
||||
})
|
||||
}
|
||||
module.exports.resizeImage = resizeImage
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
const sharp = require('sharp')
|
||||
const fs = require('fs')
|
||||
|
||||
function resize(filePath, width, height, format = 'webp') {
|
||||
const readStream = fs.createReadStream(filePath);
|
||||
let sharpie = sharp()
|
||||
sharpie.toFormat(format)
|
||||
|
||||
if (width || height) {
|
||||
sharpie.resize(width, height, { withoutEnlargement: true })
|
||||
}
|
||||
|
||||
return readStream.pipe(sharpie)
|
||||
}
|
||||
|
||||
module.exports = resize;
|
||||
Loading…
Add table
Add a link
Reference in a new issue