This video demonstrates exactly what you need:
how to stream the image of USB webcams (and IP cameras as well) to website in C#[
^]. The following code snippet shows how to
connect to your USB webcam and display its image:
private void ConnectUSBCamera_Click(object sender, RoutedEventArgs e)
{
_webCamera = WebCamera.GetDefaultDevice();
if (_webCamera == null) return;
_connector.Connect(_webCamera, _provider);
_videoSender = _webCamera;
_webCamera.Start();
_videoViewerWpf.Start();
}
And the code example below presents the
implementation of the broadcasting. This solution is based on
MJPEG streaming (
Motion JPEG[
^]):
private void Start_Streaming_Click(object sender, RoutedEventArgs e)
{
var ip = ipAddressText.Text;
var port = PortText.Text;
_streamer = new MJPEGStreamer(ip, int.Parse(port));
_connector.Connect(_videoSender, _streamer.VideoChannel);
_streamer.ClientConnected += streamer_ClientConnected;
_streamer.ClientDisconnected += streamer_ClientDisconnected;
_streamer.Start();
}
void streamer_ClientConnected(object sender, Ozeki.VoIP.VoIPEventArgs<imjpegstreamclient> e)
{
e.Item.StartStreaming();
}
void streamer_ClientDisconnected(object sender, Ozeki.VoIP.VoIPEventArgs<imjpegstreamclient> e)
{
e.Item.StopStreaming();
}
private void Stop_Streaming_Click(object sender, RoutedEventArgs e)
{
_streamer.Stop();
_connector.Disconnect(_videoSender, _streamer.VideoChannel);
}</imjpegstreamclient></imjpegstreamclient>
If you are interested in this solution, I encourage you try out the example program that can be found next to the previously mentioned video and it comes with free source code.