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

Re: RPi Cam Web Interface

Thu Jan 09, 2014 6:24 pm

Mrbcsimpson wrote:- Camera sensitivity (I get around 20 videos per 10 mins in an empty, evenly lit room)
- Change the port (I would like to port forward the Pi to view outside my home network)
Your "Camera sensitivity" issue is I believe a bug in 'motion' as it is being used here. See my previous post: I suspect you can prevent the issue using the "mask" option. If silvanmelchior is monitoring, it would probably be helpful to include this mask as standard in the installation, until we can fix motion's incomplete-JPEG-read problem.

The port-forwarding question is a general firewall issue. You need to change your home router to allow access to your Pi. Make sure you understand the security implications of doing so (no ssh passwords, un-used exposed services etc), because your Pi and perhaps all computers in your house could be compromised by hackers with port-scanning bot nets within minutes if you don't. Here is some reading to get you started:

http://alexdberg.blogspot.com/2012/11/c ... berry.html
http://raspi.tv/2012/how-to-set-up-keys ... spberry-pi
https://library.linode.com/securing-your-server
http://www.raspberrypi.org/phpBB3/viewt ... 63#p107163

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

Re: RPi Cam Web Interface - MOTION gets partial JPEG file?

Thu Jan 09, 2014 6:34 pm

buzzai wrote:I had a quick look at the motion code (using jpegutils to decode jpegs) and it seems it mmap's the mjpeg file and reads the frames from there.
Referring to http://stackoverflow.com/questions/1462 ... aced-on-di (see the response to the question) the contents of this mmap'ed file change unnoticed as soon as this file is renamed...
SO it seems like motion is still processing the mjpeg file contents when raspimjpeg decides to rename the file.
As you said, there's no handshake between the two processes, so as long as motions decodes the jpegs faster than raspimjpeg renames them, there's no problem. Any hickup and we get gray blocks (or worse, depending on how error-proof the mjpeg decoding of jpegutils is).
Sounds like you've found the issue. Is "motion" simply re-reading this file asynchronously at its fixed sample rate (3 fps?) or does it somehow detect when the data is changed (apparently not?) What is not clear to me is the most suitable way to avoid this problem. Is there any solution that does not require modifications to "motion"? If motion is not synchronized to the data source, how does it ever work properly and avoid partial-frame data problems? Seems to me if the file rename from raspimjpeg is asynchronous to motion's read of the mmap'd file, then you will eventually get a split frame. If motion is 2x faster it happens 1/2 as often on average, but there is no speed at which it cannot happen (except for the granularity / blocksize of memory paging I guess). Was this architecture designed assuming some uncompressed YUV / RGB format, where each image always has the same number of bytes, so if you get an image that contains part (new frame) and part (new frame - 1) data, it makes little difference?

One workaround would be to simply use uncompressed image data (YV12 ?) to pass the image between raspimjpeg and motion, instead of JPEG. As long as you limit the update rate to that actually used by motion (3 fps I think) you are not actually using more CPU overall. It's just the JPEG decode happens in raspimjpeg (or even direct from GPU?) instead of inside motion.

User avatar
g7ruh
Posts: 68
Joined: Mon Apr 23, 2012 9:49 am
Location: Blackfield UK

Re: RPi Cam Web Interface

Thu Jan 09, 2014 8:04 pm

silly question, maybe, but could the grey blocks be caused by an operating system issue like incomplete write to disk (i.e. if sync is used it would not occur as cached data write is forced by sync) and the other process grabs it before the O/S has completed its "housekeeping"

lateral thinking maybe, but can someone discount this as the issue? It certainly seems like a timing issue.

Roger

User avatar
Mrbcsimpson
Posts: 17
Joined: Tue Jan 07, 2014 9:29 pm
Location: Lincolnshire, UK
Contact: Website

Re: RPi Cam Web Interface

Thu Jan 09, 2014 10:42 pm

jbeale wrote:
Mrbcsimpson wrote:- Camera sensitivity (I get around 20 videos per 10 mins in an empty, evenly lit room)
- Change the port (I would like to port forward the Pi to view outside my home network)
The port-forwarding question is a general firewall issue. You need to change your home router to allow access to your Pi. Make sure you understand the security implications of doing so (no ssh passwords, un-used exposed services etc), because your Pi and perhaps all computers in your house could be compromised by hackers with port-scanning bot nets within minutes if you don't.
Thanks for the reply, I understand that I have to port forward and I have the safety aspects covered here. Only when you view the Pi you do so through the IP, and without the addition of a port in the address bar ie :8080 it only shows .html
so my question would be, which port do I port forward after having used this tutorial?

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

