Click here to Skip to main content
Licence 
First Posted 26 Mar 2003
Views 243,630
Bookmarked 137 times

C# WebCam Service with FTP and Installer

By | 31 Mar 2003 | Article
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

About the Author

Dan Glass

Architect
support.com
Australia Australia

Member

Tech Support

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionplease help me quickly to send image to my web site quickly Pinmemberhansalsal21:36 23 Feb '11  
GeneralLicense PinmemberRocky113817:29 8 Jun '10  
GeneralRe: License PinmemberApple Lam16:11 29 Aug '10  
GeneralCapture video Pinmemberdzango3:40 23 Mar '10  
GeneralJust works with the first shoot, (looking deeper than other comments) [modified] Pinmemberjoputaidilico3:29 31 Mar '08  
Questionmemory leak? Pinmemberjgerdes11:04 19 Oct '07  
GeneralWebcam captures exactly one image, BOMBS on second PinmemberPeter {faa780ce-0f0a-4c28-81d2-3667b71287fd}12:49 14 Apr '07  
GeneralFtpClient class Runs once then fails Pinmemberalanmcq0:02 13 Mar '07  
Question.NET 2.0 work PinmemberWarrenHuisman13:43 1 Sep '06  
GeneralAnother slight modification to the FTPClient PinmemberSteveDT1236:10 23 Jun '06  
GeneralIntegrate with the Motion Dectection [modified] Pinmembersyd kahn2:43 7 Jun '06  
Generalonly run once ? when i restart the service it will run again but once PinmemberMastarezma4:23 25 May '06  
GeneralRe: only run once ? when i restart the service it will run again but once Pinmemberdakdog3209:10 25 May '06  
GeneralRe: only run once ? when i restart the service it will run again but once PinmemberMastarezma13:13 25 May '06  
GeneralRe: only run once ? when i restart the service it will run again but once Pinmemberkarande2320:23 30 May '06  
GeneralRe: only run once ? when i restart the service it will run again but once Pinmemberp3kurwud8:16 13 Aug '06  
GeneralSet Resolution Pinmemberdoomsday3297:34 11 May '06  
Generalnot able to run the application Pinmemberketulvinayshah20:38 12 Apr '06  
GeneralImage Size Pinmembermnlux15:27 12 Mar '06  
GeneralRe: Image Size Pinmemberdoomsday3297:03 11 May '06  
QuestionHowto change FrameSize? Pinmemberclemens819:10 20 Jan '06  
QuestionDamn this so nearly works... PinmemberFelixWatts7:31 21 Dec '05  
AnswerRe: Damn this so nearly works... PinmemberMartijn Stegeman4:49 13 Mar '06  
Jokeerror in errorlog .... Pinmembercodemanloyd5:20 2 Dec '05  
GeneralCapture only one time PinmemberHuu Long23:40 1 Nov '05  

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.

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