首页 > 解决方案 > 为什么 Apple FaceTime 高清摄像头不提供 MJPEG/DMB1 像素格式

问题描述

我一直在尝试部署 CoreMediaIO 框架来捕获 Mac 内置摄像头流:

  OSStatus result;
  UInt32 dataSize;
  CMIOObjectPropertyAddress opa = {kCMIOObjectPropertyClass,
                                   kCMIOObjectPropertyScopeGlobal, 0};

  opa.mSelector = kCMIOStreamPropertyDirection;
  UInt32 direction;
  result = CMIOObjectGetPropertyData(objectID, &opa, 0, NULL, sizeof(UInt32),
                                     &dataSize, &direction);
  if (result != 0) {
    printf("Error getting kCMIOStreamPropertyDirection for stream\n");
    return;
  }
  printf("Stream is %s\n", direction == 0 ? "output" : "input");
  opa.mSelector = kCMIOStreamPropertyFormatDescriptions;
  CFArrayRef streamDescriptions = NULL;
  if (CMIOObjectHasProperty(objectID, &opa)) {
    printf("Stream offers multiple formats\n");
    result =
        CMIOObjectGetPropertyData(objectID, &opa, 0, NULL, sizeof(CFArrayRef),
                                  &dataSize, &streamDescriptions);
    if (result != 0) {
      printf("Error in CMIOObjectGetPropertyData for stream\n");
      return;
    }
  }

令人惊讶的是,只提供了 YUV 格式:

"<CMVideoFormatDescription 0x7fd360c0f970 [0x7fff8b4d1b60]> {\n\tmediaType:'vide' \n\tmediaSubType:'2vuy' \n\tmediaSpecific: {\n\t\tcodecType: '2vuy'\t\tdimensions: 160 x 120 \n\t} \n\textensions: {{\n    CVBytesPerRow = 320;\n    CVFieldCount = 1;\n    CVImageBufferColorPrimaries = \"ITU_R_709_2\";\n    CVImageBufferTransferFunction = \"ITU_R_709_2\";\n    CVImageBufferYCbCrMatrix = \"ITU_R_709_2\";\n    FormatName = \"Y'CbCr 4:2:2 - uyvy\";\n    \"com.apple.cmio.format_extension.video.only_has_i_frames\" = 1;\n}}\n}",

显然,相机传感器硬件确实支持 MJPEG 帧格式。但是为什么它在 CoreMediaIO 框架中不可用呢?

标签: cameravideo-streamingavfoundationmacos-catalina

解决方案


您可能需要编写一个 CMIO 驱动程序来公开 MJPEG 格式


推荐阅读