User avatar
jacksonliam
Posts: 181
Joined: Tue Feb 07, 2012 10:09 pm

Re: RaspiMJPEG

Wed Dec 11, 2013 9:23 pm

I'll take a look at this code sometime, it seems similar to my MJPG-Streamer fork with an mmal based raspi-cam plugin.

Most of the development happened here:
http://www.raspberrypi.org/phpBB3/viewt ... 43&t=45178

Code is kept here:
https://github.com/jacksonliam/mjpg-streamer

It pipelines frames into the jpeg stills encoder to get the individual jpegs directly into the mjpg-streamer buffers, much more efficient than using input_file.so, CPU use is very low.

Are you able to store h.264 while streaming mjpg? Thats something I'd like to be able to do (along with time-lapse creation).

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

Re: RaspiMJPEG

Wed Dec 11, 2013 10:09 pm

Yes, the preview-output of the camera is connected to a image-resizer and then to a jpg-encoder and the video-output is connected to a h264-encoder. RaspiMJPEG receives commands with a Unix-Pipeline to start/stop video capturing (1920x1080, 30fps) or even take a full-res snapshot (5M), because there is a second jpg-encoder connected to the image-output of the camera.

A I mentioned with my installer it's possible to see the camera-preview in a website (like with mjpeg-streamer) and control camera settings and take a video/picture from this website, so you have a control interface for your camera as a homepage.

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

Re: RaspiMJPEG

Wed Dec 11, 2013 11:38 pm

RaspiMJPEG is interesting to me as an example of code that saves full-res HD and at the same time delivers lower-resolution JPEGS. If I ever find the time, I'm hoping to combine this with some code like the 'motion' application, that processes low-resolution still frames looking for changes (eg. someone walking by) and can then immediately flag that point in the high-res video as the interesting part. Or perhaps save the .h264 file in 5-second-long chunks (eg. raspivid "--segment" feature) and continuously delete / overwrite all of them except where motion was detected, so just that part is archived.

The vanilla "motion" security-camera application already works on the R-Pi, but only at relatively low framerate and not full resolution. Being able to detection motion with at least several fps and then store full-HD from that point in time would be a big leap forward in capability for that use case.

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

Re: RaspiMJPEG

Thu Dec 12, 2013 7:35 am

I have compiled and installed both raspimjpeg and mjpg_streamer according to the instructions earlier in this thread, here and here.

When I try mjpeg-streaming from the R-Pi like this:

Code: Select all

raspimjpeg -w 1280 -h 720 -d 1 -of /run/shm/img.jpg &
LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /run/shm -n img.jpg" -o "output_http.so -w /usr/local/www" &
the stream is visible on my WinXP computer (quadcore Q9550 @ 2.83 GHz) but the framerate is very slow and stuttery (uneven), even if I drop down to 640x480 resolution and "-d 2". This is ethernet (not wireless) and 'iperf' says my network bandwidth from R-Pi to WinXP box is consistently 72 Mbit/sec so that ought to be enough. The youtube video demo here shows quite smooth low-latency video on the laptop screen. I have done this now with two completely different R-Pi setups and two WinXP machines and got the same stuttery results, with lag up to several seconds. I tried Firefox and also Chrome as the browser. Any ideas what could be wrong with my setup?

As far as I can tell raspimjpeg can deliver around 25 fps at 640x480 so maybe the issue is the mjpg_streamer code. Was the youtube demo done with mjpg_streamer, or something else?

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

Re: RaspiMJPEG

Thu Dec 12, 2013 9:18 am

@jbeale: I have the RaspiMJPEG compiled now on the Pi but I don't understand at this point how to make the stream visible on Windows. Could you elaborate a bit? I can show the stream from Raspivid with netcat and mplayer.

Joe116
Posts: 24
Joined: Thu Apr 04, 2013 9:22 am

Re: RaspiMJPEG

Thu Dec 12, 2013 9:49 am

