Skip to content

Instantly share code, notes, and snippets.

@suissa
Last active June 12, 2023 10:07
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save suissa/8561624 to your computer and use it in GitHub Desktop.
Save suissa/8561624 to your computer and use it in GitHub Desktop.
Add watermark with Node.js and ffmpeg
var ffmpeg = require('ffmpeg');
try {
var process = new ffmpeg('example.mp4');
process.then(function (video) {
console.log('The video is ready to be processed');
var watermarkPath = 'watermark-suissa.png',
newFilepath = './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 = function (error, files) {
if(error){
console.log('ERROR: ', error);
}
else{
console.log('TERMINOU', files);
}
}
//add watermark
video.fnAddWatermark(watermarkPath, newFilepath, settings, callback)
}, function (err) {
console.log('Error: ' + err);
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}
@josephfraser
Copy link

Thanks Awesome

@musabkhunaijir
Copy link

how can i add (overlay) ?

@agates4
Copy link

agates4 commented May 16, 2019

updated syntax for nodeJS

const fs = require("fs")
var ffmpeg = require("ffmpeg")

async createVideoWatermark() {
    var video = await new ffmpeg("example.mp4")
    var watermarkPath = "example_watermark.png"
    var newFilepath = "watermarked_video.mp4"

    var 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
    }

    // deletes any existing video so we can replace it
    fs.unlinkSync(newFilepath)

    // creates our watermarked video
    await video.fnAddWatermark(watermarkPath, newFilepath, settings)
}

@tilonuz99
Copy link

how to edit watermark pixel?

@pramodWebDev
Copy link

how can change the margin values ?

@hisanibrahim
Copy link

@agates4

only remove existing video file if there is one. otherwise there will be error.

Fix is below

     // deletes any existing video so we can replace it
     if (fs.existsSync(newFilepath)) {
          fs.unlinkSync(newFilepath);
      }

@rajneeshksharma
Copy link

Getting this error while trying to adding watermark to a video, video duration is 25 min and the size is 110mb
One more thing conversation is taking 1 hour for 110mb video
Please help
image

@sharmajays
Copy link

it helped me a lot i am very thankfull to you for sharing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment