Silence-GitHub / BBMetalImage

A high performance Swift library for GPU-accelerated image/video processing based on Metal.
MIT License
988 stars 126 forks source link

Mirror video when using front camera #55

Closed blurtime closed 4 years ago

blurtime commented 4 years ago

The resulting video won't be mirrored when the front camera is used - unlike Snapchat, Instagram, etc. do it. I would suggest changing the mirroring when using the front camera. Now, however, the mirroring looks weird while recording so I added a transform to the metalView when the front camera is being used (although I'm sure there are more elegant solutions to achieve this more generally).

blurtime commented 4 years ago

Note: If you add the same code in the init of "BBMetalCamera.swift" and initialize the camera with .front, the video won't be mirrored which is odd (EDIT: in the resulting video file!). After switching twice it will be, though. I have seen some other pods facing the same problem, too, so I'm guessing it is something you cannot influence. My provisional solution is to just initialize with the .back camera which is fine, too.

Silence-GitHub commented 4 years ago

Maybe it's not necessary. To mirror texture, use BBMetalFlipFilter. To mirror BBMetalView for display only, set bb_textureMirroring property to true.

blurtime commented 4 years ago

Well, I guess this is the more elegant solution I was referring to. I'll close the pull request :)

blurtime commented 4 years ago

Important note: I tried the flip filter but found that only the vertical flip would be accounted for in the resulting video file. Therefore, it seems as though the horizontal flip will still have to be achieved by mirroring the connection. You can easily try it out by recording yourself with the flip - applied as in the demo - and keeping your face on the right side of the screen. The resulting file will make it look like you were keeping your face on the left while accounting for the vertical flip. You can choose if you'd like to reopen the pull request.