gpt4 book ai didi

node.js - 如何在nodejs中使用ffmpeg并将结果通过管道传输到带有spawn的流?

转载 作者:行者123 更新时间:2023-12-04 23:32:07 25 4
gpt4 key购买 nike

const { spawn } = require('child_process');
const fs = require('fs');
const readStream = fs.createReadStream('./a.h264');
const command = spawn('ffmpeg', ['-i', 'pipe:0', '-c', 'copy', '-o', 'pipe:1']);
const writeStream = fs.createWriteStream('./a.temp.h264');
readStream.pipe(command.stdin);
command.stdout.pipe(writeStream);

我想将流传输到 ffmpeg 并输出到另一个流,如何使用 ffmpeg 并将结果传输到 nodejs 中的 spawn 流?

最佳答案

要从 nodejs 读取文档,我知道是否只有一个流输入,只需这样做:

const { spawn } = require('child_process');
const fs = require('fs');
const readStream = fs.createReadStream('./a.h264');
const command = spawn('ffmpeg', ['-i', 'pipe:0', '-c', 'copy', 'pipe:1'],{
stdio: ['pipe','pipe','ignore']
});
const writeStream = fs.createWriteStream('./b.h264');
readStream.pipe(command.stdin);
command.stdout.pipe(writeStream);

关于node.js - 如何在nodejs中使用ffmpeg并将结果通过管道传输到带有spawn的流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70735866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com