Click here to Skip to main content
15,886,689 members
Articles / Programming Languages / C#
Article

C# WebCam Service with FTP and Installer

Rate me:
Please Sign up or sign in to vote.
4.68/5 (29 votes)
31 Mar 20032 min read 385.2K   3.2K   143   91
C# WebCam Windows Service with FTP upload, Windows Service Installer, and file rotation.

Introduction

I got tired looking for an app to write a snap shot from my camera to disk; that was free, no ad ware and with no advertising on the image. I found a guy who wrapped the DirectX Library in C# - WHAT A CHAMP! Here's a link to his article. Anyway, he has a full library called DShowNET and I called into that, made a Windows service that always runs when my PC is on. I added a full FTP library that is extended from the work by Jaimon Mathew.

Overview

This package comes as a project and a DLL (DShowNET). It has the following files:

  • WebCamService.cs
  • FtpClient.cs
  • Capture.cs
  • WebCamInstaller.cs

Now, using the DShowNET library is a little tricky, and just to get a photo out of the web cam tool some 400 lines of code are required. I extended the Sample Grabber supplied with DShowNET and added the reset event so that the photo could be taken synchronously.

The worst problem was making it stable, but this has been running on my workstation now for 20+ days without a restart. The most important code for stability is in the CloseInterfaces method - note the extensive try/catches - everything must be cleaned up, otherwise strange errors (including blue screens) will be observed.

The FTP library I extended, so I could use it as a full featured FTP client. I have added it to this project so I can upload files to the server.

Requirements

  • DirectX 8.1
  • .NET Framework
  • Visual Studio .NET (if you plan to edit it of course)
  • A Windows OS that supports Windows Services (2K,XP)
  • Any DirectX supported Video in device (Tuner, Capture, Camera etc...)
  • 5 Minutes of your time

Setup

The Installer component is used to install the service with the command:

C:\>installutil.exe D:\projects\webcam\webcamservice\bin\debug\webcamservice.exe

You will also need to edit the config file to reflect your needs:

XML
<add key="path" value="D:\Projects\WebCamService\out\WebCam.jpg"/>
<add key="CaptureCycleSeconds" value="10"/>
<add key="KeepOldImageCount" value="20"/>
<add key="FtpServer" value="???"/>
<add key="FtpUserName" value="???"/>
<add key="FtpPassword" value="???"/>
  • path is where you wish to upload the picture to.
  • CaptureCycleSeconds is how long to wait before taking another photo (add in capture time to 11+ seconds)
  • KeepOldImageCount is to hold the last n photos taken

The rest are pretty explanatory.

Now you cans start and stop the service with the following commands:

net start WebCamService
net stop WebCamService

The service will run in the background, and be started when your machine boots, NOT when you login.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect support.com
Australia Australia

Comments and Discussions

 
AnswerRe: Damn this so nearly works... Pin
Martijn Stegeman13-Mar-06 4:49
Martijn Stegeman13-Mar-06 4:49 
Jokeerror in errorlog .... Pin
codemanloyd2-Dec-05 5:20
codemanloyd2-Dec-05 5:20 
GeneralCapture only one time Pin
Huu Long1-Nov-05 23:40
Huu Long1-Nov-05 23:40 
GeneralRe: Capture only one time Pin
argrithmag20-May-06 17:36
argrithmag20-May-06 17:36 
GeneralError in errorlog Pin
dakdog32031-Aug-05 15:01
dakdog32031-Aug-05 15:01 
GeneralRe: Error in errorlog Pin
lgs.lsg2-Sep-05 11:57
lgs.lsg2-Sep-05 11:57 
GeneralRe: Error in errorlog Pin
Member 11156535-Sep-05 16:30
Member 11156535-Sep-05 16:30 
GeneralRe: Error in errorlog Pin
lgs.lsg5-Sep-05 16:36
lgs.lsg5-Sep-05 16:36 
Since I am not seeing the error, I can't say for certain how to fix it. Did you try my suggestion?
GeneralRe: Error in errorlog Pin
RussellZ7-Nov-05 11:19
RussellZ7-Nov-05 11:19 
GeneralRe: Error in errorlog Pin
lgs.lsg8-Nov-05 15:04
lgs.lsg8-Nov-05 15:04 
GeneralRe: Error in errorlog Pin
dakdog32014-Nov-05 15:03
dakdog32014-Nov-05 15:03 
GeneralStreaming to a form Pin
eRRaTuM3-Feb-05 3:38
eRRaTuM3-Feb-05 3:38 
GeneralRe: Streaming to a form Pin
lgs.lsg5-Feb-05 13:38
lgs.lsg5-Feb-05 13:38 
Generalconnecting to an Encoder application Pin
yaya10124-Dec-04 22:52
yaya10124-Dec-04 22:52 
GeneralRe: connecting to an Encoder application Pin
lgs.lsg29-Dec-04 19:56
lgs.lsg29-Dec-04 19:56 
GeneralRefreshing rate not fast enough Pin
Anonymous20-Dec-04 14:24
Anonymous20-Dec-04 14:24 
GeneralRe: Refreshing rate not fast enough Pin
lgs.lsg29-Dec-04 19:53
lgs.lsg29-Dec-04 19:53 
GeneralCompilation Pb Pin
odinette9-Dec-04 1:30
odinette9-Dec-04 1:30 
GeneralVidoe Cam Server Pin
Raymond Pang25-Nov-04 21:51
Raymond Pang25-Nov-04 21:51 
GeneralI'm impressed Pin
Rick Graham9-Nov-04 11:54
Rick Graham9-Nov-04 11:54 
GeneralSolution to &quot;Too many callback..&quot; error reports Pin
Bill Seddon4-Oct-04 23:10
Bill Seddon4-Oct-04 23:10 
GeneralRe: Solution to &quot;Too many callback..&quot; error reports Pin
clemens8119-Jan-06 8:46
clemens8119-Jan-06 8:46 
GeneralRe: Solution to &quot;Too many callback..&quot; error reports Pin
clemens8119-Jan-06 22:04
clemens8119-Jan-06 22:04 
GeneralRe: Solution to &quot;Too many callback..&quot; error reports Pin
clemens8120-Jan-06 8:24
clemens8120-Jan-06 8:24 
GeneralRe: Solution to &quot;Too many callback..&quot; error reports Pin
Martin1138-Feb-06 18:49
Martin1138-Feb-06 18:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.