相机参数 setRotation() 方法不会旋转 onPreviewFrame() 中收到的帧
Camera parameters setRotation() method does not rotate frames recieved in onPreviewFrame()
我有扩展 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
}
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;
我有扩展 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
}
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;