Files
pics/lib/file/video/videothumbnail.js
Thomas Lynch 9c85532d9b Change videothumnail to use -ss ot -t0, not both
Log (warn) on error if the first thumbnail fails because the error can be handy in debugging
2024-06-18 19:22:01 +10:00

38 lines
1.0 KiB
JavaScript

'use strict';
const ffmpeg = require('fluent-ffmpeg')
, config = require(__dirname+'/../../misc/config.js')
, uploadDirectory = require(__dirname+'/../uploaddirectory.js');
module.exports = (file, geometry, timestamp) => {
const { thumbSize } = config.get;
let inputArgs = [
timestamp === 0 ? '-t 0' : `-ss ${timestamp}`
];
let outputArgs = [
`-vf scale=${geometry.width > geometry.height ? thumbSize + ':-2' : '-2:' + thumbSize}`,
'-frames:v 1'
];
// workaround: FFmpeg native WebM decoder doesn't handle alpha.
if (file.codec === 'vp8') { inputArgs.push('-c:v libvpx'); }
if (file.codec === 'vp9') { inputArgs.push('-c:v libvpx-vp9'); }
return new Promise((resolve, reject) => {
const command = ffmpeg(`${uploadDirectory}/file/${file.filename}`)
.on('end', () => {
return resolve();
})
.on('error', function(err) {
return reject(err);
});
command
.inputOptions(inputArgs)
.outputOptions(outputArgs)
.output(`${uploadDirectory}/file/thumb/${file.hash}${file.thumbextension}`)
.run();
});
};