如何在 windows phone 8,8.1 中更改默认视频捕获分辨率 [英] how to change the default video capture resolution in windows phone 8,8.1

查看:16
本文介绍了如何在 windows phone 8,8.1 中更改默认视频捕获分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个应用程序,让用户可以选择视频录制的分辨率大小(例如全高清-1920x1080 或 vga-640x480 等)

我正在使用下面的代码,但是当我在 720p 模拟器上运行它时,它显示了其他部分的消息,即相机不支持这个.(当我将值 800,450 更改为 640,480 时,相机开始正常工作)

试试{//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);等待 pops.SetPreviewResolutionAsync(previewResolution);等待 pops.SetCaptureResolutionAsync(captureResolution);}}//}catch (Exception p) { Debug.WriteLine(p.Message);}尝试{如果(弹出!= null){//为取景器创建视频刷videoRecordBrush = new VideoBrush();videoRecordBrush.SetSource(pops);//显示取景器图像viewfinderRectangle.Fill = videoRecordBrush;//显示可用的分辨率消息MessageBox.Show("statrt 录音");MessageBox.Show(pops.PreviewResolution.ToString());MessageBox.Show(pops.CaptureResolution.ToString());}别的{MessageBox.Show("相机不支持此功能");}}捕获(异常前){MessageBox.Show("异常" + ex);}}

这是在视频模式下更改分辨率的正确代码吗?或者还有其他方法吗?

解决方案

在 Windows Phone 8.1 中,您可以更改视频预览纵横比通过更改 MediaCapture.VideoDeviceController 设置捕获的照片.

视频预览是您在实际拍摄照片之前可以从屏幕上看到的相机视图.视频预览和拍摄的照片的纵横比必须相同才能避免奇怪的线条&拍摄照片中的黑条.换句话说,就是确保拍摄的照片与您在屏幕上看到的预览完全相同.

首先,您可以检查 Windows Phone 8.1 中的所有可用分辨率.在下面的代码中,我演示了如何检查可用的分辨率以进行视频预览&拍摄的照片.返回的高度和宽度是您手机可用的分辨率,例如 i=0、高度=1080、宽度=1920 (1920x1080).请在高度和宽度线处调试以检查不同的分辨率.

MediaCapture mediacapture = new MediaCapture();等待 mediacapture.InitializeAsync(new MediaCaptureInitializationSettings{});var previewResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);var photoResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);VideoEncodingProperties allResolutionsAvailable;单位高度、宽度;//在下一行使用调试器检查高度&视频预览分辨率的宽度for (int i = 0; i 

在从上面的 heightwidth 参数检查所有可用分辨率后,您可以使用 .ElementAt 选择您想要的特定分辨率(int) 方法,例如.ElementAt(0)

var selectedPreviewResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).ElementAt(1);var selectedPhotoResolution = mediacapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).ElementAt(1);等待 mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, selectedPreviewResolution);等待 mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, selectedPhotoResolution);//在.xaml中<CaptureElement Name="viewfinder"/>viewfinder.Source = 媒体捕捉;//设置视频预览直立mediacapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);等待 mediacapture.StartPreviewAsync();

为视频预览设置 .ElementAt(i)以相同的纵横比分别拍摄的照片.以下是诺基亚 Lumia 1520 可用的分辨率.

视频预览

  • 我.....高*宽..纵横比
  • 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

拍摄的照片

  • 我....高度*宽度..纵横比
  • 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

最后,如果您想使用视频预览和视频预览可用的最大分辨率拍摄的照片,您可以使用以下代码代替.

//4:3 纵横比的最大分辨率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);//16:9 纵横比的最大分辨率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);等待 mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxPhotoResolution);等待 mediacapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, maxPreviewResolution);

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.)

I am using the code below but when I run this on 720p emulator, it shows the message which is in else part i.e. camera not support this. (when I change the value 800,450 , to 640 ,480 camera start 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);
            }
        }

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.

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. 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, e.g at 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, 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) for Video Preview & Captured Photo separately at the same aspect ratio. Below are the resolutions available for Nokia Lumia 1520.

Video Preview

  • i.....height*width..aspect 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

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,8.1 中更改默认视频捕获分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