Java 摄影机参数setRotation()方法不旋转在onPreviewFrame()中接收的帧

Java 摄影机参数setRotation()方法不旋转在onPreviewFrame()中接收的帧,java,android,rotation,video-streaming,android-camera,Java,Android,Rotation,Video Streaming,Android Camera,我拥有扩展SurfaceView并实现Camera.PreviewCallback的自定义视图。我将此视图用作相机预览。还实现了捕获视频帧以缓冲和流式传输它们的功能 当设备的方向改变时,我使用适当的参数调用setRotation() Camera.Parameters parameters = svVideo.getCamera().getParameters(); parameters.setRotation(rotation); svVideo.getCamera().setParamete

我拥有扩展SurfaceView并实现Camera.PreviewCallback的自定义视图。我将此视图用作相机预览。还实现了捕获视频帧以缓冲和流式传输它们的功能

当设备的方向改变时,我使用适当的参数调用setRotation()

Camera.Parameters parameters = svVideo.getCamera().getParameters();
parameters.setRotation(rotation);
svVideo.getCamera().setParameters(parameters);
但遗憾的是,onPreviewFrame()回调中捕获的帧的方向并没有改变。我试图实现的是,若我旋转流媒体设备,发送到其他设备的视频流将相应地旋转

我还试着照了一些改变了旋转角度的照片。setRotation()只影响使用前向相机拍摄的照片的旋转(这很奇怪),从后向相机拍摄的照片根本不受影响

我的问题是:我怎样才能得到正确旋转的帧,用于流媒体,或者自己在回调中旋转它们

以下是我的onPreviewFrame方法:

@Override
public void onPreviewFrame(final byte[] frame, final Camera camera) {
    final long now = System.nanoTime();
    if (outq.remainingCapacity() >= 2 && (now - this.frame) >= 1000000000 / fps) { //Don't encode more then we can handle, and also not more then FPS.
        queueFrameForEncoding(frame, now);
    }
    getEncodedFrames();
    camera.addCallbackBuffer(frame); //Recycle buffer
}

谢谢你的回答。它确实会旋转图像数据,但可能有一些元数据头会弄乱结果。现在,它会生成绿色的流,但我会尝试改进它,使其仅旋转帧数据本身。它看起来没有机会在回调中接收正确旋转的帧,所以我必须手动执行此操作。我将尝试建议的解决方案,或者将预览发送到TextureView,并对其应用旋转矩阵。这样硬件就完成了所有的工作。
byte[] rotatedData = new byte[imgToDecode.length]; 
    for (int y = 0; y < imgHeight; y++) {
        for (int x = 0; x < imgWidth; x++)
            rotatedData[x * imgHeight + imgHeight - y - 1] = imgToDecode[x + y * imgWidth];
    }
int buffer = height;
height = width;
width = buffer;