User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: RPi Cam Web Interface

Wed Dec 18, 2013 3:22 am

not all options change the picture you see in the webpage,
but they change the captured picture (video) you will find then here
(pls. play for example with jpeg quality and check file size )
ls /var/www/media/
the picture in the webpage is NOT stored on SD card ( very good software )
ls /run/shm/mjpeg/

but the last change with free camera and restart :
-1- i don't think that operation should be on the web page
-2- it not helps for cpu load ( i still see 45% )
possibly change the complete autostart (erase in /etc/rc.local ) to a usual service
and make it even operational from Desktop like i show here
http://kll.engineering-news.org/kllfusi ... _id=56#gui
( i am just a linux beginner so there might be much better ways)

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

Re: RPi Cam Web Interface

Wed Dec 18, 2013 5:18 pm

I found a bug in my code, with the new update my interface needs much less cpu load and nearly nothing (0-0.3%) in idle state, so the idle autostart option is very useful now. Just run the installer again as described in the first post.

There were some questions, why the live-feed gets stuck sometimes: That's because there is no buffering, every frame is directly displayed on the website. So there is a very small delay between the cam and the website, but you see every single transmission error/delay. So as jbeale suggested, don't use wifi and lower the jpeg-quality and size of the preview if needed. The parameters can be found in /etc/rc.local

And there was a question why I add a timestamp to live-preview-path in javascript. That's an easy cross-browser way to prevent buffering, so that the image is really loaded from the RPi.

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

Re: RPi Cam Web Interface

Wed Dec 18, 2013 7:49 pm

Thanks, the CPU is significantly less now with the update.

Question: Is there any queuing between the live-view write to shared-memory and the GET that reads it? If not, I believe one reason for the choppyness and momentary freezes may be deadlock occurring between writes and reads. If this is the case, perhaps a queuing mechanism with a TTL would help. I guess this is a sort of buffering but what I am noticing is that the GET requests are getting hung (BTW: using wired network) then resuming matching how the live-view is updated (using LiveHTTPHeaders plugin). I notice in this implementation (although python based) queuing seems to be used:

https://gist.github.com/tzicatl/2409785

UPDATE: It appears it is not a deadlock reading and writing to /dev/shm area as with raspimjpeg killed, the same issue occurs, i.e. it should be streaming the sole cam.jpg file that is no longer updated and doing so smoothly, however it is straming it the same way with freezes therefore it would appear it is related to the client size browser making the requests or apache on the Pi not able to keep up.

UPDATE2: Well, tested MJPEG-Streamer also and same behavior so it appears to be a general issue not related to this effort. If no one else is having this issue on a hard-wire network connection then I will need to check things on my end.
Last edited by stefan.knight on Thu Dec 19, 2013 1:28 am, edited 2 times in total.

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

Re: RPi Cam Web Interface

Wed Dec 18, 2013 9:11 pm

silvanmelchior wrote:I found a bug in my code, with the new update my interface needs much less cpu load and nearly nothing (0-0.3%) in idle state, so the idle autostart option is very useful now. Just run the installer again as described in the first post.
Re installed with the autostart_idle option, but top still shows around 33% for raspimjpeg when the Pi is started. Raspimjpeg is idle.

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

Re: RPi Cam Web Interface

Thu Dec 19, 2013 10:38 am

After another breakdown (corrupted SD card) I flashed the SD and re installed RPi Cam; now it works with only 0.3% when idle, great! I'll let it run to see if it's more stable now; guess I messed up somewhere before.

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

Re: RPi Cam Web Interface

Thu Dec 19, 2013 11:36 pm

Silvan, I know this is based on the RaspiMJPEG work you did earlier. However, is there an option you can put in to pass the H.264 (box with MP4) preview instead of the MJPEG. Since I plan to use this on some surveillance cameras which will have WiFi, I need to conserve the bandwidth as even with a hard-wire connection, the MJPEG is choppy and not like I would like to have it as shown in your youtube video.

UPDATE: Well, you can ignore this request. I figured out my wired adapter was the issue. It is very old and limited to 10BaseT. With the WiFi adapter it is now working but still not ideal. I googled some stuff and this code seems to work quite smoothly, just not sure how to incorporate it.

Code: Select all

<?php
# Used to separate multipart
$boundary = "my_mjpeg";

# We start with the standard headers. PHP allows us this much
header("Cache-Control: no-cache");
header("Cache-Control: private");
header("Pragma: no-cache");
header("Content-type: multipart/x-mixed-replace;boundary=$boundary");

# From here out, we no longer expect to be able to use the header() function
print "--$boundary\n";

# Set this so PHP doesn't timeout during a long stream
set_time_limit(0);

# Disable Apache and PHP's compression of output to the client
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);

# Set implicit flush, and flush all current buffers
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++)
    ob_end_flush();
ob_implicit_flush(1);

