How to change default video capture resolution in Windows phone 8,8.1
I want to create an application that will give users the ability to choose the size of the video recording resolution (for example, full HD-1920x1080 or vga-640x480, etc.).
I am using the code below, but when I run it on a 720p emulator, it shows a message that is in a different location, meaning the camera does not support this. (when I change the value 800 450 to 640, 480 the camera starts working normally)
try
{
//string deviceName = DeviceStatus.DeviceName;
//var deviceName = DeviceStatus.DeviceName;
//if (deviceName.Contains("RM-885"))
//{
Windows.Foundation.Size initialResolution = new Windows.Foundation.Size(800, 450);
Windows.Foundation.Size previewResolution = new Windows.Foundation.Size(800, 450);
Windows.Foundation.Size captureResolution = new Windows.Foundation.Size(800, 450);
if (AudioVideoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back))
{
pops = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, initialResolution);
await pops.SetPreviewResolutionAsync(previewResolution);
await pops.SetCaptureResolutionAsync(captureResolution);
}
}
// }
catch (Exception p) { Debug.WriteLine(p.Message); }
try
{
if(pops != null)
{
// create the videobrush for the viewfinder
videoRecordBrush = new VideoBrush();
videoRecordBrush.SetSource(pops);
// display the viewfinder image
viewfinderRectangle.Fill = videoRecordBrush;
//shows available resolution message
MessageBox.Show("statrt recording ");
MessageBox.Show(pops.PreviewResolution.ToString());
MessageBox.Show(pops.CaptureResolution.ToString());
}
else
{
MessageBox.Show("camera not support this ");
}
}
catch(Exception ex)
{
MessageBox.Show("exception" + ex);
}
}
Does this correct code allow you to change resolution in video mode? or is there any other method?
source to share
In Windows Phone 8.1, you can change the aspect ratio of both the video preview and the captured photo by changing the MediaCapture.VideoDeviceController parameter.
Video preview is the camera view that you can see from the screen before taking pictures. It is important that the aspect ratio of the video preview and the captured photo is the same for , avoiding strange lines and black bars in the captured photo. In other words, it ensures that the photo taken is exactly the same as the preview you see on the screen.
First, you can check all available permissions on your Windows Phone 8.1. In the following code, I demonstrate how to check the available resolutions for video preview and captured photo. The returned height and width are the resolutions available for your phone, for example when i = 0, height = 1080, width = 1920 (1920x1080). Scan at the height and width lines to check different resolutions.
MediaCapture mediacapture = new MediaCapture();
await mediacapture.InitializeAsync(new MediaCaptureInitializationSettings{});
var previewResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);
var photoResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
VideoEncodingProperties allResolutionsAvailable;
uint height, width;
//use debugger at the following line to check height & width for video preview resolution
for (int i = 0; i < previewResolution.Count; i++)
{
allResolutionsAvailable = previewResolution[i] as VideoEncodingProperties;
height = allResolutionsAvailable.Height;
width = allResolutionsAvailable.Width;
}
//use debugger at the following line to check height & width for captured photo resolution
for (int i = 0; i < photoResolution.Count; i++)
{
allResolutionsAvailable = photoResolution[i] as VideoEncodingProperties;
height = allResolutionsAvailable.Height;
width = allResolutionsAvailable.Width;
}
After checking all available resolutions with the height and width parameter above, you can select specific resolutions using the .ElementAt (int) method, e.g. ..ElementAt (0)
var selectedPreviewResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).ElementAt(1);
var selectedPhotoResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).ElementAt(1);
await mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, selectedPreviewResolution);
await mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, selectedPhotoResolution);
//in .xaml <CaptureElement Name="viewfinder"/>
viewfinder.Source = mediacapture;
//to set video preview upright
mediacapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
await mediacapture.StartPreviewAsync();
Set .ElementAt (i) to preview video and captured image separately with the same aspect ratio. Below are the resolutions available for the Nokia Lumia 1520.
Video preview
- i ..... height * width .. ratio ratio
- 0 ..... 1080 * 1920 .... 16: 9
- 1 ...... 720 * 1280 ..... 16: 9
- 2 ...... 450 * 800 ....... 16: 9
- 3 .... 1080 * 1440 ...... 4: 3
- 4 ...... 768 * 1024 ...... 4: 3
- 5 ...... 480 * 640 ........ 4: 3
Captured photo
- i .... height * width .. aspect ratio
- 0 .... 3024 * 4992 ....... 4: 3
- 1 ..... 1936 * 2592 ... 162: 121
- 2 ..... 1536 * 2048 ....... 4: 3
- 3 ...... 480 * 640 .......... 4: 3
- 4 ..... 3024 * 5376 ..... 16: 9
- 5 ..... 1728 * 3072 ..... 16: 9
- 6 ..... 1456 * 2592 ... 162: 91
Finally, if you want to use the maximum resolution available for both Video Preview and Captured Photo, you can use the following code.
//maximum resolution for 4:3 aspect ratio
var maxPhotoResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Height > (i2 as VideoEncodingProperties).Height ? i1 : i2);
var maxPreviewResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Height > (i2 as VideoEncodingProperties).Height ? i1 : i2);
//maximum resolution for 16:9 aspect ratio
var maxPhotoResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
var maxPreviewResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
await mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxPhotoResolution);
await mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, maxPreviewResolution);
source to share
If you want more control over the recorded video, you should use the new Windows Phone 8 API: AudioVideoCaptureDevice , which has SetCaptureResolutionAsync .
source to share