Webcam-server

Browsers, email, chat, etc.
Post Reply
Message
Author
User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

Webcam-server

#1 Post by Geoffrey »

looking for a webcam server I came across one called webcam-server,strange as it seems.
before I go to far into it, it does require java and a web server to be installed, I have python installed so I was able to utilize
the web server that is build into it.

I was going to make a package to install this, but due to fact that others may want to add it to there own web server and configure it
to their own liking I won't, it's not that difficult to install from the files just by coping them to their respective folders.
there is plenty of documentation in the readme's on setting it up in a custom way, though I didn't change anything to get it working
other than making a few small scripts to start, stop and run the viewer.

The webcam_server.tar.gz contains all the files extracted from deb packages the web-cam server and lib files for video for Linux converter
which was needed to get my camera to work.

" The preloadable libv4l1 wrapper which adds v4l2 device compatibility to v4l1
applications is called v4l1compat.so. The preloadable libv4l2 wrapper which
adds support for various pixelformats to v4l2 applications is called
v4l2convert.so. "

script to start the server

Code: Select all

#!/bin/bash -
export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so;
webcam-server
to stop the server

Code: Select all

#!/bin/bash -
#stop webcam-server
killall webcam-server
script to run the viewer

Code: Select all

#!/bin/bash -
java -classpath applet.jar WebCam localhost 8888
The start and stop scripts placed in /usr/bin and the viewer script go's into the same folder as the applet.jar, so that a standalone view of the cam can be monitored.

I don't know if there any other dependencies but for java, it worked first time for me using quirk120NOP though I've added quite a number of lib files with other apps, I would say that a webcam should be working with another camera application to be sure
Attachments
webcamviewer.png
the stand alone viewer
(44.55 KiB) Downloaded 3773 times
webcam_server.tar.gz
contains webcam-server, video for linux converter, documents and manual
(148.78 KiB) Downloaded 915 times

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#2 Post by Geoffrey »

Well I may have got ahead of myself, it appears that it has a problem working over the net, I should have read a bit more about some of the issues it has.

But it looks like I have found a way to make it work without having to use a web server to run the applet, so far it seems to work well, I'm in the process of making a GUI to run the server and viewer as well as a one for the remote client, I'll post again as soon as I have something worth while to try.

Edit:

well I have made a pet package for the server, it all seems to run ok, the next step is to create a client GUI, I don't have any real coding experience so would like some help with it from anyone that is interested.

I've never done anything like this before so I will try to explain the best way I can as to how it works.

When I first started with the server that I downloaded I found that it worked ok locally over the lan, but when getting a friend of mine to see if he would test it for me found that there was no image displayed in his browser, the port that the server runs on is port 8888, so asked him to try that, sure enough a static image was displayed in the browser, so seeing that it was sending to the internet I made a script to run the java applet and edited it for my web address and sent it and a copy of the applet to him, he ran it and what do you know it worked.

So there is no need to run a webserver to serve the java applet, one less thing to worry about, a applet run at the receiving end is all that's needed and it can still be viewed in a web browser as a static image which you can refresh to update and save the image to file.

I've finish the server and Gui to the best of my ability, I'll upload it for testing purposes if any one could give me some feedback on the scripting it would be appreciated, I'll post the code to see if I've made any mistakes.

This is the main GUI ..

Code: Select all

#!/bin/sh
DLG1="
 <wtitle>WCS</wtitle>
 <vbox>
 <pixmap>
     <input file>camera-web48.png</input> 
    </pixmap> 
  <text><label>WebCam Server</label></text>
        <frame --------Controls-------->

	  
   <hbox>
     <text><label>Start Server</label></text>
      <vbox>
    <button>
     <input file>camera-web-start.png</input>
     <action>webcam_start &</action>
	  </button>
       </vbox>
	   </hbox>
      
   <hbox>
     <text><label>Stop Server</label></text>
      <vbox>
    <button>
     <input file>camera-web-stop.png</input>
     <action>webcam_stop &</action>
	  </button>
       </vbox>
	   </hbox>
    	
	<hbox>
     <text><label>Start Viewer</label></text>
      <vbox>
    <button>
     <input file>viewer.png</input>
    <action>/usr/share/webcam/webcam-viewer &</action>
	    </button>
       </vbox>
	   </hbox>
	   
	   <hbox>
     <text><label>Stop Viewer</label></text>
      <vbox>
    <button>
     <input file>viewer-stop.png</input>
    <action>/usr/share/webcam/webcam-viewer-stop &</action>
	    </button>
       </vbox>
	   </hbox>    
    </frame>
		 
   <button cancel></button>
	
 </vbox>
 
