Streampunk / beamcoder

Node.js native bindings to FFmpeg.
GNU General Public License v3.0
397 stars 76 forks source link

watermark #51

Open vinnitu opened 3 years ago

vinnitu commented 3 years ago

Hi All!

I want to add watermak (really other type of processing) on each frame end encode to same codec and container.

Is it possible with beamcoder? Maybe somebody have an example?

Thanks!

jpietek commented 3 years ago

Works exactly as in plain libav/ffmpeg: https://ffmpeg.org/ffmpeg-all.html#overlay-1

vinnitu commented 3 years ago

yes... but if I want draw something on frame?

Rock-N-Troll commented 3 years ago

if you get each frame and change the pixel colors in the right spots and loop over and perform the action for all frames, you can do it (depending on colorspace. example below is for rgb pixels in a frame)

https://github.com/Streampunk/beamcoder#creating-frames There can also be an alpha channel so just depends on the format (rgb, yuv, etc.). It will take some trial and error

pseudocode:

let frame = beamcoder.frame({
          width: encParams.width,
          height: encParams.height,
          format: encParams.pix_fmt
        }).alloc();// or whatever frame data you have, in a loop

        let [ rgbdata ] = frame.data;//existing pixel values

        rgbPixelCount = 3 * width* height; //3 values (r, g, and b) for every pixel of the frame from 0-255, so 0,1,2 are the 1st pixel rgb values

        rgbdata[pixelToChange*3] = 0; //set r value
        rgbdata[pixelToChange*3+1] = 0;//set g value
        rgbdata[pixelToChange*3+2] = 0;//set b value

additional resource with similar approach: https://github.com/Streampunk/beamcoder/issues/19