Giter Club home page Giter Club logo

Comments (6)

mustafa-toptal avatar mustafa-toptal commented on August 30, 2024 3

This is how I rounded the corners of my stream

function roundedImage(ctx, x, y, width, height, radius) {
    ctx.beginPath();
    ctx.moveTo(x + radius, y);
    ctx.lineTo(x + width - radius, y);
    ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
    ctx.lineTo(x + width, y + height - radius);
    ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
    ctx.lineTo(x + radius, y + height);
    ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
    ctx.lineTo(x, y + radius);
    ctx.quadraticCurveTo(x, y, x + radius, y);
    ctx.closePath();
  }

merger.addStream(cameraStream, {
        draw: (ctx, frame, done) => {
          const x = 20;
          const y = merger.height - 180;
          const width = 100;
          const height = 150;
          ctx.save();
          roundedImage(ctx, x, y, width, height, 10);
          ctx.strokeStyle = "#fff";
          ctx.stroke();
          ctx.clip();
          ctx.drawImage(frame, x, y, width, height);
          ctx.restore();
          done();
        },
        x: 20,
        y: merger.height - 180,
        width: 100,
        height: 150,
        mute: false,
      });

Screenshot from 2022-04-16 16-58-33

from video-stream-merger.

no-1ne avatar no-1ne commented on August 30, 2024 1

There seem to be option to override draw method for each stream passed, that may work?

https://github.com/t-mullen/video-stream-merger#custom-draw-function

from video-stream-merger.

hthetiot avatar hthetiot commented on August 30, 2024

@Iulian33 Did you try to Google: "canvas image rounded corners"

from video-stream-merger.

Iulian33 avatar Iulian33 commented on August 30, 2024

@hthetiot we have access to method getCanvasContext() to get merged canvas already, but we do not have an option to get canvas for added stream in my case the webCamera from corner or to send on option to add corner radius to that added stream camera from corner.

from video-stream-merger.

ChristianMatthias avatar ChristianMatthias commented on August 30, 2024

I made it work by adding the following code to the _drawVideo() function inside the Library.
The borderRadius is a custom added attribute to the stream object which makes the corners round by the value in px.

this._ctx?.save(); this._ctx?.beginPath(); this._ctx?.moveTo(positionX + stream.borderRadius, positionY); this._ctx?.lineTo(positionX + width - stream.borderRadius, positionY); this._ctx?.quadraticCurveTo(positionX + width, positionY, positionX + width, positionY + stream.borderRadius); this._ctx?.lineTo(positionX + width, positionY + height - stream.borderRadius); this._ctx?.quadraticCurveTo(positionX + width, positionY + height, positionX + width - stream.borderRadius, positionY + height); this._ctx?.lineTo(positionX + stream.borderRadius, positionY + height); this._ctx?.quadraticCurveTo(positionX, positionY + height, positionX, positionY + height - stream.borderRadius); this._ctx?.lineTo(positionX, positionY + stream.borderRadius); this._ctx?.quadraticCurveTo(positionX, positionY, positionX + stream.borderRadius, positionY); this._ctx?.closePath(); this._ctx?.clip(); this._ctx?.drawImage(element, positionX, positionY, width, height); this._ctx?.restore();

from video-stream-merger.

hthetiot avatar hthetiot commented on August 30, 2024

@Iulian33 you have access to individual draw stream, by providing draw option on addStream like @mustafa-toptal solution here #77 (comment)

I think we can add his solution in the documentation as an example to solve this issue and provide an example usage of custom draw.

from video-stream-merger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.