Page 1 of 1

MJPG and crontab

Posted: Sat Dec 07, 2013 11:48 am
by harlock74
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.

Re: MJPG and crontab

Posted: Sat Dec 07, 2013 11:59 am
by DougieLawson
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.

Re: MJPG and crontab

Posted: Sat Dec 07, 2013 12:06 pm
by harlock74
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:

Re: MJPG and crontab

Posted: Sat Dec 07, 2013 1:51 pm
by scruss
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?

Re: MJPG and crontab

Posted: Sat Dec 07, 2013 8:19 pm
by harlock74
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!

Re: MJPG and crontab

Posted: Thu Dec 12, 2013 3:51 pm
by scruss
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.

Re: MJPG and crontab

Posted: Mon Dec 23, 2013 8:58 pm
by harlock74
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!