_id: video_processing version: 2 title: en=Video processing;ru=Работа с видео description: Using FFmpeg process videos readme: "Fix ffmpeg fluent" author: Anton Breslavskii | https://github.com/breslavsky url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/video_processing.yaml nodes: split_video_by_frames: _id: split_video_by_frames arrange: x: 280 y: 110 category: id: split_video_by_frames title: en=Video processing;ru=Обработка видео costs: "" environment: {} inputs: video: order: 1 title: Source video type: video required: true fps: order: 2 title: Frame rate type: integer min: 1 max: 60 step: 1 default: 12 outputs: frames: title: Frames type: image[] package: video_processing script: |- export async function run({ inputs }) { const { video, fps } = inputs; const { FatalError, NextNode } = DEFINITIONS; const ffmpeg = require('fluent-ffmpeg'); const path = require('path'); const fs = require('fs/promises'); const { fileTypeFromBuffer } = require('file-type'); const frames = []; await useTempFolder(async (tmpFolder) => { const { data } = await download(video); const { ext } = await fileTypeFromBuffer(data); const videoPath = path.join(tmpFolder, `source.${ext}`); await fs.writeFile(videoPath, data); await new Promise((resolve, reject) => { ffmpeg(videoPath) .outputOptions([ `-r ${fps || 12}`, '-q:v 1' ]) .output(`${tmpFolder}/%05d.jpg`) .on('start', (cmd) => console.log(cmd)) .on('end', () => resolve()) .on('error', (err) => reject(new FatalError(err))) .run(); }); const files = await fs.readdir(tmpFolder); for (const file of files) { if (file.endsWith('jpg')) { frames.push(await fs.readFile(path.join(tmpFolder, file))); } } }); return NextNode.from({ outputs: { frames } }); } source: catalog title: en=Split video by frames;ru=Разбить видео по кадрам version: 6