Windows Phone 8 provides a robust array of options for video recording, including
AudioVideoCaptureDevice was introduced in Windows Phone 8 and provides an extended set of capabilities and improved performance. Moreover, as it is part of the WinPRT API, it is the only interface that can be called from native code. Details can be found here.
One of the most exciting features of
AudioVideoCaptureDevice is that it provides advanced settings for video recording, such as H.264 encoding level, H.264 encoding profiles, video frame rate, and so on. The full list of supported settings can be found on this MSDN webpage.
In order to set those advanced settings, you’ll need to use
AudioVideoCaptureDevice.SetProperty(). As different devices have different hardware capabilities on the front and rear cameras, you’ll need to check the supported values or ranges before setting the properties to a specific camera on a specific device. You can use
AudioVideoCaptureDevice.GetSupportedPropertyValues for this purpose. In order to check the range or value of a specific property, you will need to know the format of the property and which method to check for supported range or value. You can find the property formats on this MSDN page.
There are some behaviors in the latest AudioVideoCaptureDevice.SetProperty that you should be aware of. These are in the version time-stamped “2013.5.27″, and are subject to change in upcoming releases of Windows Phone 8. However, understanding these will help you be a bit more efficient in your coding.
Let’s start with the basics. First, if you try to set properties before calling
AudioVideoCaptureDevice.OpenAsync, the setting will fail with System.NullReferenceException, which is quite understandable as there is no instance of AudioVideoCaptureDevice constructed yet.
Secondly, most of the video recording settings can be set after
AudioVideoCaptureDevice.OpenAsync, including H264EnableKeyframes, H264EncodingLevel, H264EncodingProfile, H264QuantizationParameter, UnmuteAudioWhileRecording, VideoFrameRate, VideoTorchMode, VideoTorchPower. However, H264RequestDropNextNFrames and H264RequestIdrFrame cannot be set after AudioVideoCaptureDevice.OpenAsync yet, otherwise SetProperty will throw System.InvalidOperationException. These two settings can be set during recording only.
Thirdly, it is important to check the supported ranges or legal values for certain properties. If the values do not fall within the supported ranges or legal values, SetProperty will throw System.ArgumentException. Also note that when using AudioVideoCaptureDevice.GetSupportedPropertyRange, if the returned instance of CameraCapturePropertyRange has the same value for both Max and Min properties, then there is no point of setting the property as it might throw exceptions from some devices in some earlier releases.
AudioVideoCaptureDevice supports two ways to start recording:
StartRecordingToSinkAsync is for native code. If you want to set
H264QuantizationParameter, be sure to use
AudioVideoCaptureDevice grants a rich set of advanced settings to customize video recording. We hope you find these tips and tricks helpful.