HarmonyOS 屏幕录制使用OH\_AVScreenCapture\_SetCallback中onVideoBufferAvailable获取的RGBA数据不正确?

OH\_AVScreenCapture\_SetCallback,获取的RGBA数据保存不对,希望获取正确的RGBA数据方法(ffplay -f rawvideo -pixel\_format rgba -video\_size 720x1280 -i test.rgba)。

阅读 494
1 个回答

onVideoBufferAvailable接口已废弃,建议使用新接口:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/\_a\_v\_screen\_capture-V5\#oh\_avscreencapture\_onbufferavailable

获取的RGBA数据不正确,可能是使用的方式有问题,可参考以下demo示例:

static napi_value StartScreenCapture_02(napi_env env, napi_callback_info info) {
  g_avCapture = OH_AVScreenCapture_Create();
  if (g_avCapture == nullptr) {
    OH_LOG_ERROR(LOG_APP, "create screen capture failed");
  }
  OH_AVScreenCaptureConfig config_;

  OH_RecorderInfo recorderInfo;
  const std::string SCREEN_CAPTURE_ROOT = "/data/storage/el2/base/files/";
  int32_t outputFd = open((SCREEN_CAPTURE_ROOT + "screen01.mp4").c_str(), O_RDWR | O_CREAT, 0777);
  std::string fileUrl = "fd://" + std::to_string(outputFd);
  recorderInfo.url = const_cast<char *>(fileUrl.c_str());
  recorderInfo.fileFormat = OH_ContainerFormatType::CFT_MPEG_4;
  OH_LOG_INFO(LOG_APP, "==DEMO== ScreenCapture fileUrl %{public}s", fileUrl.c_str());

  SetConfig(config_);
  config_.captureMode = OH_CAPTURE_HOME_SCREEN;
  config_.dataType = OH_CAPTURE_FILE;
  config_.recorderInfo = recorderInfo;
  bool isMicrophone = true;
  OH_AVScreenCapture_SetMicrophoneEnabled(g_avCapture, isMicrophone);
  OH_AVScreenCapture_SetStateCallback(g_avCapture, OnStateChange, nullptr);

  OH_AVSCREEN_CAPTURE_ErrCode result = OH_AVScreenCapture_Init(g_avCapture, config_);
  if (result != AV_SCREEN_CAPTURE_ERR_OK) {
    OH_LOG_INFO(LOG_APP, "==DEMO== ScreenCapture OH_AVScreenCapture_Init failed %{public}d", result);
  }
  OH_LOG_INFO(LOG_APP, "==DEMO== ScreenCapture OH_AVScreenCapture_Init %{public}d", result);

  result = OH_AVScreenCapture_StartScreenRecording(g_avCapture);
  if (result != AV_SCREEN_CAPTURE_ERR_OK) {
    OH_LOG_INFO(LOG_APP, "==DEMO== ScreenCapture Started failed %{public}d", result);
    OH_AVScreenCapture_Release(g_avCapture);
  }
  OH_LOG_INFO(LOG_APP, "==DEMO== ScreenCapture Started %{public}d", result);

  m_scSaveFileIsRunning = true;
  napi_value res;
  napi_create_int32(env, result, &res);
  return res;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进