在Windows Phone 8中捕获视频时最小化视频文件大小

时间:2013-07-05 08:48:15

标签: vb.net video windows-phone-8 compression resolution

我正在我的应用中录制视频并将其上传到服务器。该应用程序适用于小型视频,但如果视频超过10秒,则视频大小变得非常大,应用程序崩溃。

如何最小化视频的大小?我可以设置分辨率吗?我还可以压缩视频吗?

你还建议我做些什么来确保视频不是很大?

这是我的代码:

Public Sub InitializeVideoRecorder()
        If captureSource Is Nothing Then
            ' Create the VideoRecorder objects.
            captureSource = New CaptureSource()
            fileSink = New FileSink()

            videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()

            ' Add eventhandlers for captureSource.
            AddHandler captureSource.CaptureFailed, AddressOf OnCaptureFailed

            ' Initialize the camera if it exists on the device.
            If videoCaptureDevice IsNot Nothing Then
                ' Create the VideoBrush for the viewfinder.
                videoRecorderBrush = New VideoBrush()
                videoRecorderBrush.SetSource(captureSource)

                ' Display the viewfinder image on the rectangle.
                viewfinderRectangle.Fill = videoRecorderBrush

                ' Start video capture and display it on the viewfinder.
                captureSource.Start()

                ' Set the button state and the message.
                UpdateUI(ButtonState.Initialized, "")
            Else
                ' Disable buttons when the camera is not supported by the device.
                UpdateUI(ButtonState.CameraNotSupported, "A camera is not supported on this device.")
            End If
        End If
End Sub

1 个答案:

答案 0 :(得分:2)

为了减小视频尺寸,我们可以将分辨率降低。代码

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;

它会帮助你。视频的分辨率必须非常低(可用)。