Update video_processing.yaml
Browse files- video_processing.yaml +39 -37
video_processing.yaml
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
_id: video_processing
|
|
|
|
| 2 |
title: en=Video processing;ru=Работа с видео
|
| 3 |
description: Using FFmpeg process videos
|
| 4 |
-
version: 1
|
| 5 |
-
url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/video_processing.yaml
|
| 6 |
readme: ""
|
|
|
|
|
|
|
| 7 |
nodes:
|
| 8 |
split_video_by_frames:
|
| 9 |
_id: split_video_by_frames
|
|
@@ -35,47 +36,48 @@ nodes:
|
|
| 35 |
type: image[]
|
| 36 |
package: video_processing
|
| 37 |
script: |-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
const fs = require('fs/promises');
|
| 41 |
-
const { fileTypeFromBuffer } = require('file-type');
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
await new Promise((resolve, reject) => {
|
| 56 |
-
ffmpeg(videoPath)
|
| 57 |
-
.outputOptions([
|
| 58 |
-
`-r ${fps || 12}`,
|
| 59 |
-
'-q:v 1'
|
| 60 |
-
])
|
| 61 |
-
.output(`${tmpFolder}/%05d.jpg`)
|
| 62 |
-
.on('start', (cmd) => log(cmd))
|
| 63 |
-
.on('end', () => resolve())
|
| 64 |
-
.on('error', (err) => reject(err))
|
| 65 |
-
.run();
|
| 66 |
-
});
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
}
|
| 79 |
source: catalog
|
| 80 |
title: en=Split video by frames;ru=Разбить видео по кадрам
|
| 81 |
version: 6
|
|
|
|
| 1 |
_id: video_processing
|
| 2 |
+
version: 1
|
| 3 |
title: en=Video processing;ru=Работа с видео
|
| 4 |
description: Using FFmpeg process videos
|
|
|
|
|
|
|
| 5 |
readme: ""
|
| 6 |
+
author: Anton Breslavskii | https://github.com/breslavsky
|
| 7 |
+
url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/video_processing.yaml
|
| 8 |
nodes:
|
| 9 |
split_video_by_frames:
|
| 10 |
_id: split_video_by_frames
|
|
|
|
| 36 |
type: image[]
|
| 37 |
package: video_processing
|
| 38 |
script: |-
|
| 39 |
+
export async function run({ inputs }) {
|
| 40 |
+
const { video, fps } = inputs;
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
const { FatalError, NextNode } = DEFINITIONS;
|
| 43 |
+
const ffmpeg = require('fluent-ffmpeg');
|
| 44 |
+
const path = require('path');
|
| 45 |
+
const fs = require('fs/promises');
|
| 46 |
+
const { fileTypeFromBuffer } = require('file-type');
|
| 47 |
|
| 48 |
+
const frames = [];
|
| 49 |
|
| 50 |
+
await useTempFolder(async (tmpFolder) => {
|
| 51 |
+
|
| 52 |
+
const { data } = await download(video);
|
| 53 |
+
const { ext } = await fileTypeFromBuffer(data);
|
| 54 |
+
const videoPath = path.join(tmpFolder, `source.${ext}`);
|
| 55 |
+
await fs.writeFile(videoPath, data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
await new Promise((resolve, reject) => {
|
| 58 |
+
ffmpeg(videoPath)
|
| 59 |
+
.outputOptions([
|
| 60 |
+
`-r ${fps || 12}`,
|
| 61 |
+
'-q:v 1'
|
| 62 |
+
])
|
| 63 |
+
.output(`${tmpFolder}/%05d.jpg`)
|
| 64 |
+
.on('start', (cmd) => console.log(cmd))
|
| 65 |
+
.on('end', () => resolve())
|
| 66 |
+
.on('error', (err) => reject(new FatalError(err)))
|
| 67 |
+
.run();
|
| 68 |
+
});
|
| 69 |
|
| 70 |
+
const files = await fs.readdir(tmpFolder);
|
| 71 |
+
for (const file of files) {
|
| 72 |
+
if (file.endsWith('jpg')) {
|
| 73 |
+
frames.push(await fs.readFile(path.join(tmpFolder, file)));
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
});
|
| 78 |
|
| 79 |
+
return NextNode.from({ outputs: { frames } });
|
| 80 |
+
}
|
| 81 |
source: catalog
|
| 82 |
title: en=Split video by frames;ru=Разбить видео по кадрам
|
| 83 |
version: 6
|