'ffmpeg'在Hapi js(Node js)中未被识别为内部或外部命令

编程入门 行业动态 更新时间:2024-10-10 17:26:27

'ffmpeg'在Hapi js(Node js)中<a href=https://www.elefans.com/category/jswz/34/1770388.html style=未被识别为内部或外部命令"/>

'ffmpeg'在Hapi js(Node js)中未被识别为内部或外部命令

我想在上传视频时添加水印图像。我尝试使用节点ffmpeg,但是很不幸,git base命令行显示*“ ffmpeg” **无法识别。

'ffmpeg'不被识别为内部或外部命令,可运行程序或批处理文件。

const createVideoWatermark = async () =>{
    try {
        const ffmpeg = require("ffmpeg");
        var process = new ffmpeg('./uploads/video1.mp4');
        process.then(async function (video) {
            console.log('The video is ready to be processed');
            var watermarkPath = './uploads/watermark.jpg',
            newFilepath = './uploads/video-com-watermark.mp4',
            settings = {
                position        : "SE"      // Position: NE NC NW SE SC SW C CE CW
              , margin_nord     : null      // Margin nord
              , margin_sud      : null      // Margin sud
              , margin_east     : null      // Margin east
              , margin_west     : null      // Margin west
            };
            var callback = async function (error, files) {
            if(error){
                console.log('ERROR: ', error);
              }
              else{
                console.log('Waiting', files);
              }
            }
          //add watermark
            await video.fnAddWatermark(watermarkPath, newFilepath, settings, callback);
            return watermarkPath;    
        }, function (err) {
          console.log('Error: ' + err);
          return err;
      });
  } catch (e) {
      console.log(e.code);
      console.log(e.msg);
     return e.msg;
  }

}

[请帮助我解决此问题。我不确定我在哪里弄错了。请纠正我。

回答如下:

最后,我已经使用child_process。我已经使用绘图文字添加了水印。

server.route({
    method: 'GET',
    path: '/video/watermark',
    handler: (request, h) => {

        return new Promise((resolve, reject) => {
          const str = "overlay=10:";
          const child =  execFile('/your-exe-file-path', ['-i', 'from-video-path' , '-vf' , 'drawtext="fontfile=./yourpath/font-filename.ttf:text="Added Watermark": fontcolor=white: fontsize=34:box=1: [email protected]:boxborderw=5: x=(w-text_w)/2: y=(h-text_h)/2', '-codec:a', 'copy', 'destination-video-path' ], (error, stdout, stderr) => {
              if (error) {
                  console.error('err:=====', error);
                   reject(err)
              }else{
                console.log('result: ===========', child);
               resolve({ message: child })
              }

          })
        }); //return end
    }
});

更多推荐

'ffmpeg'在Hapi js(Node js)中未被识别为内部或外部命令

本文发布于:2024-05-07 15:34:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756942.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未被   命令   ffmpeg   Hapi   Node

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!