alband
Posts: 16
Joined: Mon Jul 29, 2013 4:59 pm

VLC Camera Streaming with cron job

Wed Jan 15, 2014 1:50 pm

Hi,

TL,DR: I cannot get VLC to run from a cron job in any way. If someone else can, could they tell me how so I can try please! :)

I'm quite new to Linux + Pi so having worn out hits on Google, I'm stuck for what to do.
I'm trying to get my Pi to run a bash script at boot using a cron job. The script starts raspivid, then streams it with VLC:
"Start_Stream.sh"

Code: Select all

#!/bin/bash

/usr/bin/raspivid -o - -t 0 -fps 25 -w 1280 -h 720 -g 5 -b 10000000 -awb off | /usr/bin/cvlc stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

 echo "test" > /home/pi/test.txt
If I run it from CLI via SSH, it works fine and I can pick up the camera stream no trouble on my laptop.

However, I CANNOT get it, or anything involving VLC to run via a cron job. Just running that script via a cron job results in test.txt being created but no evidence of raspivid or vlc being run (ps axg...). If I take off the second part of the main function, so I just have the raspivid bit, it works as a cron job.
...So this works:

Code: Select all

#!/bin/bash

/usr/bin/raspivid -o - -t 0 -fps 25 -w 1280 -h 720 -g 5 -b 10000000 -awb off

 echo "test" > /home/pi/test.txt
So I reckoned the problem is either the "piping" (I believe it's called piping when you use a "|" like that? Like I said, I'm a bit new). Or it's the VLC command itself.
So I tried removing the pipe thing as follows. This runs the raspivid bit, but not the VLC bit:

Code: Select all

#!/bin/bash

/usr/bin/raspivid -o - -t 0 -fps 25 -w 1280 -h 720 -g 5 -b 10000000 -awb off
/usr/bin/cvlc stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

 echo "test" > /home/pi/test.txt
So I reckoned it must be VLC. So I've been spending ages just trying to get SOME evidence of VLC running from a cron job.
I've tried the method detailed here, using my own .flv file: http://michaelchrisco.com/wiki/index.ph ... a_cron_job but that still refuses to run. I'm checking using ps axg and with all these tests, I just scheduling with crontab -e so they run at that point, not on reboot, for example:

Code: Select all

33 13 * * * bash /home/pi/Start_Stream4.sh
I've tried putting "Screen" method into a bash script like this:

Code: Select all

#!/bin/bash

/usr/bin/screen -d -m /usr/bin/vlc-wrapper /home/pi/bluetit.flv --novideo --volume 700 --repeat --rc-fake-tty

 echo "test" > /home/pi/test.txt
The file "test.txt" is produced, but vlc isn't running. If I run the same bash script via the CLI, it works just fine and VLC is left running.

I've also tried creating VLC bash scripts that should convert a file and save it as a new file. If the file is there VLC has run. Again, these run through the CLI, but not through a cron job.

I'm completely stuck for what to do and am clueless as to why it wouldn't work. As you can imagine, I've tried various permutations of the above tests but not once has VLC run from a cron job.

Thanks in advance for any suggestions or advice. I suppose what would be really useful is if someone could get VLC running from a cron job, then I can try to replicate to find the problem.
Thanks,
David.

Edit: I'm using "2013-09-25-wheezy-raspbian"

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: VLC Camera Streaming with cron job

Thu Jan 16, 2014 9:23 am

There is no guaranteed graphical environment or TTY when the cron job is executed.
After a quick Google (running vlc in cron) using vlc with "-I http" is required. You could see if this is indeed the case.
There are numerous other thoughts on the subject like setting a DISPLAY but the outcome is rarely clear.

alband
Posts: 16
Joined: Mon Jul 29, 2013 4:59 pm

Re: VLC Camera Streaming with cron job

Thu Jan 16, 2014 12:51 pm

Well, feeling quite stupid now. It's because cron was running it as root. I'd read that before, but decided it couldn't be it because examples on the internet didn't seem to need to be accounting for that, like the one I linked to. ...Except that one was. It used "crontab -e", I was using "sudo crontab -e". I tried everything with just "crontab -e" and it all works. Even the first commands I had, without "-I http" or "DISPLAY" or "screen" stuff.

So now I'm just using the original script I had in the OP. Is there a disadvantage to using cron as a normal user not root? I feel like there must be give how simple-er solution it seems to be. (Also feel slightly peeved I > 5 hours yesterday fighting this, when the solution was so simple).

Also, should I still add the "-I http"? It worked without it, but should I still use it?

Anyway, thanks. Hope this'll help someone else who is trying to run VLC from cron headless (in more that one sense ;) )

Return to “Troubleshooting”