Fix video snapshot overlay rotation for Camera2 only

pull/502/head
Mattia Iavarone 6 years ago
parent ed34c67ef0
commit e83206be7a
  1. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  2. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  3. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/video/SnapshotVideoRecorder.java
  4. 7
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/TextureMediaEncoder.java
  5. 2
      demo/src/main/res/layout/activity_camera.xml

@ -372,7 +372,7 @@ public class Camera1Engine extends CameraEngine implements
LOG.i("onTakeVideoSnapshot", "rotation:", stub.rotation, "size:", stub.size);
// Start.
mVideoRecorder = new SnapshotVideoRecorder(Camera1Engine.this, glPreview, getOverlay());
mVideoRecorder = new SnapshotVideoRecorder(Camera1Engine.this, glPreview, getOverlay(), stub.rotation);
mVideoRecorder.start(stub);
}

@ -707,9 +707,9 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
outputSize = new Size(outputCrop.width(), outputCrop.height());
stub.size = outputSize;
// Vertical: 0 (270-0-0)
// Left (unlocked): 270 (270-90-270)
// Right (unlocked): 90 (270-270-90)
// Upside down (unlocked): 180 (270-180-180)
// Left (unlocked): 270 (270-90-270)
// Right (unlocked): 90 (270-270-90)
// Upside down (unlocked): 180 (270-180-180)
// Left (locked): 270 (270-0-270)
// Right (locked): 90 (270-0-90)
// Upside down (locked): 180 (270-0-180)
@ -719,7 +719,9 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
LOG.i("onTakeVideoSnapshot", "rotation:", stub.rotation, "size:", stub.size);
// Start.
mVideoRecorder = new SnapshotVideoRecorder(this, glPreview, getOverlay());
// The overlay rotation should alway be VIEW-OUTPUT, just liek Camera1Engine.
int overlayRotation = getAngles().offset(Reference.VIEW, Reference.OUTPUT, Axis.ABSOLUTE);
mVideoRecorder = new SnapshotVideoRecorder(this, glPreview, getOverlay(), overlayRotation);
mVideoRecorder.start(stub);
}

@ -62,15 +62,18 @@ public class SnapshotVideoRecorder extends VideoRecorder implements RendererFram
private Surface mOverlaySurface;
private Overlay mOverlay;
private boolean mHasOverlay;
private int mOverlayRotation;
public SnapshotVideoRecorder(@NonNull CameraEngine engine,
@NonNull GlCameraPreview preview,
@Nullable Overlay overlay) {
@Nullable Overlay overlay,
int overlayRotation) {
super(engine);
mPreview = preview;
mEngine = engine;
mOverlay = overlay;
mHasOverlay = overlay != null;
mOverlayRotation = overlayRotation;
}
@Override
@ -129,6 +132,7 @@ public class SnapshotVideoRecorder extends VideoRecorder implements RendererFram
mResult.rotation,
type, mTextureId,
mHasOverlay ? mOverlayTextureId : TextureMediaEncoder.NO_TEXTURE,
mOverlayRotation,
scaleX, scaleY,
mFlipped,
EGL14.eglGetCurrentContext()

@ -34,15 +34,18 @@ public class TextureMediaEncoder extends VideoMediaEncoder<TextureMediaEncoder.C
boolean scaleFlipped;
EGLContext eglContext;
int transformRotation;
int overlayTransformRotation;
public Config(int width, int height, int bitRate, int frameRate, int rotation, String mimeType,
int textureId, int overlayTextureId, float scaleX, float scaleY, boolean scaleFlipped, EGLContext eglContext) {
int textureId, int overlayTextureId, int overlayTransformRotation,
float scaleX, float scaleY, boolean scaleFlipped, EGLContext eglContext) {
// We rotate the texture using transformRotation. Pass rotation=0 to super so that
// no rotation metadata is written into the output file.
super(width, height, bitRate, frameRate, 0, mimeType);
this.transformRotation = rotation;
this.textureId = textureId;
this.overlayTextureId = overlayTextureId;
this.overlayTransformRotation = overlayTransformRotation;
this.scaleX = scaleX;
this.scaleY = scaleY;
this.scaleFlipped = scaleFlipped;
@ -140,7 +143,7 @@ public class TextureMediaEncoder extends VideoMediaEncoder<TextureMediaEncoder.C
boolean hasOverlay = mConfig.overlayTextureId != NO_TEXTURE;
if (hasOverlay) {
Matrix.translateM(overlayTransform, 0, 0.5F, 0.5F, 0);
Matrix.rotateM(overlayTransform, 0, mConfig.transformRotation, 0, 0, 1);
Matrix.rotateM(overlayTransform, 0, mConfig.overlayTransformRotation, 0, 0, 1);
Matrix.translateM(overlayTransform, 0, -0.5F, -0.5F, 0);
}

@ -17,7 +17,7 @@
android:layout_marginBottom="88dp"
android:keepScreenOn="true"
app:cameraExperimental="true"
app:cameraEngine="camera2"
app:cameraEngine="camera1"
app:cameraPreview="glSurface"
app:cameraPlaySounds="true"
app:cameraGrid="off"

Loading…
Cancel
Save