Re: RPi Cam Web Interface

Thu Jan 09, 2014 11:57 pm

The standard webserver port is port 80. When your browser asks for "http://servername.com/index.html" you are making a request to servername.com on Port 80. See also: http://en.wikipedia.org/wiki/List_of_TC ... rt_numbers

sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Re: RPi Cam Web Interface

Fri Jan 10, 2014 12:30 am

poing wrote:It seems the banding is fps-related. It's getting dark now, when using 'Auto' the banding is bad, using 'Sports' it's very bad and using 'Night' it's gone.
I am having extremely bad horizontal banding with the videos that are being generated. This is odd because raspistill and raspivid both produce high quality without the banding. In addition the video does not appear to be 1080P, have you managed to fix this issue?

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

Re: RPi Cam Web Interface

Fri Jan 10, 2014 12:42 am

I have not seen any banding on the video from my three Pi's running the RPi Cam web interface, for what that's worth. One thing this program does that raspivid doesn't is try to serve up MJPEG at the same time as recording the video. It can cause power supply fluctuations, and also RF interference to the camera if you are using wifi. See if the banding problem is still there on the video when you don't have any browser watching the live MJPEG view.

You can check the resolution of the mp4 video files using VLC, under Tools / Codec Information / Codec tab where for me it shows H264 - MPEG-4 AVC 1920x1080 at 25 fps. If you mean the image quality isn't what you expect from 1080p, that is very likely. It is my experience that you want perfect lighting conditions like outdoor full sun (and also with very little motion) to see full image quality out of this camera. Anything indoors or in dim light, the automatic noise reduction kicks in to remove noise (and detail). In adition, anything moving also gets blurred not just by the shutter speed but due to the temporal noise reduction filter. As far as I know the noise reduction cannot be reduced or turned off. So if your application is a security camera to capture detailed images from moving subjects, it's not the ideal tool.

sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Re: RPi Cam Web Interface

Fri Jan 10, 2014 1:50 am

jbeale wrote:I have not seen any banding on the video from my three Pi's running the RPi Cam web interface, for what that's worth. One thing this program does that raspivid doesn't is try to serve up MJPEG at the same time as recording the video. It can cause power supply fluctuations, and also RF interference to the camera if you are using wifi. See if the banding problem is still there on the video when you don't have any browser watching the live MJPEG view.

You can check the resolution of the mp4 video files using VLC, under Tools / Codec Information / Codec tab where for me it shows H264 - MPEG-4 AVC 1920x1080 at 25 fps. If you mean the image quality isn't what you expect from 1080p, that is very likely. It is my experience that you want perfect lighting conditions like outdoor full sun (and also with very little motion) to see full image quality out of this camera. Anything indoors or in dim light, the automatic noise reduction kicks in to remove noise (and detail). In adition, anything moving also gets blurred not just by the shutter speed but due to the temporal noise reduction filter. As far as I know the noise reduction cannot be reduced or turned off. So if your application is a security camera to capture detailed images from moving subjects, it's not the ideal tool.
Thanks for the tip! I believe I have the pi sitting next to my wifi router at the moment, I'll move it when I get home for some additional testing. After checking with VLC it indeed shows it's 1080p, the quality is just not good at all. It is currently in low light so perhaps that is the issue. Unfortunately for me I would like to use this for some perimeter security around my property, detail isn't the most important aspect but it is definitely desirable.

UPDATE moving the cable away from the pi board appears to have resolved my horizontal scan lines and improved quality (less noise)!
Last edited by sedonami on Fri Jan 10, 2014 7:12 am, edited 1 time in total.

User avatar
Mrbcsimpson
Posts: 17
Joined: Tue Jan 07, 2014 9:29 pm
Location: Lincolnshire, UK
Contact: Website

Re: RPi Cam Web Interface

Fri Jan 10, 2014 6:33 am

jbeale wrote:The standard webserver port is port 80. When your browser asks for "http://servername.com/index.html" you are making a request to servername.com on Port 80. See also: http://en.wikipedia.org/wiki/List_of_TC ... rt_numbers
Exactly the information that I was after, thank you very much.

sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Re: RPi Cam Web Interface

Fri Jan 10, 2014 8:06 am

