MediaCapture: MJPG stream converted to NV12

Saruman the White 26 Reputation points
2021-03-02T18:04:38.877+00:00

I have an UWP (C++/WinRT) application running on Hololens 2, that reads frames from an external camera (USB-attached). I am reading the frames via winrt::Windows::Media::Capture::MediaCapture:
(1) I obtain a winrt::Windows::Media::Capture::Frames::MediaFrameSource for the camera (stream type is MediaStreamType::VideoRecord, source kind is MediaFrameSourceKind::Color).
(2) select a format for the MediaFrameSource, out of its SupportedFormats() for a particular resolution, framerate etc.
(3) then get a MediaFrameReader from the said source
(4) hook on the MediaFrameReader's event FrameArrived and call StartAsync

This works alright - the FrameArrived handler fires at the expected rate, giving me frames. My issue is the following:

  • when I query SupportedFormats in MediaFrameSource, there are formats with MJPG subtype (camera supports this)
  • when I select one of these MJPG formats, the FrameArrived event still fires, but the frame is (internally) converted to NV12

I need to disable this internal conversion to NV12 and retrieve the MJPG frames as generated by the camera.

I have also tried to use Media Foundation, from which I can get the MJPG frames successfully, but only on desktop. On Hololens, the API is limited for some reason, leaving me unable to obtain IMFMediaSource for the webcam. So MF is probably not an option on Hololens 2. Encoding the frames myself from NV12 to JPEG is also not an option, as HL2 does not have enough computational resources to do the required conversions.

Any ideas what else I can do to receive MJPG from the webcam?

Developer technologies | Universal Windows Platform (UWP)
{count} vote

Accepted answer
  1. Rob Caplan - MSFT 6,037 Reputation points Microsoft Employee Moderator
    2021-03-23T23:18:26.497+00:00

    Hi Saruman,

    HoloLens 2 development isn't (yet!) covered on the Q&A forums. For help with HoloLens 2 programming you can open a support ticket at https://aka.ms/mrsupport to work one-on-one with a HoloLens 2 programming specialist.

    External cameras aren't supported on the HoloLens 2, so the behavior from one is undefined. See the supported USB classes at https://learn.microsoft.com/en-us/hololens/hololens-connect-devices#hololens-2-connect-usb-c-devices

    Even with the onboard camera, I'd expect only the uncompressed & YUV formats (see https://learn.microsoft.com/en-us/windows/win32/medfound/video-subtype-guids) to be available at the MediaFrameReader level, not encoded formats such as MJPG.

    You can get MJPG output by capturing to a custom sink. The pipeline will encode it before calling your sink.

    Media capture is very complicated and there may be a better way to get to your end goal. If you'd like to discuss this with a HoloLens 2 media specialist please open a case at https://aka.ms/mrsupport

    --Rob


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.