Click here to Skip to main content
11,490,003 members (68,603 online)
Click here to Skip to main content

C# WebCam Service with FTP and Installer

, 31 Mar 2003 280K 2.6K 144
Rate this:
Please Sign up or sign in to vote.
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:

<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

Share

About the Author

Dan Glass
Architect support.com
Australia Australia

Comments and Discussions

 
GeneralThank you Dan! Pin
Member 105806974-Aug-14 21:01
memberMember 105806974-Aug-14 21:01 
Questionplease help me quickly to send image to my web site quickly Pin
hansalsal23-Feb-11 22:36
memberhansalsal23-Feb-11 22:36 
GeneralLicense Pin
Rocky11388-Jun-10 18:29
memberRocky11388-Jun-10 18:29 
GeneralRe: License Pin
Apple Lam29-Aug-10 17:11
memberApple Lam29-Aug-10 17:11 
GeneralCapture video Pin
dzango23-Mar-10 4:40
memberdzango23-Mar-10 4:40 
GeneralJust works with the first shoot, (looking deeper than other comments) [modified] Pin
joputaidilico31-Mar-08 4:29
memberjoputaidilico31-Mar-08 4:29 
Questionmemory leak? Pin
jgerdes19-Oct-07 12:04
memberjgerdes19-Oct-07 12:04 
GeneralWebcam captures exactly one image, BOMBS on second Pin
Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}14-Apr-07 13:49
memberPeter {faa780ce-0f0a-4c28-81d2-3667b71287fd}14-Apr-07 13:49 
GeneralFtpClient class Runs once then fails Pin
alanmcq13-Mar-07 1:02
memberalanmcq13-Mar-07 1:02 
Question.NET 2.0 work Pin
WarrenHuisman1-Sep-06 14:43
memberWarrenHuisman1-Sep-06 14:43 
GeneralAnother slight modification to the FTPClient Pin
SteveDT12323-Jun-06 7:10
memberSteveDT12323-Jun-06 7:10 
GeneralIntegrate with the Motion Dectection [modified] Pin
syd kahn7-Jun-06 3:43
membersyd kahn7-Jun-06 3:43 
Generalonly run once ? when i restart the service it will run again but once Pin
Mastarezma25-May-06 5:23
memberMastarezma25-May-06 5:23 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
dakdog32025-May-06 10:10
memberdakdog32025-May-06 10:10 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
Mastarezma25-May-06 14:13
memberMastarezma25-May-06 14:13 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
karande2330-May-06 21:23
memberkarande2330-May-06 21:23 
GeneralRe: only run once ? when i restart the service it will run again but once Pin
p3kurwud13-Aug-06 9:16
memberp3kurwud13-Aug-06 9:16 
GeneralSet Resolution Pin
doomsday32911-May-06 8:34
memberdoomsday32911-May-06 8:34 
Generalnot able to run the application Pin
ketulvinayshah12-Apr-06 21:38
memberketulvinayshah12-Apr-06 21:38 
GeneralImage Size Pin
mnlux12-Mar-06 16:27
membermnlux12-Mar-06 16:27 
GeneralRe: Image Size Pin
doomsday32911-May-06 8:03
memberdoomsday32911-May-06 8:03 
QuestionHowto change FrameSize? Pin
clemens8120-Jan-06 10:10
memberclemens8120-Jan-06 10:10 
QuestionDamn this so nearly works... Pin
FelixWatts21-Dec-05 8:31
memberFelixWatts21-Dec-05 8:31 
AnswerRe: Damn this so nearly works... Pin
Martijn Stegeman13-Mar-06 5:49
memberMartijn Stegeman13-Mar-06 5:49 
Jokeerror in errorlog .... Pin
codemanloyd2-Dec-05 6:20
membercodemanloyd2-Dec-05 6:20 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 1 Apr 2003
Article Copyright 2003 by Dan Glass
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid