未被识别为内部或外部命令"/>
'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)中未被识别为内部或外部命令
发布评论