【问题标题】:fluent ffmpeg node js command流畅的ffmpeg节点js命令
【发布时间】:2021-04-16 21:12:05
【问题描述】:
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 文件中) 我想创建一个可以在下面的命令行上运行的脚本

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

我的意思是它将是动态的,因为来自任何目录的任何输入文件和来自任何目录的任何输出文件都像一个函数,它将接受用户输入并相应地执行。无需手动设置。 有没有办法做到这一点??我尝试了很多,但都是在命令行上手动或手动设置节点。我正在尝试创建一个可以为任何输入运行的动态 js 文件

【问题讨论】:

    标签: javascript node.js ffmpeg fluent-ffmpeg


    【解决方案1】:

    您可能想要的是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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-21
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 2020-04-07
      • 2020-11-11
      • 2018-06-28
      • 1970-01-01
      相关资源
      最近更新 更多