javascript - 流畅的ffmpeg节点js命令
问题描述
const ffmpeg = require('fluent-ffmpeg');
const videoFile = './f1.mp4';
ffmpeg.ffprobe(videoFile, (err,metaData) => {
const {duration} = metaData.format;
const startingTime = parseInt(duration - 60);
const clipDuration = 20;
ffmpeg()
.input(videoFile)
.inputOptions([`-ss ${startingTime}`])
.outputOptions([`-t ${clipDuration}`])
.output('./result.mp4')
.on('end', ()=> console.log('Done!'))
.on('error',(err)=>console.error(err))
.run();
});
所以这是我的节点 js 代码,我在其中剪切我选择的视频剪辑并给我一个输出。我通过节点索引运行它。js(代码在 index.js 文件中)我想创建一个可以在下面的命令行上运行的脚本
节点 index.js start_time end_time 输入/文件/path.mp4 输出/目录/
我的意思是它将是动态的,因为来自任何目录的任何输入文件和来自任何目录的任何输出文件都像一个函数,它将接受用户输入并相应地执行。无需手动设置。有没有办法做到这一点??我尝试了很多,但都是在命令行上手动或手动设置节点。我正在尝试创建一个动态 js 文件,它将为任何输入运行
解决方案
你可能想要的是process.argv
. 这是参数向量:参数列表,其中前两个是节点进程和正在运行的文件。例子:
const args = process.argv.slice(2);
if (!args.length !== 4) {
console.error('Incorrect number of arguments');
process.exit(1);
}
const [ startTime, endTime, inputFile, outputDirectory ] = args;
推荐阅读
- javascript - 如何合并两个 Javascript 对象
- python - 使用 tensorflow 将 BIOBERT 预训练的词嵌入到 CNN 中
- ios - 由于域 com.apple.dt.MobileDeviceErrorDomain 代码错误,无法在 iPhone 上安装应用程序:-402653081
- java - 运行 heroku 本地网络后的 ClassNotFoundException;不确定要在 Procfile 中包含什么?
- apache-kafka - python的kafka-python(KafkaConsumer)需要很长时间才能打印出消息
- reactjs - Web 应用的外部库在发布后出错
- python - 如何从 Django 表单访问 response.user
- html - 我需要在可见性被隐藏的元素上使用 aria-hidden 吗?
- php - 如果它是由 HTML 选择标记分配的,则在下一个 pahe 中获取 PHP 会话变量时会出现问题
- react-native - FaceDetector:不工作选项 faceDetectionClassifications.all