How to change the resolution of camera while recording video in WP8

ⅰ亾dé卋堺 提交于 2019-12-02 08:22:13

问题


I am using the video recording sample provided by microsoft here. I want to change the resolution of the video being recorded in my app. Currently its recording in highest resolution by default. How to do so?

videoCaptureDevice.DesiredFormat = new VideoFormat(PixelFormatType.Unknown, 480, 640, 30);

The above statement is throwing Argument Exception.

Also, if possible let me know how to capture from the front camera?

How to achieve this? Please help.


回答1:


Second parameter for AudioVideoCaptureDevice.OpenAsync is the resolution. And you can get the resolutions using AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensor).




回答2:


You may try this one.

private AudioVideoCaptureDevice VideoRecordingDevice;
private Windows.Foundation.Size resolution = new Windows.Foundation.Size(320, 240);
VideoRecordingDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, resolution);

NB: Remember that it may only used for wp8 or later version.




回答3:


The Solution is (With my knowledge)

     VideoCaptureDevice webcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

 int videoformatcount = webcam.SupportedFormats.Count(); //We will get the avilable video format

  if (videoformatcount > 0)
             {
                var Temp = webcam.SupportedFormats;

                VideoFormat objVideoFormat = Temp[videoformatcount - 1];

                webcam.DesiredFormat = new VideoFormat(PixelFormatType.Format8bppGrayscale, objVideoFormat.PixelWidth, objVideoFormat.PixelHeight, 1);
            }

captureSource.VideoCaptureDevice = webcam;

This will produce the lowest resolution video




回答4:


Use AudioVideoCaptureDevice to recoed video

StorageFolder isoStore = await ApplicationData.Current.LocalFolder.GetFolderAsync("Shared");
            var file = await isoStore.CreateFileAsync("foos1.wmv", CreationCollisionOption.ReplaceExisting);
            using (var s = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                Windows.Foundation.Size resolution = new Windows.Foundation.Size(640, 480);
                avDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
                    AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).Last());

                VideoBrush videoRecorderBrush = new VideoBrush();
                videoRecorderBrush.SetSource(avDevice);

                viewfinderRectangle.Fill = videoRecorderBrush;

                await avDevice.StartRecordingToStreamAsync(s);

                Thread.Sleep(30000);


                await avDevice.StopRecordingAsync();



            }


            new MediaPlayerLauncher()
            {
                Media = new Uri(file.Path, UriKind.Relative),
            }.Show();


来源:https://stackoverflow.com/questions/17715390/how-to-change-the-resolution-of-camera-while-recording-video-in-wp8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!