@kbabilinski
I sadly am not able to use your proposed solution. It seems to be quite easy to mess up the configuration of the ML Camera. I would appreciate your help with getting the right setup to work.
We currently try to find a recording resolution that best matches 720p. I tried both your solution directly and to modify our existing one accordingly. You can see both code examples below.
This one did not work at all, with video only and with video and image set in the config:
MLCamera.ConnectContext connectContext = MLCamera.ConnectContext.Create();
connectContext.CamId = _identifier;
//MLCamera.Identifier.Main is the only camera that can access the virtual and mixed reality flags
connectContext.Flags = MLCamera.ConnectFlag.MR;
connectContext.EnableVideoStabilization = true; // Also doesn't work with pic+video if false
// For MR
connectContext.MixedRealityConnectInfo = MLCamera.MRConnectInfo.Create();
connectContext.MixedRealityConnectInfo.MRQuality = MLCameraBase.MRQuality._960x720;
connectContext.MixedRealityConnectInfo.MRBlendType = MLCamera.MRBlendType.Additive;
connectContext.MixedRealityConnectInfo.FrameRate = MLCameraBase.CaptureFrameRate._30FPS;
_camera = MLCamera.CreateAndConnect(connectContext);
// ...
//Initialize a new capture config.
var configs = new MLCamera.CaptureStreamConfig[2]
{
new MLCamera.CaptureStreamConfig()
{
OutputFormat = MLCamera.OutputFormat.JPEG,
CaptureType = MLCamera.CaptureType.Image,
Width = 1920,
Height = 1080
},
new MLCamera.CaptureStreamConfig()
{
OutputFormat = MLCamera.OutputFormat.YUV_420_888,
CaptureType = MLCamera.CaptureType.Video,
Width = 1920,
Height = 1080
}
};
// ...
_captureConfig = new MLCamera.CaptureConfig()
{
StreamConfigs = configs,
CaptureFrameRate = MLCamera.CaptureFrameRate._30FPS
};
MLResult result = _camera.PrepareCapture(_captureConfig, out MLCamera.Metadata metaData);
With that code, we always get MLResult_InvalidParam as a return value, even if we only pass a config for image or video respectively.
In the second attempt, which is close to our actual setup, we try to get the best fit for our desired resolution (720p) instead. The code is not that beautiful / a bit redundant. It works if only used for image / video, but not for both:
MLCamera.StreamCapability[] streamCapabilities = MLCamera.GetImageStreamCapabilitiesForCamera(_camera, MLCameraBase.CaptureType.Video);
MLCamera.StreamCapability[] streamCapabilitiesPhoto = MLCamera.GetImageStreamCapabilitiesForCamera(_camera, MLCameraBase.CaptureType.Image);
if (streamCapabilities.Length == 0 || streamCapabilitiesPhoto.Length == 0)
return;
//Set the default capability stream
MLCamera.StreamCapability defaultCapability = streamCapabilities[0];
MLCamera.StreamCapability defaultCapabilityPhoto = streamCapabilitiesPhoto[0];
//Try to get the stream that most closely matches the target width and height
if (MLCamera.TryGetBestFitStreamCapabilityFromCollection(streamCapabilities, captureWidth, captureHeight,
MLCameraBase.CaptureType.Video, out MLCamera.StreamCapability selectedCapability))
{
defaultCapability = selectedCapability;
}
if (MLCamera.TryGetBestFitStreamCapabilityFromCollection(streamCapabilitiesPhoto, captureWidth, captureHeight,
MLCameraBase.CaptureType.Image, out MLCamera.StreamCapability selectedCapabilityPhoto))
{
defaultCapabilityPhoto = selectedCapabilityPhoto;
}
//Initialize a new capture config.
var configs = new MLCamera.CaptureStreamConfig[2]
{
new MLCamera.CaptureStreamConfig()
{
OutputFormat = MLCamera.OutputFormat.RGBA_8888,
CaptureType = MLCamera.CaptureType.Video,
Width = defaultCapability.Width,
Height = defaultCapability.Height
},
new MLCamera.CaptureStreamConfig()
{
OutputFormat = MLCamera.OutputFormat.JPEG,
CaptureType = MLCamera.CaptureType.Image,
Width = defaultCapabilityPhoto.Width,
Height = defaultCapabilityPhoto.Height
}
};
_captureConfig = new MLCamera.CaptureConfig()
{
StreamConfigs = configs,
CaptureFrameRate = MLCamera.CaptureFrameRate._30FPS
};
We are thus still not sure how to enable both video and photo capture. Currently, we just use a frame of the video stream instead, but ideally we would like to take a higher resolution picture.