Comments (11)
You're drawing your arc in the top-left, you'll have to draw it in the bottom-left, something like:
ctx.arc(height/2 + 50, merger.height - (height/2 + 50), height/2, 0, Math.PI*2, true);
from video-stream-merger.
That should be fine.
from video-stream-merger.
You're close, just save the state before clipping:
// my webcam feed acting as a background
merger.addStream(camera, { x: 0, y: 0, width: 1366, height: 768 });
// video I want to place in the corner of webcam feed in the form of a circle
merger.addMediaElement('circle', document.getElementById('video'), {
draw: (ctx, frame, done) => {
// video size is 1280x720, I need only a circle in the center of it
const x = 0, y = 0, width = 1280, height = 720;
ctx.save(); // <--
ctx.beginPath();
ctx.arc(x + width/2, y + height/2, width/2, 0, Math.PI*2, true);
ctx.closePath();
ctx.clip();
ctx.drawImage(frame, x, y, width, height);
ctx.restore();
done();
}
});
from video-stream-merger.
Thank you so much, I was able to draw it in a small circle at the top left corner of webcam feed
draw: (ctx, frame, done) => {
const x = 0, y = 0, width = 320, height = 185;
ctx.save();
ctx.beginPath();
// 50 pixels from top and left borders
ctx.arc(height/2 + 50, height/2 + 50, height/2, 0, Math.PI*2, true);
ctx.closePath();
ctx.clip();
ctx.drawImage(frame, x, y, width, height);
ctx.restore();
done();
}
But how to place it at the bottom left corner of the main frame?
Changing arguments to drawImage
wasn't helpful, possibly I should also change arc
but how?
Since I have a circular video, I would need 50 pixels + radius
from left and bottom borders.
from video-stream-merger.
Thank you, Thomas! Works flawlessly now!
By the way, could you please point me how could I update addMediaElement
if I will change video.src?
Say I want to display several short videos in a row using the same video tag.
Currently it shows only the first video, since it was initialized inside getUserMedia
.
Is it possible to somehow send a signal to merger that addMediaElement
source has been changed?
from video-stream-merger.
I think it will just automatically update if you change video.src. Let me know if that's not the case.
from video-stream-merger.
Unfortunately that's not the case, please take a look how I am recording it:
merger = new VideoStreamMerger({ width: 1366, height: 768 });
navigator
.mediaDevices
.getUserMedia({
audio: true,
video: {
aspectRatio: { ideal: 1.7777777778 },
width: { ideal: 1280, max: 1920 },
height: { ideal: 720, max: 1080 },
}
}).then(camera => {
merger.addStream(camera, { x: 0, y: 0, width: 1366, height: 768 });
merger.addMediaElement('circle', document.getElementById('video'), {
draw: (ctx, frame, done) => {
const x = 0, y = 0, width = 426, height = 240;
ctx.save();
ctx.beginPath();
ctx.arc(height/2 + 50, merger.height - (height/2 + 50), height/2, 0, Math.PI*2, true);
ctx.closePath();
ctx.clip();
ctx.drawImage(frame, x, merger.height - (height + 50), width, height);
ctx.restore();
done();
}
});
merger.start();
recorder = new MediaRecorder(merger.result, { mimeType: codec });
recorder.start();
// usual logic for saving
recorder.ondataavailable = chunk => {}
And while recording I flip the source of video. Next videos play as expected.
I can even hear the sound of the next video when replaying the file recorded using this code.
Moreover, the circular video is shown during the whole time webcam is recorded.
But after playing the first video it seems frozen at the last frame of the first video.
from video-stream-merger.
Thomas, I was able to get the circular video updated using this outside getUserMedia
:
merger.removeStream('circle');
merger.addMediaElement('circle', document.getElementById('video'), {
draw: (ctx, frame, done) => {
// same as inside getUserMedia()
}
});
Not sure if this is optimal to do it each time I swap the video source?
from video-stream-merger.
Also when removing the stream I can see circle video blinking for a fraction of a second.
It plays the first video, then disappears and then appears with the new video again.
So is it safe to just call addMediaElement('circle', {})
without prior removing it?
Would it spawn additional media streams or just overwrite the existing with the same name?
from video-stream-merger.
Adding the stream repeatedly without removing it will create new streams and leak memory.
from video-stream-merger.
Got it, Thomas, thank you so much for your support!
from video-stream-merger.
Related Issues (20)
- `.webm` video merge failed
- download merger.result with nodejs HOT 1
- Can I merge in an RTMP stream, instead of WebRTC?
- Crossfade between streams HOT 1
- adding more than two media streams do not work HOT 2
- Safari 14 support. HOT 5
- use OffscreenCanvas in supported browsers HOT 2
- How to merge the audio from different video streams? HOT 1
- Need to handle merger.destroy to remove audio hack also from background HOT 1
- When trying to addStream() yPosition not working HOT 4
- use AudioEffect to use GainNode to amplify gain value
- Trying to add corner radius on addStream() camera HOT 6
- Constructor should use Partial<ConstructorOptions >
- upgrade to 4.01 with problems HOT 3
- production status HOT 1
- Black Screen on iOS browsers HOT 4
- Example from README not working HOT 2
- index.html: Failed to execute 'connect' on 'AudioNode': cannot connect HOT 1
- Types not working (using complete types instead of partials)
- request: don't hardcode framerate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from video-stream-merger.