gpt4 book ai didi

javascript - 流畅的ffmpeg Node js命令

转载 作者:行者123 更新时间:2023-12-04 23:11:53 26 4
gpt4 key购买 nike

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. 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

node index.js start_time end_time input/file/path.mp4 output/directory/

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. 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

最佳答案

你可能想要的是process.argv .这是参数向量:参数列表,其中前两个是 Node 进程和正在运行的文件。例子:

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 - 流畅的ffmpeg Node js命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65675121/

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