[英]how to change the default video capture resolution in windows phone 8,8.1
I want build an app that will give users options to choose the resolution size of video recording (such as full HD-1920x1080 or vga-640x480 etc.) 我想构建一个应用程序,该应用程序将为用户提供选择视频录制分辨率大小的选项(例如完整的HD-1920x1080或vga-640x480等)。
I am using the code below but when I run this on 720p emulator, it shows the message which is in else part ie camera not support this. 我正在使用下面的代码,但是当我在720p仿真器上运行此代码时,它显示的消息是其他部分的,即相机不支持此消息。 (when I change the value 800,450 , to 640 ,480 camera start working normally)
(当我将值800,450更改为640,480时,相机开始正常工作)
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);
}
}
Is this right code to change the resolution in video mode? 这是正确的代码,可以在视频模式下更改分辨率吗? or is there any other method?
或还有其他方法吗?
In Windows Phone 8.1, u can change the aspect ratio of both video preview and captured photo by changing the MediaCapture.VideoDeviceController setting. 在Windows电话8.1,U可以通过改变MediaCapture.VideoDeviceController设置更改两个视频预览的纵横比和捕获的照片 。
Video preview is the view of camera you can see from your screen before you actually capture a photo. 视频预览是您在实际拍摄照片之前可以从屏幕上看到的摄像机视图。 It is essential for the aspect ratio of video preview and captured photo to be the same to avoid weird lines & black bars in the captured photo.
必须确保视频预览和捕获的照片的宽高比相同,以避免捕获的照片中出现怪异的线条和黑条 。 In other words, it is to ensure the photo captured to be exactly the same as the preview you see on the screen.
换句话说,这是为了确保捕获的照片与您在屏幕上看到的预览完全相同。
First, you can check all the available resolutions in your Windows Phone 8.1. 首先,您可以检查Windows Phone 8.1中所有可用的分辨率。 In the following code, I demonstrate how to check resolutions available for video preview & captured photo.
在以下代码中,我演示了如何检查可用于视频预览和捕获的照片的分辨率 。 The height&width returned is the resolutions available for your phone, eg at i=0, height=1080, width=1920 (1920x1080).
返回的高度和宽度是您手机可用的分辨率,例如,i = 0,height = 1080,width = 1920(1920x1080)。 Please debug at the height&width line to check for different resolution.
请在高度和宽度线进行调试,以检查不同的分辨率。
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 the available resolutions from the height and width parameter above, you can select the particular resolutions you want by using .ElementAt(int) method, eg .ElementAt(0) 从上面的height和width参数检查了所有可用的分辨率之后,可以使用.ElementAt(int)方法选择所需的特定分辨率 ,例如.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) for Video Preview & Captured Photo separately at the same aspect ratio. 以相同的宽高比分别为视频预览和捕获的照片设置.ElementAt(i)。 Below are the resolutions available for Nokia Lumia 1520.
以下是诺基亚Lumia 1520可用的分辨率。
Video Preview 影片预览
Captured photo 拍摄的照片
Lastly, if you want to use the maximum resolution available for both Video Preview & Captured Photo, you can use the following code instead. 最后,如果您要使用“视频预览”和“捕获的照片”可用的最大分辨率 ,则可以改用以下代码。
//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);
如果要对录制的视频进行更多控制,则应使用新的Windows Phone 8 API: AudioVideoCaptureDevice ,它具有SetCaptureResolutionAsync方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.