"
echo "$DLG1" | gtkdialog2 --stdin

###END###

This is the script to run the viewer, it creates a pid file so that there can only be one instance of it running..

Code: Select all

#!/bin/bash -
#function only one instance
cd /usr/share/webcam
kill `cat app_pid.pid`
rm app_pid.pid
java -classpath applet.jar WebCam localhost 8888 pidfile=app_pid.pid <&- &
pid=$!  
echo ${pid} > app_pid.pid  
</applet.jar>  
This kills the applet..

Code: Select all

#!/bin/bash -
cd /usr/share/webcam
kill `cat app_pid.pid`
rm app_pid.pid
This runs the server..

Code: Select all

#!/bin/bash -
export LD_LIBRARY_PATH=/usr/lib
export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so;
webcam-server
And this stops the server..

Code: Select all

#!/bin/bash -
#stop webcam-server
killall webcam-server
To make a working client without a gui this script needs to be edited, the other files can be copied from the server files.
the files are..
error.jpg
init.jpg
applet.jar

just place the script and the three files together in a folder.

Code: Select all

#!/bin/bash -
#client
#replace ADDRESS with servers ip
#
java -classpath applet.jar WebCam ADDRESS 8888
Attachments
webcam_server.pet
For TESTING remember java and a working webcam are required
(159.2 KiB) Downloaded 1019 times
webcamGUI.png
WebCam Server GUI
(16.72 KiB) Downloaded 3649 times

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#3 Post by Geoffrey »

I'm still playing around with this server, I wrote a small script to capture a image from the server that will copy it to /root/my-documents/webcam_snapshots, then it renames each image with a date stamp, this could be a handy thing, this does not require java so if you have a functioning webcam, this can be use in place of the java viewer, just use it in conjunction with the webcam_server.pet

Edit:
Changed snapshot code to " webcam-`date +%Y-%m-%d--%H:%M:%S`.jpg " this gives a more pleasing file name, eg. webcam-2010-12-07--15:29:59.jpg

Code: Select all

#!/bin/sh
wget -P /root/my-documents/webcam_snapshots localhost:8888/.jpg
cd /root/my-documents/webcam_snapshots
for file in .jpg; do NEW_FILENAME=$(stat "$file" --format webcam-`date +%Y-%m-%d--%H:%M:%S`.jpg); mv "$file" "$NEW_FILENAME"; done
If you wish to use this remote from the server pc just replace "localhost" with the servers external address and in the router forward port 8888 to the server pc, if your running a firewall in puppy you could have problems, I still haven't worked out how to configure it, so I don't run one.

edit:

Just finished making the pet for a client only GUI for java, this will have to be edited manually to change the server address, it's default is "localhost".

Edit the "webcam-client" script located in /usr/share/webcam-client

Code: Select all

#!/bin/bash -
#function only one instance
cd /usr/share/webcam-client
kill `cat app_pid.pid`
rm app_pid.pid
java -classpath client-applet.jar WebCam localhost 8888 pidfile=app_pid.pid <&- &
pid=$!  
echo ${pid} > app_pid.pid  
</client-applet.jar>  
Attachments
webcam-client.pet
(42.09 KiB) Downloaded 869 times
webcam-client.png
WebCam Client GUI, java needed to run the applet
(13.16 KiB) Downloaded 3622 times
Last edited by Geoffrey on Tue 07 Dec 2010, 05:58, edited 2 times in total.

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#4 Post by Geoffrey »

I've done some more research, the server streams a series of ".jpg" files so there is no reason that it can't be viewed in a web page not using a java applet, here is the html code for non java webcam web page viewer.

you can change the refresh rate to suit, it is currently set to "0.1" which is 10 frame a second and it is linked the " localhost:8888 ", to add it to a website change it to point to your server " your webserver address:8888 " , change both references to it in the html.

Just cut and Paste the code into a new blank file and name it what ever you want to call it .html......

Code: Select all

