Reputation: 122
I am recording a video in my app and uploading it to a server. The app is working fine for small videos but if the video is longer than 10 seconds the video size becomes very big and the app crashes.
How can I minimize the size of the video? Can I set the resolution? Can I also compress the video?
What else do you recommend I do to make sure the video is not gigantic?
Here is my code :
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
Upvotes: 1
Views: 604
Reputation: 1095
To reduce the video size we can make the resolution as much low.The code
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;
It will help you.The video must be in very low resolution(Available).
Upvotes: 2