# The loop, producing one jpeg frame per iteration
while (true) {
    # Per-image header, note the two new-lines
    print "Content-type: image/jpeg\n";
    print "Content-Length: 76800\n\n";

    # Your function to get one jpeg image
    readfile("/dev/shm/mjpeg/cam.jpg");

   print "\n\n";

    # The separator
    print "--$boundary\n";
}


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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 3:50 am

Seems RaspiMJPEG has a memory leak after it has been running for a while:

Code: Select all

[14461.487182] Out of memory: Kill process 2436 (raspimjpeg) score 392 or sacrifice child
[14461.499824] Killed process 2436 (raspimjpeg) total-vm:127644kB, anon-rss:51728kB, file-rss:0kB

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 3:55 am

poing wrote:After another breakdown (corrupted SD card) I flashed the SD
I've had a number of SD card corruption problems after I loaded the RPI Cam Web Interface. At first I thought it was an unrelated coincidence. Seeing your comment, I'm not so sure. I'm using my second Rpi (v. 2) with a freshly download of Raspbian with updates. I just did a fresh download/install of the interface(12/20/2013). I checked voltages on the powers supply under load (5.35 V) and switched several SD cards.

Symptoms: The browser interface will stop but the ssh link as well as pinging the IP address will be stay up. However, typing any command into the ssh console (such as "ls") will return "command not found.
Recording a video and playing it back seems to accelerate the "crash" of the browser interface.
I need to do a windows scandisk on the SD card before it will reboot.
The SD cards are all "HC" rated but different brands. They behave somewhat differently. The oldest, a ativa 4GB, is the worst, a 32 GB Linirex is better but still end up the same. I tend to buy the cheapest SD card I can find, so it possible they are all marginal.

Would over-clocking help or make thing worse? Perhaps my problems are unrelated. I don't know.
Edit: Hardware/SD card runs normally with dronkert.net webcam installation.
Last edited by rleyden on Fri Dec 20, 2013 2:27 pm, edited 2 times in total.

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 7:13 am

I recognize those symptoms, but I doubt it's the SD card as my Pies have been super stable with the used Sandisk 8GB class 4 cards, running for month. I'm running RPi Cam now for 20 hours and can still record and playback videos or stop and start raspimjpeg without a glitch. Early days, but the problems seem to have ended with the latest update where the CPU drops to 0.3% when raspimjpeg is idle.

andlinux
Posts: 18
Joined: Fri Dec 13, 2013 12:08 pm
Location: Belgium

Re: RPi Cam Web Interface

Fri Dec 20, 2013 10:13 am

Here it's still working. The RPi is almost 2 days on without a reboot.
I still didn't update the RPi Cam Web interface.

Gonna do that now :)

EDIT: Well, I have no idea if it's updated. I did all the 3 steps like in the first post but the cpu rate is still high (33.6%)
Same problem as poing ?

Code: Select all

 2126 root      20   0 76644 1400  756 S  33.6  1.1   0:40.66 raspimjpeg        
EDIT2: Just updated the 2nd Pi and there it's normal.

Code: Select all

2134 root      20   0 76516 1276  756 S   4.9  0.3   0:01.71 raspimjpeg

yoshiwa
Posts: 9
Joined: Mon Dec 09, 2013 6:07 pm

Re: RPi Cam Web Interface

Fri Dec 20, 2013 12:14 pm

Same issue over here indeed , still high cpu for raspimjpeg , even after update and reboot :)

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 1:40 pm

I re-flashed the SD card and did all the updates before it worked.

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 1:45 pm

...but it's now stuck again after 27 hours :? Recorded a video but can't stop it anymore, display is frozen. I can ssh into the Pi and top shows about 70% for Apache but I can't see raspimjpeg listed...

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 2:15 pm

poing wrote:...but it's now stuck again after 27 hours :? Recorded a video but can't stop it anymore, display is frozen. I can ssh into the Pi and top shows about 70% for Apache but I can't see raspimjpeg listed...

see what the dmesg command shows. Probably the same out of memory like mine?

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 3:08 pm

dmesg gives me:

Code: Select all

[66428.114190] Out of memory: Kill process 2917 (raspimjpeg) score 425 or sacrifice child
[66428.114209] Killed process 2917 (raspimjpeg) total-vm:194468kB, anon-rss:43492kB, file-rss:344kB

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 3:11 pm

poing wrote:dmesg gives me:

Code: Select all

[66428.114190] Out of memory: Kill process 2917 (raspimjpeg) score 425 or sacrifice child
[66428.114209] Killed process 2917 (raspimjpeg) total-vm:194468kB, anon-rss:43492kB, file-rss:344kB
yes, same as mine. Hopefully Silvan can have a look where the slow leak is occurring.

delinend
Posts: 20
Joined: Thu Dec 27, 2012 12:43 pm

Re: RPi Cam Web Interface

Fri Dec 20, 2013 6:02 pm

Hmm.. Right now, I can't make a wget from "wget http://grustu.ch/share/rpi_cam/RPi_Cam_ ... staller.sh" :?

