talkeasy
Posts: 38
Joined: Sun Nov 04, 2012 10:57 pm

Re: RPi Cam Web Interface

Mon Jan 20, 2014 3:41 pm

@Phenom55 - Yes you can stream to a phone via a browser.

Use the index2.html version modified by poing above.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: RPi Cam Web Interface

Mon Jan 20, 2014 3:46 pm

talkeasy wrote:@Phenom55 - Yes you can stream to a phone via a browser.

Use the index2.html version modified by poing above.
Note it's experimental... if you tap the image it will record an image but if either video recording or motion is active it will end raspimjpeg instead and you'll have to restart the Pi. Easy to work around but it has to be done first ;-)

kyle2k
Posts: 84
Joined: Tue Feb 19, 2013 2:47 pm

Re: RPi Cam Web Interface

Mon Jan 20, 2014 9:49 pm

@silvanmelchior

Thank you very much for this ;-)

I am having lots of fun playing and editing parts to suit my needs, even got it streaming to another pi running Raspbmc browser on my TV.

One question how hard/easy would it be for me to change the motion detection to save pictures instead of video?

Loving your work so far and if you have a bitcoin address I would be happy to send you a small donation.

Once again thanks.

Regards Kyle

User avatar
jbeale
Posts: 3476
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: RPi Cam Web Interface

Mon Jan 20, 2014 10:13 pm

it is very straightforward to change the /etc/motion/motion.conf file to have motion itself save the low-resolution MJPEG frame used for motion detection, for example these changes:

Code: Select all

# save still image, could be 'off' for no still, 'on' for all motion frames,  'first' for first detected motion per event, 
# ... 'best' for frame with most motion, etc.
output_normal best

# apply timestamp to lower right hand edge
text_right %Y-%m-%d\n%T-%q

# directory to save still images, this location makes it visible and downloadable in the web browser interface
target_dir /var/www/media
This is suitable for small thumbnail-images for a quick glance at what triggered the motion. It is a 512 x 288 pixel image due to the MJPEG resolution used.

If you need full-resolution 1920x1080 images, that would need another application like avconv to read the saved .mp4 file and extract a still frame from it, which is also certainly possible, but would need a bit of scripting work to setup, and additional CPU time to run.

If you want full-frame 5Mpixel stills, that can't be done in the existing software. It could be done, but I think would require quite a bit of coding.

kyle2k
Posts: 84
Joined: Tue Feb 19, 2013 2:47 pm

Re: RPi Cam Web Interface

Tue Jan 21, 2014 12:59 am

Thanks for your quick reply jbeale,

I will spend some time tomorrow playing with your suggestions :D

Full res is not important to me just something I can scan and upload with python.

I am ok with php, learning and loving python but still an amateur with C.

Thanks again Kyle

Edit: Most of my testing has been done on a model A using WIFI and the results have been surprisingly good.
Not as good as on my model B over ethernet but this project has inspired me to order another model B and cam :lol:

Hiberius Brecht
Posts: 1
Joined: Tue Jan 21, 2014 7:27 am

Re: RPi Cam Web Interface

Tue Jan 21, 2014 7:38 am

Hi,

I'm having difficulties to pass instructions on to my camera at startup time via the FIFO-Pipe. What I want to achieve is to setup my camera at startup to ro 270, em night, qu 100, bi 25000000, br 55, md1. I wrote those instructions into my rc.local. But only the ro 270 appears to be taken into account. The others are ignored. I tried already placing them all into individual echo instructions, into one single echo instruction, with and without spaces between them. But so far the result is always that only the first instruction, the ro 270, is taken by the camera. Does anyone know how to do this in a correct way so that I don't need to setup my camera manually at startup time via the browser?

Many thanks,
H.B.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: RPi Cam Web Interface

Tue Jan 21, 2014 9:06 am

What happens when you start and stop the video? This might sound strange, but, using my phone web page over WiFi, when I change WB to 'Sun' nothing happens although when I change 'Contrast' to 100 it works. If I then start the video suddenly the WB is changed to 'Sun'.