<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>webcam</title>
<meta http-equiv="refresh" content="1">
</head>
<body style="color: rgb(0, 0, 0); background-color: rgb(142, 174, 255);"
alink="#000099" link="#000099" vlink="#990099">
<div style="text-align: center;"><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
WebCam<br>
</div>
<div style="text-align: center;"><a href="http://localhost:8888/.jpg"><img
style="border: 5px solid ; width: 320px; height: 240px;"
alt="The WebCam Is Currently Unavailable"
src="http://localhost:8888/.jpg"></a><br>
</div>
<br>
<br>
</body>
</html>

Edit:

Tested this over the internet, found that it refreshs to fast and the browser is erratic, changed " <meta http-equiv="refresh" content="0.1"> " to "<meta http-equiv="refresh" content="1"> " works fine now, updated code 1refresh a second.

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

Conky

#5 Post by Geoffrey »

Found yet another way to view a streamed jpg webcam server, using Conky to display it on the desktop.
this one is a bit tricky as most puppy versions have pwidgets which use conky as its engine, this most likely can be incorporated into pwidget if one was inclined to do so, I think there is a widget for displaying images so that could be used.

This uses the webcam image as a background for conky and the conky.conf can be edited so that the text doesn't overlay the image.

The requirements for this are conky with imlib2 support, I used pet packages, conky-imlib2-1.7.2.pet and imlib2-1.4.2.pet located here.

This is similar to the snapshot as it uses wget to retrieve images that are stored in /root/.conky/webcam/images/, this done by the script webcam in /root/.conky/webcam/.

This is the script called webcam..

Code: Select all

#!/bin/sh
Image="~/.conky/webcam/images/webcam.jpg"
ImageSize="320x240"
Layers=1
wget -q localhost:8888/.jpg -O ~/.conky/webcam/images/webcam-image.jpg && mv ~/.conky/webcam/images/webcam-image.jpg ~/.conky/webcam/images/webcam.jpg
    echo "\${image $Image -p 0,0 -s $ImageSize -n}"
exit 0
This script as the others needs to be edited to change the location of the server where the images are located, default is localhost:8888.

This is the code for the conky.conf file..

Code: Select all

update_interval 10.0
own_window  yes
own_window_transparent yes
border_width 0
draw_outline no
draw_shades no
own_window_type root
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
alignment tr
minimum_size 320 240
gap_x 30
gap_y 50
TEXT
${execp ~/.conky/webcam/webcam}
The default is to update the image every 10 seconds and places the image in the top righthand corner of the desktop.
Attachments
webcam_conky.jpg
screenshot conky with webcam image
(46.28 KiB) Downloaded 3619 times
conky.conf.tar.gz
conky.conf
(336 Bytes) Downloaded 794 times
conky-webcam-script.tar.gz
the script called webcam, this is placed in /root/.conky/webcam/
(280 Bytes) Downloaded 753 times

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#6 Post by Geoffrey »

I have had another go at building a user interface for the webcam server, I have changed the way it controls things quite a bit, it now can be viewed using conky as well as java, also added a snapshot .

The Gui is now a gtkdialog3 of a fixed window size and the buttons have mouse over tooltip text, have made it as simple as I can, it may not look exciting but it is functional.

The application directory webcam contains all the files and scripts this include the png icons, as I found that it slowed it down considerably if it was to look else where for them, it opens instantly now wheres before it took up to 5 seconds or more.

I have made it so that it uses a updated conky executable, this works ok on my quirky NOP 1.20 which was using conky 1.6.1and now has the conky executable from the conky-imlib2-1.7.2.pet, also I only used the lib files from the imlib2-1.4.2.pet has this is all that is needed to view images with conky.

Had to add scripts to control conky as I am running two, one for the webcam and the other for on screen system info, I did this creating pid files so that there is no interaction between the two and only one instance of each can be run, this seems to work well, the cam is viewed in a conky movable window instead of embedded into the desktop, the java viewer functions in the same manner.

I don't know how this will effect pwidgets as I don't use them, would say that a pid file would have to control it also, so as not to have any interactions with the other instances of conky.

Added a snapshot button with sound and button to open the "webcam_snapshots" directory, also changed the date time format of the saved image file slightly from what they were to, eg. webcam_2010-12-14_21:12:14.jpg.

I'll upload a pet for it for testing only, it could break conky if pwidgets are being used, there may be some missing dependacies for the webcam-server executable, if it don't run from the menu try typing " webcam_start " in the terminal that should tell what it is missing.
Attachments
webcam_server_viewer_gui.jpg
(21.22 KiB) Downloaded 3548 times
conky_java_viewers.jpg
(20.26 KiB) Downloaded 2015 times

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#7 Post by Geoffrey »