andlinux
Posts: 18
Joined: Fri Dec 13, 2013 12:08 pm
Location: Belgium

Re: RPi Cam Web Interface

Fri Dec 20, 2013 6:05 pm

Today I had that same problem, after some minutes I was able to do a wget.

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 8:46 pm

First of all, thanks a lot for your testings! I found a memory leak in my code (I used asprintf without free) and fixed it and I'm running a long-time test now. The new software is already online, if you want to update your RPi just go through the steps in my first post as usual.

Additionally I added a way to check if the update was successful, to prevent long-time tests without a successful update. So after going throught the steps in my first post, run "raspimjpeg --version" and check if it outputs "RaspiMJPEG Version 1.0". Then check if the file /var/www/Version.txt" exists and contains "1.0". If so, the update was successful.

@Stefan: At the moment I don't use a queue, but I write into "cam.jpg.part" and rename it to "cam.jpg" afterward. I don't know how your preview looks like, but with my setup the mjpeg is very smooth, but it stucks sometimes for approximately 0.5s.
And thanks a lot for your googled code, if I find the time I try if works better this way.

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 9:46 pm

silvanmelchior wrote:First of all, thanks a lot for your testings! I found a memory leak in my code (I used asprintf without free) and fixed it and I'm running a long-time test now. The new software is already online, if you want to update your RPi just go through the steps in my first post as usual.

Additionally I added a way to check if the update was successful, to prevent long-time tests without a successful update. So after going throught the steps in my first post, run "raspimjpeg --version" and check if it outputs "RaspiMJPEG Version 1.0". Then check if the file /var/www/Version.txt" exists and contains "1.0". If so, the update was successful.

@Stefan: At the moment I don't use a queue, but I write into "cam.jpg.part" and rename it to "cam.jpg" afterward. I don't know how your preview looks like, but with my setup the mjpeg is very smooth, but it stucks sometimes for approximately 0.5s.
And thanks a lot for your googled code, if I find the time I try if works better this way.
Thank you very much for the update on the memory leak. I have updated now and will test. Yes, you preview is smooth and I do see the sticking also. The code I found seems to remedy this. To test it out, just create a separate php file in /var/www and paste it in and hit it directly with the browser. If you find it works better and an improvement, then it would be great to see it incorporated.

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

Re: RPi Cam Web Interface

Fri Dec 20, 2013 10:47 pm

Re-flashed the card, did the updates as indicated. THIS IS FANTASTIC!!!! Display is *SMOOTH* (based on preliminary 30 second initial view).

Looking again at the webpage a few minutes later: @Silvian: My gut feeling: YOU NAILED IT!!!; This is really great, smooth, lickin' my fingers!

Sadly it's bedtime for me so I'll look again in the morning. I'll keep it running.

WOW!!!!!!!!

yeme
Posts: 7
Joined: Sun Jul 28, 2013 9:29 pm

Re: RPi Cam Web Interface

Sat Dec 21, 2013 1:24 am

I too have this streaming with Chrome. I am trying to have my video surveillance software pick up this video stream and need help with the path of the displayed stream on the Pi. From my review of this thread, I am trying: /run/shm/mjpeg/ with no success. Any suggestions?

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

Re: RPi Cam Web Interface

Sat Dec 21, 2013 2:53 am

yeme wrote:I too have this streaming with Chrome. I am trying to have my video surveillance software pick up this video stream and need help with the path of the displayed stream on the Pi. From my review of this thread, I am trying: /run/shm/mjpeg/ with no success. Any suggestions?
the image is here:
/dev/shm/mjpeg/cam.jpg

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

Re: RPi Cam Web Interface

Sat Dec 21, 2013 3:05 am

yeme wrote:I too have this streaming with Chrome. I am trying to have my video surveillance software pick up this video stream and need help with the path of the displayed stream on the Pi. From my review of this thread, I am trying: /run/shm/mjpeg/ with no success. Any suggestions?
If your software is not running on the Pi, you need a URL to access the stream over the network. For example, whatever your Chrome browser is pointed to. Or are you remotely accessing your Pi's filesystem via Samba, etc.?

I don't know exactly what your software expects but I think this implementation relies on the remote web browser running a javascript .js file that keeps hitting the Apache server to reload each new JPEG image. The R-Pi just captures and saves the jpeg image from the camera and also hosts the webserver, but it does not send out a "stream" of images on its own, without the continual action of the javascript code.

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

Re: RPi Cam Web Interface

Sat Dec 21, 2013 11:38 am

Hmmm, celebrating too early... After 12 hours a completely locked up Pi after stopping the camera. Although the stream is very smooth, the videos it produces have a lot of very irregular banding going on as you can see in the screen dumps below. Look at the green horizontal bars, the white reflection is from the flat cable.
banding1.jpg
banding1.jpg (46.93 KiB) Viewed 9065 times
banding2.jpg
banding2.jpg (53.03 KiB) Viewed 9065 times

Return to “Camera board”