Valiceemo
Posts: 33
Joined: Wed Apr 19, 2017 1:47 pm

starting live stream at boot

Thu Oct 05, 2017 1:10 pm

Im currently using the following commend to start a live stream from my Pi Camera, connected to a Pi 3:

Code: Select all

sudo raspivid -o - -t 0 -w 640 -h 360 -n -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard access=http,mux=ts,dst=:8090}' :demux=h264
What is the best way to have this run at boot?
creating a service via systemd?

User avatar
RaTTuS
Posts: 10108
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: starting live stream at boot

Thu Oct 05, 2017 1:26 pm

yes to systemd service [learn it it will be useful],
why do you use sudo
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Valiceemo
Posts: 33
Joined: Wed Apr 19, 2017 1:47 pm

Re: starting live stream at boot

Fri Oct 06, 2017 12:52 pm

So, I have had a play and have not been successful.

I created a picamerastream.service file:

Code: Select all

[Service]
Type=idle
ExecStart=/bin/sh -c 'sudo raspivid -o - -t 0 -w 1280 -h 720 -n -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264' >  /home/pi/logs/picamera-stream.log 2>&1

[Install]
WantedBy=multi-user.target
The service appears to start but fail?

Code: Select all

[email protected]:~/logs $ sudo systemctl status picamerastream.service
  ● picamerastream.service - Pi Camera Streamer
   Loaded: loaded (/lib/systemd/system/picamerastream.service; enabled)
   Active: active (running) since Thu 2017-10-05 21:01:54 BST; 1min 12s ago
 Main PID: 31656 (sh)
   CGroup: /system.slice/picamerastream.service
           ├─31656 /bin/sh -c sudo raspivid -o - -t 0 -w 1280 -h 720 -n -fps 25|cvlc -vvv stream:///dev/stdin --sout  
#standard{access=http,mux=ts,dst=:8090}' :demux...
       ├─31657 sudo raspivid -o - -t 0 -w 1280 -h 720 -n -fps 25
       └─31662 raspivid -o - -t 0 -w 1280 -h 720 -n -fps 25

Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13784)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 20360)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13589)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13339)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13571)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13569)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13447)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13814)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13725)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13804)- aborting
I also tried creating a script that is called from the service unit file:

Code: Select all

#!/bin/sh

Sudo raspivid -o - -t 0 -w 640 -h 360 -n -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264
And the unit file:

Code: Select all

[Unit]
Description=Pi Camera Streamer
After=multi-user.target

[Service]
Type=idle
ExecStart=/bin/bash -c '/home/pi/scripts/system/picamera.sh'

[Install]
WantedBy=multi-user.target
No mater how I run it, I get some form of error.

I think it might be the actual code to start the stream? Perhaps it needs tidying up?

Code: Select all

'sudo raspivid -o - -t 0 -w 1280 -h 720 -n -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264' 

User avatar
RaTTuS
Posts: 10108
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: starting live stream at boot

Fri Oct 06, 2017 1:58 pm

remove the sudo , why are you using sudo , don't use sudo
pipes and sudo are not what you expect
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Valiceemo
Posts: 33
Joined: Wed Apr 19, 2017 1:47 pm

Re: starting live stream at boot

Fri Oct 06, 2017 2:03 pm

RaTTuS wrote:
Fri Oct 06, 2017 1:58 pm
remove the sudo , why are you using sudo , don't use sudo
pipes and sudo are not what you expect
so my unit file should like this:

Code: Select all

[Service]
Type=idle
ExecStart=/bin/sh -c 'raspivid -o - -t 0 -w 1280 -h 720 -n -fps 25 | cvlc -vvv stream:///dev/stdin --sout '#standard access=http,mux=ts,dst=:8090}' :demux=h264' >  /home/pi/logs/picamera-stream.log 2>&1
EDIT:
Removed sudo from the unit file and I still get the same error.
I think it may be a problem with the way the ExecStart is defined, as the output of

Code: Select all

sudo systemctl status picamerastream.service
seems to show that it is only running part of that one-liner?

kevinob
Posts: 1
Joined: Tue Apr 10, 2018 12:14 pm

Re: starting live stream at boot

Tue Apr 10, 2018 12:23 pm

Did you fix this problem? i am currently facing the exact same problem as you and the exact same error.
I am able to run my .sh file (which includes the raspivid vlc command) as a working executable, then the stream starts and works.
But from boot i get this buffer error

lwhistler
Posts: 16
Joined: Sat Jul 16, 2016 10:37 pm

Re: starting live stream at boot

Mon Apr 23, 2018 8:26 pm

crontab -e

Code: Select all

@reboot /home/pi/Desktop/your_script.sh

xinsnake
Posts: 1
Joined: Sun May 13, 2018 2:10 pm

Re: starting live stream at boot

Sun May 13, 2018 2:14 pm

Here is what I did to get it working...

Code: Select all

[email protected]:~# cat /etc/systemd/system/camera.service 
[Unit]
Description=Raspberry Pi Cam Stream
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/bin/camera-stream.sh
User=pi
Restart=on-failure

[Install]
WantedBy=multi-user.target

Code: Select all

[email protected]:~# cat /usr/bin/camera-stream.sh 
#!/bin/bash

/usr/bin/raspivid -t 0 -fps 25 -w 1280 -h 720 -o - | \
    /usr/bin/cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264

johnnyJE
Posts: 21
Joined: Sat Sep 10, 2016 5:09 pm
Location: NYC

Re: starting live stream at boot

Sun Aug 12, 2018 11:30 pm

Valiceemo wrote:
Fri Oct 06, 2017 12:52 pm
So, I have had a play and have not been successful.
...

The service appears to start but fail?

Code: Select all

[email protected]:~/logs $ sudo systemctl status picamerastream.service
...

Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13784)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 20360)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13589)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13339)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13571)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13569)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13447)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13814)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13725)- aborting
Oct 05 21:03:06 media-pi sh[31656]: mmal: Failed to write buffer data (4096 from 13804)- aborting
I am having the same error

Code: Select all

hostname raspivid[440]: mmal: Failed to write buffer data (4096 from 19438)- aborting
here is my unit file

Code: Select all

# /etc/systemd/system/camstream.service
[Unit]
Description=raspivid tcp server
After=network.target

[Service]
Type=simple
User=pi
ExecStart=/usr/bin/raspivid -n -pf high -w 1280 -h 720 -l -o tcp://0.0.0.0:3333 -fps 24 -t 0
#PIDFile=/var/run/raspivid.pid
#ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
Edit: I did not think this would be an issue, but setting the -t flag down to a real number that's not zero made the bug go away. Here's where the error may be coming form for any engineers: https://github.com/raspberrypi/userland ... id.c#L1490

Return to “Camera board”