Reputation: 41
I am currently trying to record a video in square shape and create a output as .mp4. It seems to be really challenging. I tried diffrent approches including: OnPreviewFrame and FFMpeg. But never got a satisfing result. Today i found Grafika. And it seems to be the right way. But because of the complextity of the Code i am stuck now. Using the Example: CameraCaptureActivity.java i managed to record a video. But its shape is rectangluar and not square. Furthermore the camera is rotated by 90 degrees. I was already trying to manipulate certain parameters but never got a good video. Some where squeezed and so on.
Does anybody know what parameters i need to change inside Grafikas example to get the right result? In the end the camera of my android phone should record Videos like Vine or Instagram.
Thanks for your help!
Upvotes: 1
Views: 1810
Reputation: 52353
A few notes:
CameraCaptureActivity is complicated because it's trying to use GLSurfaceView (originally to answer this question). ContinuousCaptureActivity is a better choice.
You can't generally constrain the camera preview to an arbitrary shape by setting Camera parameters. You have to accept the image or video frames it gives you, then modify them to look the way you want. In your case, that means stripping off the top/bottom or left/right edges.
I'm pretty sure Instagram is no longer strictly square. So you may be behind the times. :-)
The Grafika code works by feeding the Camera into a SurfaceTexture, which turns the camera frames into GLES textures. You can then render the texture however you like. By selecting a square shape, and modifying the texture coordinates, you can have square video.
The best place to start is with the "texture from camera" Activity. Note in particular the "zoom" feature, which adjusts the texture coordinates to select the inner part of the image. You can modify ScaledDrawable2d#getTexCoordArray()
to map the inner portion of the frame, and modify the render code to use a square quad. Feed that into a video encoder.
Upvotes: 1