silvanmelchior wrote:Just a little information: I've written an installer that installs raspimjpeg and appache with a little website on Raspbian, so all you have to do is to run the installer (shell-script) and you'll be able to see the camera preview on a website (640x360 px, 30 fps). I'm going to write a tutorial and will add a link here as soon as I have some free time.
Hello silvanmelchior,

that sound's really great!
I like to add a pan / tilt feature with two rc servos and the servoblaster (servod) for raspi which I used already for other projects, maybe in the way that the PT can used like a foscam from any app...

Sorry to bother you but when we can expect the update?

KR

Joe

Joe116
Posts: 24
Joined: Thu Apr 04, 2013 9:22 am

Re: RaspiMJPEG

Thu Dec 12, 2013 10:17 am

I now try this https://github.com/jacksonliam/mjpg-streamer
After installing

Code: Select all

aptitude install cmake libx11-dev libjpeg62-dev
I was able to compile
and run

Code: Select all

~/mjpg-streamer/mjpg-streamer-experimental# ./mjpg_streamer -o "output_http.so -p 80 -w ./www" -i "input_raspicam.so -x 1280 -y 720 -fps 10 -quality 40"
Open the stream in tinycammonitor pro on my Nexus 4 with:
[url]http://<ip>/?action=stream&ignored.mjpg[/url]
Shows me up to 5,0fps (around 2500kb / sec) --> WiFi G 54mbit is the limit here!

Or just open in browser:
[url]http://<ip>[/url]
To see all possible types of streaming (mjpeg, javascript, java...)

With an load below 0.5 wow!!!

if you run mjpeg_streamer with:

Code: Select all

~/mjpg-streamer/mjpg-streamer-experimental# ./mjpg_streamer -o "output_http.so -p 80 -w ./www" -i "input_raspicam.so -x 1280 -y 720 -fps 30 -quality 20"
You get up to 12fps with 1280x720 @ 2500kb/sec --> if you raise the jpeg quaility to 40 the fps will go town to max. 5 but with the same rate! If a second client is open an stream the framrate goes down to the half...

Sorry to highjack this thread...

Edit: it depents on the jpeg quality how many frames are send! --> with 1080p and quality 5 you will get 8 to 12fps but with quality 50 you will get only 0.5fps, so after some tests in 720p with quality 5 i get 20fps with an load from below 0.3. And in this case the fps will not drop to half when a second stream is opened..

KR

Joe
Last edited by Joe116 on Thu Dec 12, 2013 3:24 pm, edited 2 times in total.

gordon77
Posts: 5164
Joined: Sun Aug 05, 2012 3:12 pm

Re: RaspiMJPEG

Thu Dec 12, 2013 11:11 am

I am using Raspistill to save jpgs as fast as possible, currently approx every 750mS upto 960x720, I then process them. I need to use many of the options eg -t 0 -tl 0 -iSO 800 -ex off -ss 150 -br 70 -co 90 etc

Could I use RaspiMJPEG for this, does it allow me to set ISO, exposure, shutter speed ?

It's sounds like it should work faster than Raspistill.

Gordon77

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

Re: RaspiMJPEG

Thu Dec 12, 2013 12:04 pm

@jbeale: No, the demo-video was with appache installed on RPi and a little homepage that reloads the picture with javascript, a similar homepage will be included in my installer, bit there you can also control the camera settings (brightness, contrast, ...)

@Joe116: I try to publish it this Sunnday

@gordon77: Yes, with raspimjpeg -w xxx -h yyy -d 1 -of /path/to/pic_%04d.jpg for example you can save 30 pictures a second, if your sd-card is fast enough. To set camera settings you need to give raspimjpeg with the parameter -cf a path to a unix-pipe and now you can write the settings while raspimjpeg is running into this pipe, so you can change the settings during the timelapse. All information are in the readme on github (Readme_RaspiMJPEG.md)

gordon77
Posts: 5164
Joined: Sun Aug 05, 2012 3:12 pm

Re: RaspiMJPEG

Thu Dec 12, 2013 12:12 pm

