添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
const ffmpeg = require('fluent-ffmpeg'); const fs = require('fs'); const { v4: uuidv4 } = require('uuid'); // 定义输入视频路径(可以是本地文件或 URL) const inputPath = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4'; // 定义缩略图的输出文件夹路径 const outputPath = `${__dirname}/thumbnail`; // 如果输出文件夹不存在,则创建它 if (!fs.existsSync(outputPath)) { fs.mkdirSync(outputPath); // 生成缩略图 ffmpeg(inputPath) .screenshots({ timestamps: [1], // Capture a thumbnail at 1 second into the video filename: `thumbnail-${uuidv4()}.jpg`, // Generate a unique filename folder: outputPath, .on('end', () => { console.log('Thumbnail generated successfully.'); .on('error', (err) => { console.error('Error generating thumbnail:', err);

1. 输入视频inputPath可以是本地视频文件或指向视频文件的 URL。

2. 输出路径:缩略图将保存在thumbnail文件夹中。如果该文件夹不存在,则会自动创建。

3. 缩略图生成

使用 fluent-ffmpeg 在 Node.js 中生成视频缩略图既简单又高效。这种方法允许您自动创建缩略图,是视频处理应用程序的理想选择。

本文来自作者投稿,版权归原作者所有。如需转载,请注明出处:https://www.nxrte.com/jishu/52697.html

(0)