This might be due to the WiFi or something else, but I didn't change anything related in my 'phone' implementation. Still looking into getting the model B working again, maybe backfeeding power will work.

rahlquist
Posts: 149
Joined: Tue Jan 21, 2014 1:02 pm

Re: RPi Cam Web Interface

Tue Jan 21, 2014 1:10 pm

First off many thanks to silvanmelchior for his work on this! I was starting to feel very frustrated with the sluggish other methods with huge delays in the video stream and/or poor performance. This has been working great for me so far.

One question though. The 512x288 preview image. Was that specific size chosen for a particular reason, or could it be changed somewhat with the usual nod to the fact that bigger is less apt to perform as well? I guess what I am asking is, does this size perform better than others because its some mathematical derivative of the full size?

Thanks!

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: RPi Cam Web Interface

Tue Jan 21, 2014 3:04 pm

I don't think that's the reason as the scaling is done in the GPU which is quite fast. Larger images take more bandwidth so will be less smooth. But I had fairly good results with 1920x1080. To change it edit /etc/rc.local with:

Code: Select all

sudo nano /etc/rc.local
and reboot.

User avatar
rleyden
Posts: 70
Joined: Thu Jun 14, 2012 2:17 am

Re: RPi Cam Web Interface

Tue Jan 21, 2014 5:14 pm

I addded a PIR sensor to my RPi camera setup to capture activity around my fish pond. The most interesting activity occurs at night so I added a relay activated spotlight. Setting exposure mode to "night" seems to give better exposure than "auto", although the spotlight is bright enough for auto mode to give an OK video.

I have a unexpected issue. The captured mp4 video plays back 20 seconds of action in 2 seconds, like time lapse. I gather that night mode exposures takes too long for normal video frame rates but I don't understand why the video isn't just encoded at the appropriate frames per second to give real time play back. Is there a setting to force this or do I have to re-encode the video off-line?

User avatar
jbeale
Posts: 3476
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: RPi Cam Web Interface

Tue Jan 21, 2014 5:15 pm

poing wrote: But I had fairly good results with 1920x1080.
Very interesting! I didn't even think to try the full size. I'll bet that the 'motion' program doesn't have a very fast detection response at that resolution, though. I went down to 256x144 to lower the motion detection response time.
rleyden wrote:The captured mp4 video plays back 20 seconds of action in 2 seconds
If you use 'night' you can get shutter times and frame rates down to 1 second / 1 fps when it is dark. The video is saved as raw .h264 (which does not include timing infomation) and then afterwards wrapped as a MP4 format file. The MP4 stays at a fixed default frame rate, I think it is 25 fps, so you would see 25x speedup on playback when dark. Unfortunately the camera does not talk directly to the MP4 program (MP4Box) so it doesn't know the true capture framerate. You could manually run MP4Box on raw .h264 files and pass it the correct framerate, if you know it. For example if you have "myvid.h264" and you want to create "myvid.mp4" with 15 fps playback rate, you could do

Code: Select all

MP4Box -fps 15 -add myvid.h264 myvid.mp4

User avatar
leol
Posts: 147
Joined: Fri Jan 13, 2012 4:27 pm
Location: Haute-Vienne, France

Re: RPi Cam Web Interface

Tue Jan 21, 2014 5:23 pm

rleyden wrote:I addded a PIR sensor to my RPi camera setup to capture activity around my fish pond. The most interesting activity occurs at night so I added a relay activated spotlight. Setting exposure mode to "night" seems to give better exposure than "auto", although the spotlight is bright enough for auto mode to give an OK video.

I have a unexpected issue. The captured mp4 video plays back 20 seconds of action in 2 seconds, like time lapse. I gather that night mode exposures takes too long for normal video frame rates but I don't understand why the video isn't just encoded at the appropriate frames per second to give real time play back. Is there a setting to force this or do I have to re-encode the video off-line?
The native video output is in h264 format that does not include any indication of frame rate. You will need to put it into an mp4 container using ffmpeg for example. There has been much discussion of this on the forum. I'm sure you will be able to find a full explanation using Google.

