1

我正在我的应用程序中录制视频并将其上传到服务器。该应用程序适用于小视频,但如果视频超过 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
4

1 回答 1

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;

它将对您有所帮助。视频的分辨率必须非常低(可用)。

于 2013-07-19T07:38:36.723 回答