diff --git a/Live/src/main/java/com/frank/live/camera/Camera2Helper.java b/Live/src/main/java/com/frank/live/camera/Camera2Helper.java index ac7fdb2..20fdfbe 100644 --- a/Live/src/main/java/com/frank/live/camera/Camera2Helper.java +++ b/Live/src/main/java/com/frank/live/camera/Camera2Helper.java @@ -593,6 +593,10 @@ public class Camera2Helper { } else { YUVUtil.YUV420pRotate180(dstData, yuvData, width, height); } + // front camera need to flip + if (CAMERA_ID_FRONT.equals(mCameraId)) { + YUVUtil.flipYUV(dstData, width, height, rotation == 90, rotation == 180); + } if (camera2Listener != null) { camera2Listener.onPreviewFrame(dstData); } diff --git a/Live/src/main/java/com/frank/live/util/YUVUtil.java b/Live/src/main/java/com/frank/live/util/YUVUtil.java index 4d94d1b..0f9591f 100644 --- a/Live/src/main/java/com/frank/live/util/YUVUtil.java +++ b/Live/src/main/java/com/frank/live/util/YUVUtil.java @@ -126,4 +126,29 @@ public class YUVUtil { } } + private static void swap(byte[] a, int i, int j) { + byte temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + + public static void flipYUV(byte[] dst, int width, int height, boolean flipX, boolean flipY) { + if (dst == null || width <= 0 || height <= 0) + return; + if (flipY) { + for (int i=0; i> 8 + 128 // V = (112 * R - 94 * G - 18 * B) >> 8 + 128 -static void rgba_to_yuv420p(int *argb, int8_t *yuv, int width, int height) { +static void rgba_to_yuv420p(const int *argb, int8_t *yuv, int width, int height) { int frameSize = width * height; int index = 0; int yIndex = 0; diff --git a/app/src/main/cpp/yuv/yuv_converter.h b/app/src/main/cpp/yuv/yuv_converter.h index f02224f..491d312 100644 --- a/app/src/main/cpp/yuv/yuv_converter.h +++ b/app/src/main/cpp/yuv/yuv_converter.h @@ -7,7 +7,7 @@ #include -static void rgba_to_yuv420p(int *argb, int8_t *yuv, int width, int height); +static void rgba_to_yuv420p(const int *argb, int8_t *yuv, int width, int height); static void yuv420p_to_argb(const int8_t *yuv, int *argb, int width, int height); diff --git a/picture/ffmpeg_group.png b/picture/ffmpeg_group.png index fc7656e..cfb815d 100644 Binary files a/picture/ffmpeg_group.png and b/picture/ffmpeg_group.png differ