Click here to Skip to main content
15,887,596 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.4K   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

 
GeneralRe: Problem Pin
Rickym10-Jun-04 1:49
Rickym10-Jun-04 1:49 
GeneralFTP Problem Pin
Rickym7-Jun-04 8:01
Rickym7-Jun-04 8:01 
QuestionCan this work with photo taken using pocket pc or smartphone? Pin
fionalee24-Apr-04 6:31
fionalee24-Apr-04 6:31 
AnswerRe: Can this work with photo taken using pocket pc or smartphone? Pin
ThaBean4-Dec-04 3:43
ThaBean4-Dec-04 3:43 
GeneralChanging resolution of incoming video stream without using DsUtils.ShowCapPinDialog Pin
alexhongkong14-Mar-04 17:03
alexhongkong14-Mar-04 17:03 
GeneralRe: Changing resolution of incoming video stream without using DsUtils.ShowCapPinDialog Pin
jerfypowell15-Jan-05 18:28
jerfypowell15-Jan-05 18:28 
GeneralRe: Changing resolution of incoming video stream without using DsUtils.ShowCapPinDialog Pin
lgs.lsg30-Jan-05 18:28
lgs.lsg30-Jan-05 18:28 
QuestionCan this do any better than 1fps? Pin
Juzzam29-Oct-03 8:20
Juzzam29-Oct-03 8:20 
AnswerNevermind I figured it out Pin
Juzzam29-Oct-03 13:11
Juzzam29-Oct-03 13:11 
GeneralRe: Nevermind I figured it out Pin
Ark9-Mar-04 6:47
Ark9-Mar-04 6:47 
Generali also want the source code Pin
kkyirui20-Dec-04 16:06
kkyirui20-Dec-04 16:06 
GeneralRe: Nevermind I figured it out Pin
lunarseacow21-Nov-08 1:09
lunarseacow21-Nov-08 1:09 
QuestionCan this be run on Windows 98? Pin
Juzzam29-Oct-03 6:47
Juzzam29-Oct-03 6:47 
GeneralNeed help getting it to work Pin
Juzzam28-Oct-03 19:04
Juzzam28-Oct-03 19:04 
GeneralRe: Need help getting it to work Pin
Juzzam28-Oct-03 19:33
Juzzam28-Oct-03 19:33 
QuestionWatched Threads? Pin
m2N24-Oct-03 2:47
m2N24-Oct-03 2:47 
AnswerRe: Watched Threads? Pin
m2N24-Oct-03 4:41
m2N24-Oct-03 4:41 
GeneralFtpClient Pin
El Dorko28-Apr-03 5:28
El Dorko28-Apr-03 5:28 
GeneralRe: FtpClient Pin
Someone54383-Jun-03 22:31
Someone54383-Jun-03 22:31 
GeneralRe: FtpClient Pin
Ian Turner (syzygy)4-Jun-03 1:03
sussIan Turner (syzygy)4-Jun-03 1:03 
GeneralRe: FtpClient Pin
Craig Arnold22-Jul-03 1:30
Craig Arnold22-Jul-03 1:30 
GeneralRe: FtpClient Pin
Craig Arnold22-Jul-03 3:03
Craig Arnold22-Jul-03 3:03 
GeneralMultiple calls to Capture Pin
robotech11-Apr-03 16:32
robotech11-Apr-03 16:32 
GeneralRe: Multiple calls to Capture Pin
Dan Glass14-Apr-03 5:51
Dan Glass14-Apr-03 5:51 
GeneralRe: Multiple calls to Capture Pin
Philip Fitzsimons20-Jul-03 8:38
Philip Fitzsimons20-Jul-03 8:38 

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.