jbeale wrote:
20140107_214806.jpg
Out of curiousity how are you getting the timestamp added to the image? I must be missing a setting here somewhere as I can't seem to get this effect.

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: RPi Cam Web Interface

Fri Jan 10, 2014 8:31 am

It is standard motion feature.
in motion.conf:

Code: Select all

# Draws the timestamp using same options as C function strftime(3)
# Default: %Y-%m-%d\n%T = date in ISO format and time in 24 hour clock
# Text is placed in lower right corner
#text_right %Y-%m-%d\n%T-%q
Just make sure you do not have the comment sign in front of the text_right

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

Re: RPi Cam Web Interface

Fri Jan 10, 2014 2:44 pm

For the gray block issue, did anyone try providing the netcam_url with the http protocol to the JPG image instead of the file protocol? I believe the web server should be able to provide a true complete JPG or MJPEG stream that meets the motion requirements.

sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Re: RPi Cam Web Interface

Fri Jan 10, 2014 4:36 pm

shuckle wrote:It is standard motion feature.
in motion.conf:

Code: Select all

# Draws the timestamp using same options as C function strftime(3)
# Default: %Y-%m-%d\n%T = date in ISO format and time in 24 hour clock
# Text is placed in lower right corner
#text_right %Y-%m-%d\n%T-%q
Just make sure you do not have the comment sign in front of the text_right
Thanks, I have tried this and rebooted but still no timestamp. Is there possibly something else i'm missing?

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

Re: RPi Cam Web Interface

Fri Jan 10, 2014 5:26 pm

sedonami wrote:Thanks, I have tried this and rebooted but still no timestamp. Is there possibly something else i'm missing?
Note the timestamp is not generated from raspimjpeg so it isn't on the MJPEG and does not appear in your browser. It only appears in the JPEG saved by 'motion' upon motion-detection. That jpeg will be saved wherever you put as your output directory in the motion.conf file, by default that is not /var/www/media like the stills and video saved from raspimjpeg, so you won't see them there unless you've changed your /etc/motion/motion.conf file to point its output directory there, for example

Code: Select all

# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
# CHANGED
target_dir /var/www/media

sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Re: RPi Cam Web Interface

Fri Jan 10, 2014 5:58 pm

jbeale wrote:
sedonami wrote:Thanks, I have tried this and rebooted but still no timestamp. Is there possibly something else i'm missing?
Note the timestamp is not generated from raspimjpeg so it isn't on the MJPEG and does not appear in your browser. It only appears in the JPEG saved by 'motion' upon motion-detection. That jpeg will be saved wherever you put as your output directory in the motion.conf file, by default that is not /var/www/media like the stills and video saved from raspimjpeg, so you won't see them there unless you've changed your /etc/motion/motion.conf file to point its output directory there, for example

Code: Select all

# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
# CHANGED
target_dir /var/www/media
jbeale thanks again! That helped as well, however it appears as though those images are turned off be default. To turn them on I added the following line in motion.conf and it worked.

Code: Select all

output_normal first

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

Re: RPi Cam Web Interface

Sun Jan 12, 2014 5:38 pm

I found something strange...

I re-installed RPi Cam Web Interface and it's dark outside now. When I set the Exposure Mode to 'Night' the picture gets brighter than before (a few weeks ago) while the scene outside is the same. If I then take a still image the exif says 1 sec ISO 1600! And indeed, the images as seen on the webpage take a second to refresh where it was quicker before.

Somehow this overrides the ISO 800 limitation that is inside Raspistill when using -ex night for I tried but cannot get it to ISO 1600, even with -t 10000.

Apart from that I still get a corrupted card after a few hours, there's still some banding (also when I take a regular video in daylight with Raspivid, used not to have that) and when I take a video using the web interface it renders black on the webpage but they show normal when downloaded. Possibly there's something wrong with my setup.

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

Re: RPi Cam Web Interface

Sun Jan 12, 2014 10:48 pm

poing wrote:I found something strange...

I re-installed RPi Cam Web Interface and it's dark outside now. When I set the Exposure Mode to 'Night' the picture gets brighter than before (a few weeks ago) while the scene outside is the same. If I then take a still image the exif says 1 sec ISO 1600! And indeed, the images as seen on the webpage take a second to refresh where it was quicker before.

Somehow this overrides the ISO 800 limitation that is inside Raspistill when using -ex night for I tried but cannot get it to ISO 1600, even with -t 10000.
In the past day or two JamesH and Dom updated the firmware to improve the shutter/ISO setting range available to the "night" exposure mode, as you just found out. Post here: http://www.raspberrypi.org/phpBB3/viewt ... 00#p485562

