node.js - NodeJs 中的子进程生成输出文件和目录
问题描述
我正在使用带有子进程的ffmpeg来合并音频和视频,但是当我尝试下载文件时,它正在同一个文件夹中下载,但我希望它下载到公共文件夹中。
以下是我的子进程生成代码。
// Start the ffmpeg child process
const ffmpegProcess = cp.spawn(ffmpeg, [
// Remove ffmpeg's console spamming
'-loglevel', '8', '-hide_banner',
// Redirect/Enable progress messages
'-progress', 'pipe:3',
// Set inputs
'-i', 'pipe:4',
'-i', 'pipe:5',
// Map audio & video from streams
'-map', '0:a',
'-map', '1:v',
// Keep encoding
'-c:v', 'copy',
// Define output file
'title.mp4',
], {
windowsHide: true,
stdio: [
/* Standard: stdin, stdout, stderr */
'inherit', 'inherit', 'inherit',
/* Custom: pipe:3, pipe:4, pipe:5 */
'pipe', 'pipe', 'pipe',
],
});
解决方案
您可以设置cwd
选项。它将设置您的子进程执行其代码的路径。例如,如果您想在 fs 的根目录下运行您的进程,您可以这样做:
............
], {
cwd: '/',
windowsHide: true,
stdio: [
/* Standard: stdin, stdout, stderr */
'inherit', 'inherit', 'inherit',
/* Custom: pipe:3, pipe:4, pipe:5 */
'pipe', 'pipe', 'pipe',
],
});
所以设置你的公共文件夹的路径,然后它应该在那里下载。
推荐阅读
- excel - VBA 编译错误:错误数量的参数或无效的属性分配尝试取消合并多个工作表上的 excel 单元格时
- reactjs - 找不到模块:无法解析“./reducers/index”
- python - 在 python 中使用来自不同容器的 Kafka 消息
- php - 如何在php中从网络驱动器读取文件?
- r - 如何处理R中函数列表的评估
- javascript - 如何获得相对于背景img的鼠标位置
- javascript - 如何使用渲染之间的挂钩从其父组件调用渲染道具提供的回调
- swift - 任务因超时而失败时如何显示消息
- apache-spark - 使用 simba 驱动程序将数据帧发送到 Bigquery
- c++ - 联合查找以查看形状是否在一侧或另一侧