Click here to Skip to main content
15,867,453 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 383.7K   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

 
GeneralThank you Dan! Pin
Member 105806974-Aug-14 20:01
Member 105806974-Aug-14 20:01 
Questionplease help me quickly to send image to my web site quickly Pin
hansalsal23-Feb-11 21:36
hansalsal23-Feb-11 21:36 
GeneralLicense Pin
Rocky11388-Jun-10 17:29
Rocky11388-Jun-10 17:29 
GeneralRe: License Pin
Apple Lam29-Aug-10 16:11
Apple Lam29-Aug-10 16:11 
GeneralCapture video Pin
dzango23-Mar-10 3:40
dzango23-Mar-10 3:40 
GeneralJust works with the first shoot, (looking deeper than other comments) [modified] Pin
joputaidilico31-Mar-08 3:29
joputaidilico31-Mar-08 3:29 
Questionmemory leak? Pin
jgerdes19-Oct-07 11:04
jgerdes19-Oct-07 11:04 
GeneralWebcam captures exactly one image, BOMBS on second Pin
Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}14-Apr-07 12:49
Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}14-Apr-07 12:49 
GeneralFtpClient class Runs once then fails Pin
alanmcq13-Mar-07 0:02
alanmcq13-Mar-07 0:02 
Question.NET 2.0 work Pin
WzaH1-Sep-06 13:43
WzaH1-Sep-06 13:43 
GeneralAnother slight modification to the FTPClient Pin
SteveDT12323-Jun-06 6:10
SteveDT12323-Jun-06 6:10 
GeneralIntegrate with the Motion Dectection [modified] Pin
syd kahn7-Jun-06 2:43
syd kahn7-Jun-06 2:43 
Generalonly run once ? when i restart the service it will run again but once Pin
Mastarezma25-May-06 4:23
Mastarezma25-May-06 4:23 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
dakdog32025-May-06 9:10
dakdog32025-May-06 9:10 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
Mastarezma25-May-06 13:13
Mastarezma25-May-06 13:13 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
karande2330-May-06 20:23
karande2330-May-06 20:23 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
p3kurwud13-Aug-06 8:16
p3kurwud13-Aug-06 8:16 
GeneralSet Resolution Pin
doomsday32911-May-06 7:34
doomsday32911-May-06 7:34 
Generalnot able to run the application Pin
ketulvinayshah12-Apr-06 20:38
ketulvinayshah12-Apr-06 20:38 
GeneralImage Size Pin
mnlux12-Mar-06 15:27
mnlux12-Mar-06 15:27 
GeneralRe: Image Size Pin
doomsday32911-May-06 7:03
doomsday32911-May-06 7:03 
QuestionHowto change FrameSize? Pin
clemens8120-Jan-06 9:10
clemens8120-Jan-06 9:10 
QuestionDamn this so nearly works... Pin
FelixWatts21-Dec-05 7:31
FelixWatts21-Dec-05 7:31 
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 

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.