HeikoG
Posts: 12
Joined: Wed Oct 16, 2013 11:53 am

Re: RPi Cam Web Interface

Tue Jan 21, 2014 8:16 pm

Interesting. CPU is much lower with -w 1920 -h 1080.

User avatar
rleyden
Posts: 70
Joined: Thu Jun 14, 2012 2:17 am

Re: RPi Cam Web Interface

Tue Jan 21, 2014 11:10 pm

jbeale wrote: You could manually run MP4Box on raw .h264 files and pass it the correct framerate, if you know it
Thanks. I tried using MP4Box with inputing the mp4 file but it didn't change the fps. No matter, Avidemux worked.
Perhaps I should have mentioned that the first 4 frames are overexposed (3 fps real time, so 1.3 sec). As far as I can tell, the whole clip is collected at 3 fps then encoded at 25 fps. So, it seems the camera is not only using pre-trigger values for initial exposure but also using pre-trigger or maybe 1st frame exposure times to set the capture interval. I can easily put a delay between turning on the spotlight and starting the recording. Alternatively, I could stop and restart the recording so as to not miss the instant around the PIR trigger. I suspect some wildlife may flee when the lights go on so I don't want a long delay.

Hugh-Roger
Posts: 27
Joined: Sat Jan 18, 2014 12:31 am

Re: RPi Cam Web Interface

Wed Jan 22, 2014 1:45 pm

silvanmelchior, Nice work.

Unfortunately I had to back out my installation because I had forgotten that I already had nginx web server running on port 80 (which I was using for another project).

Moving apache onto a different port is not a problem, but in the first case I ran your script with the 'remove' parameter, but this did not remove apache - it still served the web cam page - even after a reboot.

I reran the shell remove again, and it displayed :

The following packages were automatically installed and are no longer required:
apache2-mpm-prefork apache2.2-bin apache2.2-common ffmpeg gpac-modules-base
liba52-0.7.4 libaprutil1-dbd-sqlite3 libaprutil1-ldap libglu1-mesa libgpac2
libmysqlclient18 libpq5 mysql-common ssl-cert
Use 'apt-get autoremove' to remove them.

running apt-get autoremove did the trick and removed apache and co. Nginx was then able to restart.

Great work though, I just wanted to feed this back in case it is of any use to any one.

rahlquist
Posts: 149
Joined: Tue Jan 21, 2014 1:02 pm

Re: RPi Cam Web Interface

Wed Jan 22, 2014 2:55 pm

HeikoG wrote:Interesting. CPU is much lower with -w 1920 -h 1080.
Are you referring to changing the preview image size? If so I see the same decrease in CPU. The only problem is network bandwidth goes way up and I cant seem to get motion to trigger as reliably. Would be great on a wired connection though.

silvanmelchior
Posts: 76
Joined: Mon Nov 25, 2013 5:56 pm

Re: RPi Cam Web Interface

Wed Jan 22, 2014 5:34 pm

Hello everybody

It's been a while, I'm pretty busy at the moment.

My Pi was running for two weeks without any problems, so I guess the Interface is stable now, except somebody else made other experiences. I had the same problem with false triggered motion detection in dark environment. Fortunately I remembered that I had similar problems while programming the live-stream and using php to read the file seemed to help. So I changed the netcam-url in the motion.conf file to http://localhost/cam_pic.php and now It seems to work (at least during the few minutes I was testing). As I read, stefan.knight even suggested this, so you were right.

@jbeale: Thanks a lot four your support here, I'm really busy at the moment... And thanks for the idea with the filesize and delete-all buttons, I updated the website.

@kyle2k: This is very nice, thank you, but a donation is really not necessary. Glad to see that you like my work.

@Hugh-Roger: I added apt-get autoremove to thanks for the sharing

To update to the latest version, just rerun the installer. /var/www/Version.txt should show 2.1 and /etc/motion/motion.conf should include netcam_url http://localhost/cam_pic.php afterwards.

