HarmonyOS 鸿蒙Next中surface模式下对相机流视频编码可以设置输出帧的方向么,目前看输出的帧都是90度旋转的

HarmonyOS 鸿蒙Next中surface模式下对相机流视频编码可以设置输出帧的方向么,目前看输出的帧都是90度旋转的

encoderVideoOutput = cameraManager.createVideoOutput(videoProfile, params.surfaceId);

// Create a preview stream output object
XComponentPreviewOutput = cameraManager.createPreviewOutput(XComponentPreviewProfile, this.XComponentSurfaceId);
// Create the cameraInput object.
try {
  cameraInput = cameraManager.createCameraInput(cameraDevices[cameraIndex!=null?cameraIndex:0]);
} catch (error) {
  let err = error as BusinessError;
  Logger.error(TAG, `Failed to createCameraInput. error: ${JSON.stringify(err)}`);
}
try {
  await cameraInput.open();
} catch (error) {
  let err = error as BusinessError;
  Logger.error(TAG, `Failed to open cameraInput. error: ${JSON.stringify(err)}`);
}

// Session flow.
try {
  videoSession = cameraManager.createSession(camera.SceneMode.NORMAL_VIDEO) as camera.VideoSession;
} catch (error) {
  let err = error as BusinessError;
  Logger.error(TAG, `Failed to create the session instance. error: ${JSON.stringify(err)}`);
}

try {
  videoSession.beginConfig();
} catch (error) {
  let err = error as BusinessError;
  Logger.error(TAG, `Failed to beginConfig. error: ${JSON.stringify(err)}`);
}

// Add CameraInput to the session.
try {
  videoSession.addInput(cameraInput);
} catch (error) {
  let err = error as BusinessError;
  Logger.error(TAG, `Failed to add cameraInput. error: ${JSON.stringify(err)}`);
}

// Add the XComponent preview stream to the session.
try {
  videoSession.addOutput(XComponentPreviewOutput);
} catch (error) {
  let err = error as BusinessError;
  Logger.error(TAG, `Failed to add XcomponentPreviewOutput. error: ${JSON.stringify(err)}`);
}

// Add the encoder video stream to the session.
try {
  videoSession.addOutput(encoderVideoOutput);
} catch (error) {
  let err = error as BusinessError;
  Logger.error(TAG, `Failed to add encoderVideoOutput. error: ${JSON.stringify(err)}`);
}

更多关于HarmonyOS 鸿蒙Next中surface模式下对相机流视频编码可以设置输出帧的方向么,目前看输出的帧都是90度旋转的的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

在HarmonyOS鸿蒙Next的surface模式下,相机视频编码输出帧的方向由设备传感器和系统默认配置决定。目前输出帧的90度旋转是系统预设行为,通常与设备物理方向相关。鸿蒙的相机API允许通过设置输出参数调整方向,但具体实现需参考鸿蒙的Camera API文档中关于图像方向的配置项。

更多关于HarmonyOS 鸿蒙Next中surface模式下对相机流视频编码可以设置输出帧的方向么,目前看输出的帧都是90度旋转的的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS Next的surface模式下,相机视频编码输出的帧方向默认由设备传感器决定,通常与设备物理方向相关。目前API未直接提供设置输出帧方向的接口。若遇到90度旋转问题,建议在编码后处理阶段通过图像旋转或调整渲染方向来修正。可检查设备方向传感器数据,结合业务逻辑进行动态调整。

回到顶部