I tried the webcam_server_testing_only.pet on a copy of lupu-511 that I had on a usb stick, works ok as pwidgets isn't installed by default, so it should be ok as long as pwidgets isn't used.

would make an alternative to pwidgets as it will still give a conky desktop system display, I will make another Gui less the java, that might be a better choice, keep it small and simple.
Attachments
webcam_server_lupu-511.jpg
(40.62 KiB) Downloaded 1816 times

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#8 Post by technosaurus »

micko, jemimah and I put together a similar widget a while back that used ffmpeg and conky if you need any ideas ... never got around to testing streaming with ffmpeg's udp capabilities though (for realtime mp4 stream broadcasting)

hijacked this thread:
http://www.murga-linux.com/puppy/viewtopic.php?t=52373

Conky stuff
  • TEXT
    ${execi 1 /usr/bin/webcam}
    ${image /tmp/camshot1.jpg -s 320x240}
and code for /usr/bin/webcam

Code: Select all

ffmpeg -y -r 1 -t 1 -f video4linux2 -s qvga -i /dev/video0 /tmp/camshot%d.jpg &
jemimah also made it refresh the desktop background instead
I posted a mod to use multiple cameras (for security or nanny cams etc..)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#9 Post by Geoffrey »

technosaurus

Yes I've been following jemimah's thread, I tried the ucview but I couldn't get to work, it either broke my QuirkyNOP 1.20 or ended up with it running but no image just a black screen, I think it was to do with file version conflicts with dbus.

So I thought I'd have a bash at finding something, that's when I came across webcam-server and thought that would be good enough for my needs, but soon found that it had a issue with it's java applet, it don't like to be served, as far as I can tell it has a java security issue, so it seemed the server side of things are fine, that's when I decided to see what could be done with it.

It looks to be quite versatile and as I already use conky I knew that it could display images which has lead me to where it is now, I'll be removing any java compatibility to try and keep it as small as possible, I don't think another 50 or so megs for java is justified just to view a cam.

I,m going to use pythons simple server to serve a html for it that way no client is needed other than a web browser that can refresh a page.

Thanks for the link, I will still look at realtime video if I can sort the problems that I've been having.

Geoffrey

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#10 Post by Geoffrey »

This is the conky only version, I've cleaned up the scripts resized the gui replace the .conky with .webcam removed one Dir and renamed the image Dir to image-cache so as not to be to confusing, restructured the snapshot Dir so now it saves to it as eg. root/my-documents/webcam_snapshots/2010/Dec/18_Sat/webcam_2010-12-18_21:14:17.jpg, that should make it easier to sort.

I trolled the net looking for something that might be better, but there seems to be not much that would make it more usable than it is at the moment, not without making it a massive size, well it works in lupu 5.11 without any problem, just don't install pwidgets or conky from the ppm.

Conky is in the Startup Dir, just remove it if it's not required, .conkyrc is in root, that can be replaced or edited.

The only thing that would make it better is to have a remote server viewer with a list of servers to select from, or being able type in a webcam address, but as I have only just started playing around with scripts it is beyond me at the moment, maybe something for someone else to have a go at.
Attachments
webcam_gui.jpg
the gui is smaller now, looks more tidy
(16.56 KiB) Downloaded 3433 times

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

Firefox ipcam addon

#11 Post by Geoffrey »

I found a Firefox ipcam addon that works with the latest version of Firefox 3.6.13, shows cam in a sidebar https://addons.mozilla.org/en-US/firefox/addon/241025/
Attachments
firefox_addon.jpg
(28.03 KiB) Downloaded 3377 times

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#12 Post by technosaurus »

if you'd like to play with it as webcam server

Save this as index.html in /root/Web-Server/
<meta http-equiv="refresh" content="1"><html><head><title>My Webcam</title></head><body><img src="webcam1.jpg" alt="Webcam" /></body></html>

then run:
hiawatha #not necessary, you can just use the page directly
while (true) do ffmpeg -y -r 1 -t 1 -f video4linux2 -s qvga -i /dev/video0 /root/Web-Server/webcam%d.jpg; done

you should now see an image refresh every second at
http://localhost/
(if you have it as a server, then others can see it online too)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#13 Post by Geoffrey »

