HarmonyOS 屏幕录制使用OH_AVScreenCapture_SetCallback中onVideoBufferAvailable获取的RGBA数据不正确

OH_AVScreenCapture_SetCallback,获取的RGBA数据保存不对,希望获取正确的RGBA数据方法(ffplay -f rawvideo -pixel_format rgba -video_size 720x1280 -i test.rgba)。

HarmonyOS
2024-12-25 15:59:20
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

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;
}
分享
微博
QQ
微信
回复
2024-12-25 19:03:34
相关问题
使用lineHeight行间距展示不正确
480浏览 • 1回复 待解决
web页面栈不正确,如何处理?
460浏览 • 1回复 待解决
HarmonyOS 调用OH_LOG_SetCallback接口崩溃
196浏览 • 1回复 待解决