Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement mirrored video feature for createCapture (#6441) #6703

Merged
merged 5 commits into from
Feb 27, 2024

Conversation

Vishal2002
Copy link
Contributor

@Vishal2002 Vishal2002 commented Jan 6, 2024

Resolves #6441

Changes:

  • Added a new feature to create a flipped video using createCapture.
  • Modified the createCapture function to accept a boolean parameter for flipping the video.

Screenshots of the change:

Screenshot 2024-01-06 162132 Screenshot 2024-01-05 234941

PR Checklist

  • npm run lint passes
  • [Inline documentation] is included / updated
  • [Unit tests] are included / updated

Copy link

welcome bot commented Jan 6, 2024

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on! I've added a few comments, let me know what you think!

@@ -2212,7 +2212,7 @@ if (navigator.mediaDevices.getUserMedia === undefined) {
p5.prototype.createCapture = function(...args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the doc comments above this to mention the flipped parameter, and maybe add an example that uses it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will soon update the inline documentation and give a simple good-to-go example.

@@ -2253,6 +2264,9 @@ p5.prototype.createCapture = function(...args) {
if (domElement.width) {
videoEl.width = domElement.width;
videoEl.height = domElement.height;
if (flipped) {
videoEl.elt.style.transform = 'scaleX(-1)';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you call yourCapture.hide() and image(yourCapture, 0, 0) to draw it to the canvas, is it flipped there too? If not, we may need to update the part of the code where media elements draw to their internal canvas and draw it scaled there too (see this comment for details: #6441 (comment))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya that I missed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davepagurek I did it , now it is working with the capture.hide() and image(capture,0,0);

Screenshot 2024-01-10 232633 Screenshot 2024-01-10 232926

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This time i have changed the _ensureCanvas() so that it works fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks great!

src/dom/dom.js Outdated
constraints = arg;
flipped = constraints.flipped || false;
}
else if (typeof arg === 'boolean') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more futureproof to force people to use the settings object (createCapture(VIDEO, { flipped: true })) than to add additional overloads with a boolean argument (createCapture(VIDEO, true)) in case we need to add any other additional boolean settings. How do you feel about taking out this branch?

src/dom/dom.js Outdated
else if (typeof arg === 'object') constraints = arg;
else if (typeof arg === 'function') callback = arg;
else if (typeof arg === 'object') {
constraints = arg;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets passed into getUserMedia below. We might want to extract just the bits we need for constraints so we don't accidentally send extra info in in the future if we add anything to the settings object. Maybe we could do something like this?

constraints = { video: arg.video, audio: arg.audio };

src/dom/dom.js Outdated
if (arg.flipped !== undefined) {
flipped = arg.flipped;
} else {
constraints = arg;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now I think this means we either can provide flipped, or we can provide constraints on the capture size. I think we want to support both at once, but just with the flipped arg removed. Maybe something like:

if (arg.flipped !== undefined) {
  flipped = arg.flipped;
}
constraints = { ...arg };
delete constraints.flipped;

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to go now! Since we've started our release process with a beta build, I'm going to hold off on merging this until after we finish the release so that we don't accidentally introduce new bugs during the testing period. I'll merge this right after that though!

@davepagurek davepagurek mentioned this pull request Feb 22, 2024
3 tasks
src/dom/dom.js Outdated Show resolved Hide resolved
@davepagurek davepagurek merged commit b862aef into processing:main Feb 27, 2024
2 checks passed
@Vishal2002 Vishal2002 deleted the dev-vishal branch March 18, 2024 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support mirrored video for createCapture
2 participants