HeikoG
Posts: 12
Joined: Wed Oct 16, 2013 11:53 am

Re: RPi Cam Web Interface

Wed Jan 22, 2014 6:38 pm

There is a heavy traffic on the Apache2 access.log. Does it make sense to disable access.log logging in case of performance?

User avatar
jbeale
Posts: 3476
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: RPi Cam Web Interface

Thu Jan 23, 2014 6:24 am

HeikoG wrote:There is a heavy traffic on the Apache2 access.log. Does it make sense to disable access.log logging in case of performance?
If every MJPEG image load is being logged, I'd think that is too much logging! I don't know if you can configure the amount of logging that Apache2 does, but if you can't turn off repeat logging of access to the same file from the same client in the same session, I would turn it all off.

rahlquist
Posts: 149
Joined: Tue Jan 21, 2014 1:02 pm

Re: RPi Cam Web Interface

Thu Jan 23, 2014 1:42 pm

Ok so a question from a relative n00b.

With the RPi Cam Web Interface running on the Pi, would it be possible to have another linux machine do the motion detection?

The reason I ask is with my testing and my sluggish wifi, if I have motion detection on and have one browser on the index.html page the pi CPU load steadily increased to 3.82. So would it be better to have a PC monitor the Pi, especially since my eventual goal is 4 or so Pi running as security devices?

Thanks!

stefan.knight
Posts: 24
Joined: Tue Dec 17, 2013 7:43 pm

Re: RPi Cam Web Interface

Thu Jan 23, 2014 5:34 pm

rahlquist wrote:Ok so a question from a relative n00b.

With the RPi Cam Web Interface running on the Pi, would it be possible to have another linux machine do the motion detection?

The reason I ask is with my testing and my sluggish wifi, if I have motion detection on and have one browser on the index.html page the pi CPU load steadily increased to 3.82. So would it be better to have a PC monitor the Pi, especially since my eventual goal is 4 or so Pi running as security devices?

Thanks!
I don't see why. You should be able to install motion on another server and set the following:
netcam_url http://<IP of Pi>/cam_pic.php

You would need to work out what you wanted to do when motion is detected, such as start and stop the recording. I assume the web interface can provide some RESTful type services to enable this remote control. Also, you would need a motion instance for each Pi cam, not sure how easy it is to get multiple instances of motion to run on a single server.

Others may have better ideas. I'm in the same boat and would like to know the best way to do it also as my CAMs (5 of them) will run on WiFi.

User avatar
jbeale
Posts: 3476
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: RPi Cam Web Interface: running 'motion'

Thu Jan 23, 2014 10:05 pm

You can do motion detection on a different server, that is often done with IP cameras. I recommend that you use a more powerful device than the R-Pi, if you have several cameras. On the other hand, if you really downsize the MJPEG image maybe it could work. At the default 512x288 resolution, raspimjpeg takes 5% of my R-Pi CPU time and motion is claiming about 16%. When the MJPEG is being viewed in a browser (over a very slow wifi link, update rate very slow), I see two apache2 threads both using 1%.

After changing the raspimjpeg call in /etc/rc.local to use 256x144 pixels and restarting, the 'motion' process uses 6% of CPU. You can go farther; you can do useful motion detection on extremely small images. The real reason for higher resolution is for human inspection of the image later, and if you rely on the 1080p video for that, then you don't need big images.

A side-effect of the smaller MJPEG image size is the MJPEG in the browser approaches nearly smooth motion (at times) even over the lousy wifi, and also apache2 uses 4% or more CPU, as more frames per second get sent out.

User avatar
jbeale
Posts: 3476
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: RPi Cam Web Interface

Thu Jan 23, 2014 10:11 pm

HeikoG wrote:There is a heavy traffic on the Apache2 access.log. Does it make sense to disable access.log logging in case of performance?
We have a problem here! Indeed it seems that every single MJPEG frame load is being logged in /var/log/apache2/access.log and also /var/log/apache2/other-vhosts-access-log and that's too much! A few lines from the access.log are copied below:

Code: Select all

