如何在 Node JS 上通过 ffmpeg 在视频中添加标题
How to add Title in video by ffmpeg on Node JS
我正在做一个项目,我必须在 FFmpeg 的视频上添加标题。我已经成功地在视频上添加了图片。谁能帮我在视频上添加文字(标题)?
这是我添加图片的代码,请提出所需的修改:
try {
var process = new ffmpeg('public/'+req.body.video);
process.then(function (video) {
console.log('The video is ready to be processed');
var watermarkPath = 'public/images/logo.png',
newFilepath = 'public/videos/watermarked/'+name,
settings = {
position : "SC" // 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 = function (error, files) {
if(error){
console.log('ERROR: ', error);
}
else{
console.log('TERMINOU', files);
res.send('videos/watermarked/'+name)
}
}
//add watermark
video.fnAddWatermark(watermarkPath, newFilepath, settings, callback)
}, function (err) {
console.log('Error: ' + err);
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}
您可以创建 canvas ,并在 canvas 上添加一些文本,并通过 canvas 获取 png,您可以在 Node JS 上通过 ffmpeg 在视频中添加标题。
command.videoFilters({
filter: 'drawtext',
options: {
fontfile: 'Lucida Grande.ttf',
text: 'THIS IS TEXT',
/* etc. */
}
});
我正在做一个项目,我必须在 FFmpeg 的视频上添加标题。我已经成功地在视频上添加了图片。谁能帮我在视频上添加文字(标题)?
这是我添加图片的代码,请提出所需的修改:
try {
var process = new ffmpeg('public/'+req.body.video);
process.then(function (video) {
console.log('The video is ready to be processed');
var watermarkPath = 'public/images/logo.png',
newFilepath = 'public/videos/watermarked/'+name,
settings = {
position : "SC" // 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 = function (error, files) {
if(error){
console.log('ERROR: ', error);
}
else{
console.log('TERMINOU', files);
res.send('videos/watermarked/'+name)
}
}
//add watermark
video.fnAddWatermark(watermarkPath, newFilepath, settings, callback)
}, function (err) {
console.log('Error: ' + err);
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}
您可以创建 canvas ,并在 canvas 上添加一些文本,并通过 canvas 获取 png,您可以在 Node JS 上通过 ffmpeg 在视频中添加标题。
command.videoFilters({
filter: 'drawtext',
options: {
fontfile: 'Lucida Grande.ttf',
text: 'THIS IS TEXT',
/* etc. */
}
});