CAUTION! The version from master branch actually works but has some issues like a lot of memory consumption and some other issues..
Compiled libyuv Google library and wrapper for it for easy and fast scale, rotate, mirror and convert frames from android Camera2 or CameraX.
- Horizontal and/or vertical scaling.
- Rotating by 90, 180 or 270 degrees.
- Mirror horizontally or vertically.
- Convert android YUV_420_8888 frame to ARGB.
armeabi-v7a, arm64-v8a, x86, x86_64
val yuvUtils = YuvUtils() // getting library instance
val image = ... // getting an image from Camera2 or CameraX api
var yuvFrame = yuvUtils.convertToI420(image) // this step isn't mandatory but it may help you in case if the colors of the output frame (after scale, rotate etc.) are distorted
/* the first way */
val image = ... // getting an image from Camera2 or CameraX api
val scaledWidth = image.width * 2 // getting current width and height
val scaledHeight = image.height * 2 // of the image and for example double them
yuvFrame = yuvUtils.scale(image, scaledWidth, scaledHeight, Constants.FILTER_BOX)
/* the second way here yuvFrame was taken from the yuvUtils.convertToI420 method as showed above */
val scaledWidth = yuvFrame.width * 2 // getting current width and height
val scaledHeight = yuvFrame.height * 2 // of the image and for example double them
yuvFrame = yuvUtils.scale(yuvFrame, scaledWidth, scaledHeight, Constants.FILTER_BOX)
val rotate = Constants.ROTATE_270 // setting the rotation angle
yuvFrame = yuvUtils.rotate(image, rotate)
/* or */
yuvFrame = yuvUtils.rotate(yuvFrame, rotate)
/* for mirror horizontally */
yuvFrame = yuvUtils.mirrorH(image)
/* or */
yuvFrame = yuvUtils.mirrorH(yuvFrame)
/* for mirror vertically */
yuvFrame = yuvUtils.mirrorV(image)
/* or */
yuvFrame = yuvUtils.mirrorV(yuvFrame)
val argbFrame = yuvUtils.yuv420ToArgb(image)
/* or */
val argbFrame = yuvUtils.yuv420ToArgb(yuvFrame)
- app - here you can find a sample app that demonsrates scaling, rotating, mirroring and converting procedures by capturing frames from device's camera.
- yuv - here you can find a C++ class that interacts with libyuv 1759 and JNI wrapper for interacting with it from Java/Kotlin layer.
- yuv.aar - it's a compiled library of yuv module that mentioned above, it placed in a root directory of the project, you can easily add it to your project using gradle dependencies. First you have to place yuv.aar in the libs folder of your project and then add to your build.gradle the following:
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar') // this line is necessary in order to allow gradle to take yuv.aar from "libs" dir
implementation files('libs/yuv.aar') // dependency for yuv.aar library
... // other dependencies
}