192.168.42.13 - - [23/Jan/2014:13:54:56 -0800] "GET /cam_pic.php?time=1390514096323 HTTP/1.1" 200 26637 "http://192.168.42.1/" "Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0"
192.168.42.13 - - [23/Jan/2014:13:54:56 -0800] "GET /cam_pic.php?time=1390514096352 HTTP/1.1" 200 25276 "http://192.168.42.1/" "Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0"
192.168.42.13 - - [23/Jan/2014:13:54:56 -0800] "GET /cam_pic.php?time=1390514096475 HTTP/1.1" 200 26491 "http://192.168.42.1/" "Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0"
192.168.42.13 - - [23/Jan/2014:13:54:56 -0800] "GET /cam_pic.php?time=1390514096552 HTTP/1.1" 200 27334 "http://192.168.42.1/" "Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0"
192.168.42.13 - - [23/Jan/2014:13:54:56 -0800] "GET /cam_pic.php?time=1390514096616 HTTP/1.1" 200 26918 "http://192.168.42.1/" "Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0"
192.168.42.13 - - [23/Jan/2014:13:54:56 -0800] "GET /cam_pic.php?time=1390514096716 HTTP/1.1" 200 27441 "http://192.168.42.1/" "Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0"
192.168.42.13 - - [23/Jan/2014:13:54:56 -0800] "GET /cam_pic.php?time=1390514096818 HTTP/1.1" 200 26747 "http://192.168.42.1/" "Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0"
192.168.42.13 - - [23/Jan/2014:13:54:56 -0800] "GET /cam_pic.php?time=1390514096879 HTTP/1.1" 200 27234 "http://192.168.42.1/" "Mo
I have reduced the log spam with the below changes to the access.log definition in /etc/apache2/sites-available/default
but I still see a smaller trickle of "GET /status_mjpeg.php?last=ready" requests every 4 seconds, as long as a browser window is open watching the camera. You could also just leave the CustomLog line commented out and have no access log at all, if that's OK with you. A separate file /etc/apache2/conf.d/other-vhosts-access-log controls the log with the (many!) localhost reads of the MJPEG file.

Side benefit: after completely turning off both logfiles, the MJPEG update in the browser is very consistent, without the occasional freeze-frames I would always see before. I thought it was my wifi, but apparently that was due to the continuous writing to the logfile.

Code: Select all

sudo service apache2 stop
sudo rm /var/log/apache2/*        <= assuming you don't need your logs, of course....
sudo nano /etc/apache2/sites-available/default

  <scroll to bottom of file, and either just #comment out this line (no logging), or replace it:>

        CustomLog ${APACHE_LOG_DIR}/access.log combined

  <...with this, if you still want to log everything except the MJPEG reloads:>

        SetEnvIf Request_URI "^/cam_pic.php" dontlog
        CustomLog ${APACHE_LOG_DIR}/access.log common env=!dontlog

    < then edit the other big logfile config:>

sudo nano /etc/apache2/conf.d/other-vhosts-access-log

    < and comment out this line, then save the file:>

    # CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined

   <and then:>
sudo service apache2 restart

User avatar
jbeale
Posts: 3476
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: RPi Cam Web Interface

Fri Jan 24, 2014 2:01 am

If silvanmelchior is monitoring, I recommend to put in the apache2 logfile changes in the post above into your distribution by default; otherwise the logfiles are going to explode in size and it hurts performance also.

In case anyone wants it, enclosed is my /etc/motion/motion.conf file that enables saving still images as well as video in the /var/www/media directory so you can see them in the browser. Maybe this could even be turned on/off from the web browser- left as an exercise for the reader :-) I also have set it to parse the image for motion at 3 fps instead of 2 fps, which will use more CPU; you can turn it back down if you want.
motion.conf.gz
(7.14 KiB) Downloaded 387 times
Last edited by jbeale on Fri Jan 24, 2014 5:53 am, edited 1 time in total.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: RPi Cam Web Interface

Fri Jan 24, 2014 2:55 am

Good catch, writing to the log file that much will also kill the SD card.

Return to “Camera board”