0
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

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.