【问题标题】:how to change the default video capture resolution in windows phone 8,8.1如何更改 windows phone 8,8.1 中的默认视频捕获分辨率
【发布时间】:2014-06-03 11:56:15
【问题描述】:

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

我正在使用下面的代码,但是当我在 720p 模拟器上运行它时,它会显示位于 else 部分的消息,即相机不支持这个。 (当我将值 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);
            }
        }

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

【问题讨论】:

    标签: c# vb.net windows-phone-8 windows-phone


    【解决方案1】:

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

    视频预览是您在实际拍摄照片之前可以从屏幕上看到的相机视图。视频预览和拍摄照片的纵横比必须相同,以避免拍摄照片中出现奇怪的线条和黑条。也就是说,就是要保证拍出来的照片和你在屏幕上看到的预览图一模一样。

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

    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;
            }
    

    从上面的 heightwidth 参数检查所有可用分辨率后,您可以使用 .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();
    

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

    视频预览

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

    拍摄的照片

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

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

    //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);
    

    【讨论】:

    • 同理,录像流的长宽比应该和视频预览流的长宽比一致,这样在录制时预览不会失真。
    【解决方案2】:

    如果您想对录制的视频进行更多控制,您应该使用新的 Windows Phone 8 API:AudioVideoCaptureDevice,它有一个 SetCaptureResolutionAsync 方法。

    【讨论】:

    • AudioVideoCaptureDevice 类,SetCaptureResolutionAsync 方法,在我上面的代码中使用,但仍然没有获得像 1920x1080 这样的所需分辨率,它显示默认分辨率,即。 640x480
    • 您在哪个设备上测试?它可能取决于相机/设备分辨率。看看吧
    • 我在 hyper-v 上使用 windows phone 720p 模拟器。
    猜你喜欢
    • 2021-10-14
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    • 2013-04-03
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多