silvanmelchior wrote:@jbeale: No, the demo-video was with appache installed on RPi and a little homepage that reloads the picture with javascript, a similar homepage will be included in my installer, bit there you can also control the camera settings (brightness, contrast, ...)

@Joe116: I try to publish it this Sunnday

@gordon77: Yes, with raspimjpeg -w xxx -h yyy -d 1 -of /path/to/pic_%04d.jpg for example you can save 30 pictures a second, if your sd-card is fast enough. To set camera settings you need to give raspimjpeg with the parameter -cf a path to a unix-pipe and now you can write the settings while raspimjpeg is running into this pipe, so you can change the settings during the timelapse. All information are in the readme on github (Readme_RaspiMJPEG.md)
Thanks , could you give me link to this readme.

Gordon77

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

Re: RaspiMJPEG

Thu Dec 12, 2013 5:15 pm

gordon77 wrote:Thanks , could you give me link to this readme.
Probably this one: https://github.com/silvanmelchior/userl ... piMJPEG.md

UPDATE: for proper text formatting use this: https://raw.github.com/silvanmelchior/u ... piMJPEG.md
Last edited by jbeale on Thu Dec 12, 2013 9:14 pm, edited 2 times in total.

gordon77
Posts: 5164
Joined: Sun Aug 05, 2012 3:12 pm

Re: RaspiMJPEG

Thu Dec 12, 2013 8:56 pm

jbeale wrote:
gordon77 wrote:Thanks , could you give me link to this readme.
Probably this one: https://github.com/silvanmelchior/userl ... piMJPEG.md
Thanks. I' ll admit it looks a bit

gordon77
Posts: 5164
Joined: Sun Aug 05, 2012 3:12 pm

Re: RaspiMJPEG

Fri Dec 13, 2013 11:20 am

gordon77 wrote:
jbeale wrote:
gordon77 wrote:Thanks , could you give me link to this readme.
Probably this one: https://github.com/silvanmelchior/userl ... piMJPEG.md
Thanks. I' ll admit it looks a bit
I am not sure what happend to the rest of this but here it is

Thanks. I have to admit it looks a bit complicated to me at present, never used pipe.

I assume for /path/to/image.jpg I put something like /dev/shm/image.jpg but what do I put for /path/to/pipe ?

Gordon77

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

Re: RaspiMJPEG

Fri Dec 13, 2013 11:51 am

Well, no problem, just post what exactly you want to do and I show you the commands you need to enter

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

Re: RaspiMJPEG

Fri Dec 13, 2013 12:24 pm

Well, I'm trying to make this work but I don't see a view.

First I used raspistill in combination with mjpeg-streamer, that workied but I always had problems with an image that got darker.
So I decided today to start all over, then I saw this RaspiMJPEG and wanted to try that. I also use Webiopi to close and open the chickencoop door and I can control the light (on/off).

I made a script:

Code: Select all

#!/bin/bash

nohup $(raspimjpeg -w 800 -h 600 -d 5 -of /run/shm/img.jpg) &