I have not seen banding on my 1 sec, ISO-1600 photos, except for the usual slight vertical lines which are fixed-pattern noise due to lack of per-sensor dark-frame calibration.

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

Re: RPi Cam Web Interface

Sun Jan 12, 2014 11:32 pm

OK, missed that, but I can't seem to mimic the ISO 1600 1 sec behaviour with normal raspistill, only with the web cam.

I have no banding on the -ex night shots, only with faster shutter speeds and mainly in the video. So it seems interference with higher shutter speeds, will look again tomorrow.

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

Re: RPi Cam Web Interface

Mon Jan 13, 2014 10:08 am

I now started out with the latest 2014-1-7 Wheezy and the banding is gone while motion suddenly works. So I guess updating an older Wheezy, like I did before, has some issues. I'm now letting the Webcam run and see if I get a corrupted file system again after a few hours, guess not.

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

Re: RPi Cam Web Interface

Mon Jan 13, 2014 6:28 pm

Could some kind person explain how I could modify the code to rotate the camera view 180 degrees on start up please?

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

Re: RPi Cam Web Interface

Mon Jan 13, 2014 8:28 pm

talkeasy wrote:Could some kind person explain how I could modify the code to rotate the camera view 180 degrees on start up please?
The RPi Cam Web Interface is based on silvanmelchior's application called RaspiMJPEG. There is a README file in the github code which you can see here: https://raw.github.com/silvanmelchior/u ... piMJPEG.md which lists all the possible configurations and commands. RaspiMJPEG is controlled by sending commands into the named pipe /var/www/FIFO. For example if you check the 'motion' config file /etc/motion/motion.conf you will see the the video recording is started by this line:

Code: Select all

on_event_start echo 'ca 1' > /var/www/FIFO
In your case you want to send "ro 180" into the pipe at startup to set the 180 degree rotation. So I think you could add

Code: Select all

echo 'ro 180' > /var/www/FIFO
after the startup command in /etc/rc.local but I'm not sure if you need to wait a bit after startup for it to be listening, and I don't have the Pi in front of me now to try it. Anyway I think that should work.

yvonnezoe
Posts: 127
Joined: Thu Feb 14, 2013 2:10 am
Contact: Website

Re: RPi Cam Web Interface

Tue Jan 14, 2014 1:02 am

I just wanted to ask if I have to rewrite my SD card before I try this out because I've previously installed motion and openCV (which both of them doesnt work very well for me :( ). Will all these crash when put together? Also, I will be expecting to install CherryPy server, so my web app will start when I start CherryPy. I hope to include a camera output window (from RPi camera) in the web app but I'm confused how all these can be put together to work? :cry:
Just started my Raspberry Pi journey >> http://yvonnezoe.wordpress.com

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

Re: RPi Cam Web Interface

Tue Jan 14, 2014 4:43 am

yvonnezoe wrote:I just wanted to ask if I have to rewrite my SD card before I try this out because I've previously installed motion and openCV (which both of them doesnt work very well for me :( ). Will all these crash when put together? Also, I will be expecting to install CherryPy server, so my web app will start when I start CherryPy. I hope to include a camera output window (from RPi camera) in the web app but I'm confused how all these can be put together to work? :cry:
You should not have to rewrite the SD card, but that is the most foolproof way to get things working. When you say motion and openCV are not working well for you, I wonder if there is some configuration wrong on your setup. At the very least I recommend un-installing whatever is not working, before installing trying out new software. You would not want two different versions of motion running at the same time, for example.

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

Re: RPi Cam Web Interface

Tue Jan 14, 2014 9:56 am

I have a question.
I have setup the RPi Cam Web Interface and it is running quite stable.
But after twilight begins i have to stop the camera because motion does not stop to record videos.
Is this normal? What can i do?

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

Re: RPi Cam Web Interface

Tue Jan 14, 2014 11:43 am

I'd definitely would start with a fresh image, had all sorts of troubles before but it's now running for more than 24 hours without a glitch.

I've no problems at night when using -ex night exposure mode although that will revert to 1 sec shutter speed and I get video clips of one frame, apparently because motion rereads the same frame and decides there's no motion. When motion is running all the time with street lighting it's possible the lights are pulsating with different colors so each frame would have a different color and motion thinks it's motion due to the color shifts; I guess ;-)

Return to “Camera board”