technosaurus wrote:if you'd like to play with it as webcam server

Save this as index.html in /root/Web-Server/
<meta http-equiv="refresh" content="1"><html><head><title>My Webcam</title></head><body><img src="webcam1.jpg" alt="Webcam" /></body></html>

then run:
hiawatha #not necessary, you can just use the page directly
while (true) do ffmpeg -y -r 1 -t 1 -f video4linux2 -s qvga -i /dev/video0 /root/Web-Server/webcam%d.jpg; done

you should now see an image refresh every second at
http://localhost/
(if you have it as a server, then others can see it online too)
Yeah that's good, I will be able to use that for something, I ran it in the terminal there is a error but does run, skips a frame now and then

Code: Select all

[mjpeg @ 0x80776e0]mjpeg_decode_dc: bad vlc: 0:0 (0x8094490)
[mjpeg @ 0x80776e0]error dc
[mjpeg @ 0x80776e0]error y=29 x=0
[video4linux2 @ 0x8076510]max_analyze_duration reached
[video4linux2 @ 0x8076510]Estimating duration from bitrate, this may be inaccurate

Thanks for that, I appreciate the thought, I still need to use the cam online as I exchange idea's on other interest with a friend of mine and pictures say a thousand words, I don't need to serve a page to him , he just runs a local html to display the webcam saves running another server, I have yet to let him know of the firefox ipcam addon, that will be handy.

Geoffrey


edit:
" while (true) do ffmpeg -y -r 1 -t 1 -f video4linux2 -s qvga -i /dev/video0 /root/Web-Server/webcam%d.jpg; done "
I have a problem with it, after a while it locks up and cpu usage go's to 100%, I have to kill ffmpeg in the task manager then it continues until it peaks out again.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#14 Post by technosaurus »

... forgot about that - I think we ended up replacing true with sleep 1
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#15 Post by Geoffrey »

technosaurus wrote:... forgot about that - I think we ended up replacing true with sleep 1
That didn't fix it.
It looks to me that VM-Size reaches 20108kb and then locks up, the cpu percentage continues to fluctuate between 20 -80 percent.
Attachments
ffmpeg.png
(29.08 KiB) Downloaded 3433 times

exon
Posts: 23
Joined: Fri 28 Nov 2008, 21:10

#16 Post by exon »

could you also tell me what brand of webcam you have i'm looking for a good lowbudget webcam that deffenly works on puppy

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#17 Post by Geoffrey »

exon

The webcam I use is cheap one I found at a discount store, I think you can pick them up for around $7au,
it appears to be a ZSMC USB PC Camera (ZS0211), Vimicro Cam, ProductGUID=3B61539D-2361-4962-8A23-2BE11965D32D, ID 0ac8:307b, it's not to bad does 320x240 or 640x480, works with most apps I've tried, they come in all shapes and sizes, it's a bit hard to see what your buying as there isn't much info on the box that it came in, the name on the box of the one I have say's "PC CAMERA", that's it , the mini cd with the drivers is an orange color that say's "PC CAMERA Product Driver, this contains Vimicro Windows and Mac drivers, I think it could a hit and miss experience in obtaining a cam that does work.

Hope that's of some help to you

Geoffrey

hiveman
Posts: 3
Joined: Sat 03 Oct 2009, 05:44

#18 Post by hiveman »

This is great and worked perfectly up to the refresh script:
while (true) do ffmpeg -y -r 1 -t 1 -f video4linux2 -s qvga -i /dev/video0 /root/Web-Server/webcam%d.jpg; done
When I run this I get the error
ffmpeg: error while loading shared libraries: libvpx.so.0: cannot map zero-fill pages: Cannot allocate memory
I'm sure if I were a programmer I would say "Oh yeah, of course...", but since I'm not I'm hoping someone here can tell me what to do about this.

Thanks!

eneanito
Posts: 3
Joined: Mon 11 Feb 2008, 00:11

usable to ipcam?

#19 Post by eneanito »

Im woried about I can't view my IP camera from internet. ISP says it desn`t offer that service, but it doesn't close any ports. Test ports pages say ports are closed (except port 22 ssh) all about public address reported by whatsmyIp pages.
I can use team viewer and clicking one page a dont remember it has remotely started my webcam being previosly off and may be put it on web.

Your software tell me you know anything about this theme. Can you help me?

Post Reply