File size: 2,244 Bytes
3890c2b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | _id: video_processing
title: en=Video processing;ru=Работа с видео
description: Using FFmpeg process videos
version: 1
url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/video_processing.yaml
readme: ""
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: |-
const ffmpeg = require('fluent-ffmpeg');
const path = require('path');
const fs = require('fs/promises');
const { fileTypeFromBuffer } = require('file-type');
(async () => {
const { video, fps } = inputs;
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) => log(cmd))
.on('end', () => resolve())
.on('error', (err) => reject(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 next({outputs: { frames }});
})();
source: catalog
title: en=Split video by frames;ru=Разбить видео по кадрам
version: 6
|