简体   繁体   English

流畅的ffmpeg节点js命令

[英]fluent ffmpeg node js command

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();
});

So this is my node js code where I am cutting a clip of the video my choice and giving me an output.所以这是我的节点 js 代码,我在其中剪切了我选择的视频片段,并给了我一个 output。 I run it by node index.我通过节点索引运行它。 js ( code is in index.js file) I want to create a script that can run on the below command line js(代码在 index.js 文件中)我想创建一个可以在下面的命令行上运行的脚本

node index.js start_time end_time input/file/path.mp4 output/directory/节点 index.js start_time end_time 输入/文件/path.mp4 输出/目录/

I mean it will be dynamic, as any input file from any directory and any output file from any directory like a function that will take user inputs and will accordingly.我的意思是它将是动态的,因为来自任何目录的任何输入文件和来自任何目录(如 function)的任何 output 文件都将接受用户输入并相应地进行。 No manual set up.无需手动设置。 Is there a way to do that??有没有办法做到这一点?? I have tried many but all are manually on the command line or a manual node setup.我尝试了很多,但都是在命令行上手动或手动设置节点。 I am trying to create a dynamic js file that will run for any input我正在尝试创建一个动态 js 文件,它将为任何输入运行

What you probably want is process.argv .您可能想要的是process.argv This is the argument vector: list of arguments, where the first two are the node process and the file being run.这是参数向量:arguments 的列表,其中前两个是节点进程和正在运行的文件。 Example:例子:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM