简体   繁体   中英

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

What you probably want is process.argv . This is the argument vector: list of arguments, where the first two are the node process and the file being run. 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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