Webcam capture code are below:
Dim capturesource As New CaptureSource
' Get the default video capture device
Dim _videoCaptureDevice As VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()
Dim _AudioCaptureDevice As AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice()
'Dim activeFile As New IsolatedStorageFile
Dim _isf As IsolatedStorageFile
Public Sub New()
InitializeComponent()
AddHandler capturesource.CaptureImageCompleted, AddressOf CaptureImageCompleted
End Sub
Private Sub VideoCapture_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
If _videoCaptureDevice Is Nothing Then
btnPlayCapture.IsEnabled = False
btnStopCapture.IsEnabled = False
btnCaptureDevice.IsEnabled = True
MessageBox.Show("You don't have any default capture device")
Else
btnPlayCapture.IsEnabled = False
btnStopCapture.IsEnabled = True
'Set the Capture Source to the VideoBrush of the rectangle
'capturesource.Start()
capturesource.VideoCaptureDevice = _videoCaptureDevice
capturesource.AudioCaptureDevice = _AudioCaptureDevice
Dim videoBrush As New VideoBrush()
videoBrush.SetSource(capturesource)
rectWebCamView.Fill = videoBrush
If CaptureDeviceConfiguration.AllowedDeviceAccess OrElse CaptureDeviceConfiguration.RequestDeviceAccess() Then
btnPlayCapture.IsEnabled = True
btnStopCapture.IsEnabled = False
btnCaptureDevice.IsEnabled = False
End If
End If
End Sub
Private Sub btnPlayCapture_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnPlayCapture.Click
If Not capturesource.State = CaptureState.Started Then
capturesource.Start()
End If
btnPlayCapture.IsEnabled = False
btnStopCapture.IsEnabled = True
End Sub
Private Sub btnStopCapture_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnStopCapture.Click
capturesource.Stop()
btnPlayCapture.IsEnabled = True
btnStopCapture.IsEnabled = False
End Sub
Public Sub CaptureImageCompleted(ByVal sender As System.Object, ByVal e As CaptureImageCompletedEventArgs)
capturesource.CaptureImageAsync()
Dim sfd As New SaveFileDialog()
If CBool(sfd.ShowDialog()) Then
'Dim sr As New StreamReader(e.Result)
'Dim str As String = sr.ReadToEnd()
'Dim sw As New StreamWriter(sfd.OpenFile())
'sw.Write(str)
End If
End Sub
I have webcam capture code. its working perfect. But i need to make the video and save to server. I need some option or method in silverlight. I Finding most code in web
like:
Capture Image – http://www.silverlight.net/learn/graphics/webcam-and-mic/webcams-%28silverlight-quickstart%29
Most Blog and site link this one only:
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/12/28/silverlight-4-yet-more-on-capturing-video-from-webcams.aspx
Its good code But won’t work and complex to understand.. Any one teach me that one!
how to make WEBCAM RECORD?
How to Make the RECORD file saving with particular format?
If you don’t want to write your own “video encoding code” (they are not very much fun to write, trust me) you have to wait for Silverlight 5. Because Silverlight 4 doesn’t have any native video encoding libray, or method or whatever it is. And that “complex” piece of code of Mike Taulty’s is written in MVVM pattern, but it should not be a hurdle since you already know how to Start the Cam. Now, to generate a simple .avi file (of insanely monstrous size) all you need is the logic inside the “OnStartStopRecord” method of the MainViewModel, which you should put inside your Recording button’s event handler. Oh, and don’t forget to include the “Recording” folder & the files inside it. 🙂