@jrmc/adonis-attachment
Version:
Turn any field on your Lucid model to an attachment data type
41 lines (40 loc) • 1.19 kB
JavaScript
/**
* @jrmc/adonis-attachment
*
* @license MIT
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
*/
import Converter from './converter.js';
import ImageConverter from './image_converter.js';
import { bufferToTempFile } from '../utils/helpers.js';
import FFmpeg from '../adapters/ffmpeg.js';
export default class VideoThumbnailConvert extends Converter {
async handle({ input, options }) {
const filePath = await this.videoToImage(input);
if (options && filePath) {
const converter = new ImageConverter();
return converter.handle({
input: filePath,
options,
});
}
else {
return filePath;
}
}
async videoToImage(input) {
let file = input;
if (Buffer.isBuffer(input)) {
file = await bufferToTempFile(input);
}
const ffmpeg = new FFmpeg(file);
if (this.binPaths) {
if (this.binPaths.ffmpegPath) {
ffmpeg.setFfmpegPath(this.binPaths.ffmpegPath);
}
}
return ffmpeg.screenshots({
time: this.options?.startTime || 2,
});
}
}