Inconsistent video preview RRS feed

  • Question

  • I am writing my own custom camera capture UI. I have to be able to host it and control it fully in my application, so I cannot use the WinRT CameraCaptureUI control. I have based my code off the MediaCapture code samples. Generally it works well. However, there are many inconsistencies between hardware environments, and I am wondering how the Windows Camera App can provide such a consistent experience. It seems like there must be APIs that I do not have access to, or that the Camera App must be written at a much lower level.



    Inconsistent data types

    For example, to select the camera resolution, I call GetAvailableMediaStreamProperties(MediaStreamType.Photo) and iterate through the resulting collection of IMediaEncodingProperties objects.

    For the webcams on a Dell Latitude 10 tablet and on a Surface Pro tablet, this is a collection of ImageEncodingProperties. However, for a Logitech C920, the call returns a collection of VideoEncodingProperties--even though I specify MediaStreamType.Photo! I had to write a hack that checks for both cases. But how can I know it will work on all webcams? What other surprises and deviations from the documentation are out there? How does the Windows Camera App handle this?



    Inconsistent video preview behavior

    To set the resolution of the camera, I call SetMediaStreamPropertiesAsync with MediaStreamType.Photo for the tablet webcams and MediaStreamType.VideoPreview (VideoRecord works as well) for the Logitech, along with the highest resolution ImageEncodingProperties or VideoEncodingProperties.

    For the Logitech external webcam AND the Surface Pro, the resolution of the video preview changes along with the selected photo resolution. If the user picks 640x480, then the preview is grainy and the sides are cropped off since it is 4:3 and my other screens are 16:9. If I select a higher resolution, say 1280x720, then the video is sharper and fills my screen as expected.

    BUT, the Dell Latitude webcam preview resolution is ALWAYS 640x480 and ALWAYS fills the screen, which means it has to be zoomed in to fill a 16:9 screen, and is therefore even grainier. When I set the resolution and restart the preview, it does correctly set the resolution because captured still images have the desired resolution. But the video preview is always the same. I have tried calling SetMediaStreamPropertiesAsync with Photo, VideoPreview, and VideoRecord types. All behave the same way.

    The Windows Camera App is somehow able to get, on my problematic Latitude tablet, a very nice, high resolution video preview that is not grainy and is properly shaped depending on the selected resolution's aspect ratio. How does it do this? What APIs is it using to get this clean, consistent experience?

    Thaine Norris

    • Edited by dtnorris Thursday, June 6, 2013 5:26 AM more formatting
    Thursday, June 6, 2013 5:21 AM

All replies

  • This code I use seems to work well with both Surface (RT) and Logitech C920 Pro. I control the on screen camera output size by dynamically sizing a StackPanel that contains the control (rather than getting inconsistent results by allowing it to size itself). I also taking into account aspect ratio (which I have to work out in code as it is missing in many cases...). I use VideoEncodingProperties to get the supported resolutions then use ImageEncodingProperties when I want to capture a photo from the video feed. To capture a photo from the camera I use MediaStreamType.VideoPreview. MediaStreamType.Photo didn't seem to work for me.

    var _resolutionList = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);

    foreach (IMediaEncodingProperties _encodingProperties in _resolutionList)
        var _properties = _encodingProperties as VideoEncodingProperties;
        if (_properties != null)
            // Filter out resolutions less than 640x360
            if (_properties.Width >= 640 && _properties.Height >= 360)
                cameraFeedResolutionList.Add(new VideoResolution(_properties));

    Thursday, June 6, 2013 7:56 AM