Adapted primary save function to handle single streams and non-item saves (e.g. profiles).

This commit is contained in:
2024-09-11 05:16:54 +02:00
parent 536c427140
commit 370214e1a2
3 changed files with 10 additions and 7 deletions

View File

@@ -3,7 +3,7 @@
const ffmpeg = require('fluent-ffmpeg');
const fs = require('fs-extra');
function mux(sources, target, item) {
function mux(target, sources, item) {
return new Promise((resolve, reject) => {
return sources.reduce((acc, source) => {
return acc.input(source);

View File

@@ -4,21 +4,24 @@ const fs = require('fs-extra');
const path = require('path');
const ffmpeg = require('fluent-ffmpeg');
function save(filepath, item) {
function save(filepath, streams, item) {
const pathComponents = path.parse(filepath);
// allow for single stream argument
streams = [].concat(streams);
return Promise.resolve().then(() => {
return fs.ensureDir(path.dirname(pathComponents.dir));
}).then(() => {
return Promise.all(item.streams.map((stream, index) => {
const target = item.streams.length > 1 ? path.join(pathComponents.dir, `${pathComponents.name}-${index}${pathComponents.ext}`) : filepath;
return Promise.all(streams.map((stream, index) => {
const target = streams.length > 1 ? path.join(pathComponents.dir, `${pathComponents.name}-${index}${pathComponents.ext}`) : filepath;
const file = fs.createWriteStream(target);
return new Promise((resolve, reject) => {
stream.pipe(file).on('error', error => {
reject(error);
}).on('finish', () => {
if(item.mux) {
if(item && item.mux) {
console.log(`Temporarily saved '${target}', queued for muxing`);
} else {
console.log('\x1b[32m%s\x1b[0m', `Saved '${target}'`);