harlock74
Posts: 182
Joined: Fri Jan 18, 2013 10:47 am

MJPG and crontab

Sat Dec 07, 2013 11:48 am

Hi there,

I hope someone can help me out with this.

I have followed this guide here:

http://blog.miguelgrinberg.com/post/how ... spberry-pi

and everything is working like a charm as I can watch the stream in my browser.

I am now trying to automate the all process by using:

Code: Select all

crontab -e
which I have edited as follows:

Code: Select all

@reboot mkdir /tmp/stream && raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 && LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -w /usr/local/www"
Basically after rebooting my RPI I can see the new folder /tmp/stream, by running top I can see the raspistill is running but not mjpg. I am sure I am doing something wrong but I wouldn't know what though. I have also tried to edit crontab as follows:

Code: Select all

@reboot mkdir /tmp/stream && raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 && home/pi/stream.sh"
where stream.sh is a script which I have edited as follows:

Code: Select all

#!/bin/bash
LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -w /usr/local/www 
then I have given the right permission with:

Code: Select all

sudo chmod 755 /home/pi/stream
The script itself is working, indeed if I run it I can watch the video in my browser. But I won't work with crontab.

I would appreciate if someone could help me out as I am really struggling now :oops:

Many thanks in advance.

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MJPG and crontab

Sat Dec 07, 2013 11:59 am

I think you'd be better off adding a script to /etc/init.d
cp skeleton scriptname && vi scriptname
and using
update-rc.d scriptname enable
to get it running at boot time.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

harlock74
Posts: 182
Joined: Fri Jan 18, 2013 10:47 am

Re: MJPG and crontab

Sat Dec 07, 2013 12:06 pm

Hi,
Many thanks for getting back to me.
I will try what you suggested and I will let you know how it goes!
Thanks! :mrgreen:

User avatar
scruss
Posts: 3212
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: MJPG and crontab

Sat Dec 07, 2013 1:51 pm

harlock74 wrote:I have followed this guide here:

http://blog.miguelgrinberg.com/post/how ... spberry-pi
Hmm, there's a lot of specialized and assumed knowledge in that. Why it only half-installs the package, I don't know.

Code: Select all

@reboot mkdir /tmp/stream && raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 && LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -w /usr/local/www"
Basically after rebooting my RPI I can see the new folder /tmp/stream, by running top I can see the raspistill is running but not mjpg.
Well, with cron, you need to be explicit about paths. It doesn't know anything outside /bin and and /usr/bin. So you need to call mjpg_streamer as /usr/local/bin/mjpg_streamer. Also, you might be relying on /tmp being cleared out on reboots; mkdir will fail if the folder already exists, and so will the rest of your command.

Code: Select all

@reboot mkdir /tmp/stream && raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 && home/pi/stream.sh"
home/pi/stream.sh → /home/pi/stream.sh

Code: Select all

#!/bin/bash
LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -w /usr/local/www 
mjpg_streamer → /usr/local/bin/mjpg_streamer

Any scripts you run from cron inherit its limited environment. Also, is /usr/local/www writeable by this user?
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

harlock74
Posts: 182
Joined: Fri Jan 18, 2013 10:47 am

Re: MJPG and crontab

Sat Dec 07, 2013 8:19 pm

Hi DougieLawson/Scruss,

Many thanks for your kind help. I have now managed to get everything up and running :mrgreen:

Scruss,

Just out of curiosity, what did you mean by
Why it only half-installs the package, I don't know.
How can I install the full package then?

Thanks again!

User avatar
scruss
Posts: 3212
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: MJPG and crontab

Thu Dec 12, 2013 3:51 pm

One usually does a 'make' followed by a 'sudo make install', but given this package has no documentation (ಠ_ಠ) and relies on a whole bunch of other stuff to build, you're probably okay as is. I've been bitten before by installing just enough of a package to get it working. Other packages - when finding the mjpg_streamer binary in your path - might assume that everything else is also there, and fail in hilarious ways on installation.

Glad to hear you got it working.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

harlock74
Posts: 182
Joined: Fri Jan 18, 2013 10:47 am

Re: MJPG and crontab

Mon Dec 23, 2013 8:58 pm

scruss wrote:One usually does a 'make' followed by a 'sudo make install', but given this package has no documentation (ಠ_ಠ) and relies on a whole bunch of other stuff to build, you're probably okay as is. I've been bitten before by installing just enough of a package to get it working. Other packages - when finding the mjpg_streamer binary in your path - might assume that everything else is also there, and fail in hilarious ways on installation.

Glad to hear you got it working.
I see. Thank you!

Return to “Camera board”