nohup $(LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /run/shm -n img.jpg" -o "output_http.so -w /usr/local/www") &
I made this executable with chmod +x stream

and when I start it with the next command
./stream

then I see this:

Code: Select all

pi@raspberrypi ~ $ ./stream
pi@raspberrypi ~ $ MJPG Streamer Version: svn rev:
 i: folder to watch...: /run/shm/
 i: forced delay......: 0
 i: delete file.......: no, do not delete
 i: filename must be..: img.jpg
 o: www-folder-path...: /usr/local/www/
 o: HTTP TCP port.....: 8080
 o: username:password.: disabled
 o: commands..........: enabled
If I do ps -aux I see this:

Code: Select all

pi       13093  0.0  0.7  35284   912 pts/1    Sl   13:16   0:00 raspimjpeg -w 800 -h 600 -d 5 -of /run/shm/img.jpg
pi       13094  0.0  0.6  18332   772 pts/1    Sl   13:16   0:00 mjpg_streamer -i input_file.so -f /run/shm -n img.jpg -o output_http.so -w /usr/local/www
But if I go to 192.168.1.6:8080 then there is no picture on the mjpg-streamer page.
see link: http://www.wuala.com/andlinux/Share/mjpg-streamer.jpg
Although I see that the page is loading constantly.

Now I'm out of ideas

EDIT: Well, I upgraded Raspbian and updated the firmware and now it's working (after the reboot) but how can I make a script so it will start when the RPi is booting, or do I have to put that "stream" script I made in /etc/init.d/ ?

EDIT2: Scratch the last edit, when I execute Joe116 his lines.

Code: Select all

nohup $(raspimjpeg -w 1280 -h 720 -d 5 -of /run/shm/img.jpg) &
nohup $(LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /run/shm -n img.jpg" -o 
Then it's working, the problem is that I'm doing this over an SSH session and when I close this session then there's no video feed.

Now I need to find a way to start these 2 lines and that the run in the background.
Last edited by andlinux on Fri Dec 13, 2013 2:33 pm, edited 2 times in total.

gordon77
Posts: 5164
Joined: Sun Aug 05, 2012 3:12 pm

Re: RaspiMJPEG

Fri Dec 13, 2013 2:14 pm

silvanmelchior wrote:Well, no problem, just post what exactly you want to do and I show you the commands you need to enter
Thanks, much appreciated

What I do with Raspistill is I run it as a python sub process and it continually stores images as fast as it can as a jpg, approx every 750mS

typical command:

Code: Select all

   raspistill -o /run/shm/test.jpg -co 90 -br 70 -t 0 -tl 0 -ex off -ss 150000 -ISO 800 -n  -w 800 -h 600
   p=subprocess.Popen(rpistr,shell=True, preexec_fn=os.setsid)
I then read the jpg, delete the file, process it and await the next one.

If I need to change any parameters I then stop the process and restart it with the new parameters.

Could RaspiMJPEG do this but faster ?

Gordon77

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

Re: RaspiMJPEG

Fri Dec 13, 2013 3:49 pm

@andlinux: just append a &-sign to the second line too and add both lines to /etc/rc.local before the exit-command. Attention: rc.local runs your commands as root.

@gordon77: no problem, here's how you do it in a shell, so you can adopt it for python.

1. Create pipe named PIPE with command "mknod PIPE p"
2. Start raspimjpeg with the pipe: "raspimjpeg -of /run/shm/test.jpg -w 800 -h 600 -d 2 -cf PIPE
3. raspimjpeg runs and writes /run/shm/test.jpg every 67ms (-d 2). Now upen up a second terminal and navigate to the same directory you were with the first terminal and you created your pipe
4. If you want to change the brightness to 70 for example, enter

echo "br 70" > PIPE

in the second terminal. All other commands are in the readme

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

Re: RaspiMJPEG

Fri Dec 13, 2013 4:16 pm

Update: As wished, I published my installer: http://www.raspberrypi.org/phpBB3/viewt ... 43&t=63276

gordon77
Posts: 5164
Joined: Sun Aug 05, 2012 3:12 pm

Re: RaspiMJPEG

Fri Dec 13, 2013 8:43 pm

silvanmelchior wrote:@andlinux: just append a &-sign to the second line too and add both lines to /etc/rc.local before the exit-command. Attention: rc.local runs your commands as root.

@gordon77: no problem, here's how you do it in a shell, so you can adopt it for python.

1. Create pipe named PIPE with command "mknod PIPE p"
2. Start raspimjpeg with the pipe: "raspimjpeg -of /run/shm/test.jpg -w 800 -h 600 -d 2 -cf PIPE
3. raspimjpeg runs and writes /run/shm/test.jpg every 67ms (-d 2). Now upen up a second terminal and navigate to the same directory you were with the first terminal and you created your pipe
4. If you want to change the brightness to 70 for example, enter

echo "br 70" > PIPE

in the second terminal. All other commands are in the readme
Thanks for the info. I tried to install raspimjpeg following your instructions but when l try to run it it cant find the program, what am l doing wrong ?

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

Re: RaspiMJPEG

Sat Dec 14, 2013 8:45 am

@silvanmelchior I did append a &-sign to the second line and I added these lines in my /etc/rc.local file.
I see that raspimjpeg is loaded when I do "ps -aux" but the mjpg-streamer not ?

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address


_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi


nohup $(raspimjpeg -w 800 -h 600 -d 5 -of /run/shm/img.jpg) &
nohup $(LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /run/shm -n img.jpg" -o &


exit 0
EDIT: Oops I did it wrong, I forgot some text.
nohup $(LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /run/shm -n img.jpg" -o "output_http.so -w /usr/local/www") &

But it's still not working at boot :(

gordon77
Posts: 5164
Joined: Sun Aug 05, 2012 3:12 pm

Re: RaspiMJPEG

Sat Dec 14, 2013 12:27 pm

gordon77 wrote:
silvanmelchior wrote:@andlinux: just append a &-sign to the second line too and add both lines to /etc/rc.local before the exit-command. Attention: rc.local runs your commands as root.

@gordon77: no problem, here's how you do it in a shell, so you can adopt it for python.

1. Create pipe named PIPE with command "mknod PIPE p"
2. Start raspimjpeg with the pipe: "raspimjpeg -of /run/shm/test.jpg -w 800 -h 600 -d 2 -cf PIPE
3. raspimjpeg runs and writes /run/shm/test.jpg every 67ms (-d 2). Now upen up a second terminal and navigate to the same directory you were with the first terminal and you created your pipe
4. If you want to change the brightness to 70 for example, enter

echo "br 70" > PIPE

in the second terminal. All other commands are in the readme
Thanks for the info. I tried to install raspimjpeg following your instructions but when l try to run it it cant find the program, what am l doing wrong ?
I found my mistake, missed your second line <doh>

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

Re: RaspiMJPEG

Sun Dec 15, 2013 2:38 pm

andlinux wrote:@silvanmelchior I did append a &-sign to the second line and I added these lines in my /etc/rc.local file.
I see that raspimjpeg is loaded when I do "ps -aux" but the mjpg-streamer not ?

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address


_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi


nohup $(raspimjpeg -w 800 -h 600 -d 5 -of /run/shm/img.jpg) &
nohup $(LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /run/shm -n img.jpg" -o &


exit 0
EDIT: Oops I did it wrong, I forgot some text.
nohup $(LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /run/shm -n img.jpg" -o "output_http.so -w /usr/local/www") &

But it's still not working at boot :(
Made some progress.
I included the full path of mjpg-streamer, like this:

Code: Select all

nohup $(LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/mjpg_streamer -i "input_file.so -f /run/shm -n img.jpg" -o "output_http.so -w /usr/local/www") &
As you can see I added /usr/local/bin and now I see that the process is running but when I look at my webpage then there is an image that is standing still, so no streaming video.

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

Re: RaspiMJPEG

Sun Dec 15, 2013 2:45 pm

I haven't ever used mjpeg-streamer, so if the process is running and it doesn't work, I can't help. Maybe anybody else?

But if you use mjpeg-streamer to show the stream on a website, there is a better solution here: http://www.raspberrypi.org/phpBB3/viewt ... 43&t=63276

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

Re: RaspiMJPEG

Sun Dec 15, 2013 3:11 pm

Yeah, I think I'm gonna try that. I only have to integrate the stream on my webiopi webpage so I can control the chickencoop.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: RaspiMJPEG

Wed Dec 25, 2013 6:52 pm

Hi,
This is a fantastic project, thank you for creating it and for these clear instructions, worked first time!
Two questions:
  1. I now get an error shown in the image below, what does it mean and how can I correct it?
RpiCamError.JPG
RpiCamError.JPG (18.71 KiB) Viewed 8548 times
  • What is the best way to reduce the bandwidth and how can this be done?
Thanks,
Shane
Pi = too much fun!

Return to “Camera board”