gazlee
Posts: 8
Joined: Mon Feb 11, 2013 12:39 pm
Location: England

RTMP stream at boot

Mon Feb 11, 2013 1:02 pm

Hi everyone, I'm tinkering with a Pi at the moment to use as a receiver for an internal RTMP stream at the college where I work.
Basically, I'm trying to get it to boot up and automatically start playing the stream continuously.

I've got it working to an extent by creating an init script to launch omxplayer with the right options, but I'm not sure wether it's holding up the boot process, because I've noticed that after a while (not sure how long exactly) the stream stops playing and the login prompt is displayed just as if it'd finished booting up.

Here's what my (very basic) init script consists of so far:

Code: Select all

#! /bin/sh
# /etc/init.d/streamonboot
#

echo "****** Starting stream ******"
omxplayer -o hdmi rtmp://path/to/stream
On the backend I'm using nginx-rtmp on an Ubuntu server to serve the stream, the stream is h.264/AAC encoded from Flash Media Live Encoder.

Any help with this would be much appreciated,
Thanks in advance,
Gary

ghans
Posts: 7893
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: RTMP stream at boot

Mon Feb 11, 2013 9:03 pm

I'd configure the Pi for for a auto-login , and then use rc.local
to start omxplayer.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

gazlee
Posts: 8
Joined: Mon Feb 11, 2013 12:39 pm
Location: England

Re: RTMP stream at boot

Wed Feb 13, 2013 4:05 pm

Hi ghans, thanks for getting back to me so quickly, I've had a look and set it up as you suggested. I'll leave it running for a while and report back if its more stable this way.

Thanks again,
Gary

notreemedia
Posts: 2
Joined: Sun Feb 17, 2013 2:06 am

Re: RTMP stream at boot

Sun Feb 17, 2013 2:11 am

Hi Gary,

I've set up a similar thing. How stable have you found it? I have found the audio goes out of sync after a few hours and restarting the stream encoder side fixes it.

Cheers

gazlee
Posts: 8
Joined: Mon Feb 11, 2013 12:39 pm
Location: England

Re: RTMP stream at boot

Wed Feb 20, 2013 12:02 pm

Hi notreemedia, I've found it to be much more stable this way, admittedly I'm testing it at the moment with an external professionally encoded RTMP stream (Capital TV) but it's been going for about 3 days and all seems well.

The one thing I have had to do is enclose the omxplayer command in a while loop to make it automatically reconnect if the stream drops out (which seems every so often). There might be a better way of doing this, but this works for me. I put a bit of very basic logging in there too to see when the stream dropped.

Code: Select all

#!/bin/bash

while :
do

echo "------------------------------------------------"
echo ""
echo "Attempting to start Live video stream"
echo ""
echo "------------------------------------------------"

date=`date`

echo "starting on "$date"" >> screen.log

omxplayer -o hdmi rtmp://path/to/stream

echo "EXITED on ".$date."" >> screen.log

done
As far as audio drifting goes, I'm curious as to what your setup is for RTMP back end (encoder, server etc), I'm yet to find a solution that's perfect for me, NGINX RTMP seems pretty stable but the stream drops out every so often and I can't work out wether it's the encoder I'm using or the server it's self. I did notice some issues with using the MP3 audio codec on my setup, but using AAC seems fine.

Cheers,
Gary

notreemedia
Posts: 2
Joined: Sun Feb 17, 2013 2:06 am

Re: RTMP stream at boot

Wed Feb 20, 2013 1:03 pm

Hi Gary,

Cheers for all that, useful.

I'm using Wowza Media Server and Wirecast as the encoder. I'm sending a H264 1280x720 3Mb/s 25fps Main profile video with AAC audio.

I've actually done something similar with omxplayer and have a script looping to check if the omxplayer process is running and if not to reopen it. How does your script check if the player is running?

I also have an application called Gwenview (an image viewer you can install) open showing a holding image saying "Stream Offline" so when the Omxplayer stops streaming it shows this which is handy. There will be better ways of doing this but thought i would mention it anyway!

Thanks

gazlee
Posts: 8
Joined: Mon Feb 11, 2013 12:39 pm
Location: England

Re: RTMP stream at boot

Wed Feb 20, 2013 7:11 pm

The script doesn't actually check the status of omxplayer, it starts it initially and then just re-starts it if it exits, so really it's not entirely foolproof, but as I say, it works ok for me.

Regarding the encoding side, I've had better luck with the Baseline h.264 profile rather than Main, I'm not sure what levels the GPU supports, but my test setup was encoded with Flash Media Live Encoder using a Baseline h.264 (level 3.1) profile, 1280x720, 25fps at 2.5Mb/s. Seeing as you're running Wowza, have you tried using the Pi with an HLS stream?
I've just been trying mine with a 1.5Mb/s HLS stream of TWiT at 1280x720 and it plays back really nicely -

Code: Select all

http://hls.twit.tv:1935/flosoft/_definst_/mp4:twitStreamHi_1628/playlist.m3u8

Thanks for the tip about Gwenview, I'll have a look at trying to integrate that into my setup!

tofuprod
Posts: 4
Joined: Wed Feb 20, 2013 6:26 pm

Re: RTMP stream at boot

Tue Feb 26, 2013 7:30 pm

Is there a tutorial on how to setup one? :D

gazlee
Posts: 8
Joined: Mon Feb 11, 2013 12:39 pm
Location: England

Re: RTMP stream at boot

Tue Feb 26, 2013 7:57 pm

Hey, tofuprod!
Do you mean a tutorial for setting up the Pi to automatically play a stream/video at boot?
There might be one around, but if you just add that script I posted earlier in the thread to your rc.local file as ghans suggests, you'll be good to go. If you're using the standard Raspbian I believe you'll already have omxplayer installed.

Gary

tofuprod
Posts: 4
Joined: Wed Feb 20, 2013 6:26 pm

Re: RTMP stream at boot

Tue Feb 26, 2013 8:13 pm

Oh! I'm sorry, I meant setting a media server and using the Pi as the viewer. How do I pull a live stream (rtmp)? For example, I'm using Adobe Media Server and the address would be [rtmp://12.34.56.78/live], would I just then input this code?

Code: Select all

omxplayer -o hdmi rtmp://12.34.56.78/live
I am wondering how I can pull live streaming signal from my media server.

Thank you! :)

gazlee
Posts: 8
Joined: Mon Feb 11, 2013 12:39 pm
Location: England

Re: RTMP stream at boot

Tue Feb 26, 2013 8:32 pm

Oh I see! Yes, that command should work absolutely fine, normally your RTMP URL from Adobe Media Server would be a bit longer than that though, with a stream name on the end, for example:

Code: Select all

omxplayer -o hdmi rtmp://12.34.56.78/live/gary_tv
Hope that helps.

tofuprod
Posts: 4
Joined: Wed Feb 20, 2013 6:26 pm

Re: RTMP stream at boot

Tue Feb 26, 2013 9:27 pm

Gary,

That helps! Thank you!

Cheers,
Jun

omega1
Posts: 114
Joined: Mon Jul 02, 2012 3:10 pm
Location: UK

Re: RTMP stream at boot

Wed Mar 13, 2013 10:54 am

ghans wrote:I'd configure the Pi for for a auto-login , and then use rc.local
to start omxplayer.

ghans
Hi all,

I am attempting to do something very similar to the original post, but with audio only (AAC+).

ghans, could you please explain in a little more detail how to do these two things you've described? My apologies for the little knowledge of Linux!

Thanks in advance!

ghans
Posts: 7893
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: RTMP stream at boot

Sat Mar 16, 2013 3:53 pm

http://elinux.org/RPi_Debian_Auto_Login

For the rest , research on "init scripts" .


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

ALex_hha
Posts: 3
Joined: Fri Jan 10, 2014 2:33 pm

Re: RTMP stream at boot

Fri Jan 10, 2014 2:38 pm

Hello,

Could anyone suggest why I can't play stream directly from server (erlyvideo)

Code: Select all

$ omxplayer rtmp://192.168.210.102:1935/live/Test --live -o hdmi
Video codec omx-h264 width 432 height 240 profile 77 fps 15.000000
have a nice day ;)
But if I use rtmpdump all works fine

Code: Select all

$ rtmpdump -r rtmp://192.168.210.102:1935/live/Test --live -o /tmp/livevideo | omxplayer /tmp/livevideo -o hdmi
Stream info are the following

Code: Select all

$ omxplayer -i rtmp://192.168.210.102:1935/live/Test
[flv @ 0x20d2a10] Stream discovered after head already parsed
[flv @ 0x20d2a10] Could not find codec parameters for stream 1 (Audio: none, 0 channels): unspecified sample format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, flv, from 'rtmp://192.168.210.102:1935/live/Test':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(tv), 432x240 [SAR 1:1 DAR 9:5], 15 tbr, 1k tbn, 50 tbc
    Stream #0:1: Audio: none, 0 channels
    Stream #0:2: Data: none
have a nice day ;)
Thanks in advance

gazlee
Posts: 8
Joined: Mon Feb 11, 2013 12:39 pm
Location: England

Re: RTMP stream at boot

Fri Jan 10, 2014 7:40 pm

Hi ALex_hha,

Just having a look at what you've posted and the only things I can spot are the "--live" option you've specified on omxplayer, which I don't think is needed, and the fact the info output reports that the stream has no audio but you're specifying an audio output device with the "-o hdmi" option, it might be worth having another go with those couple of things changed and see what happens.

Thanks,
Gary

ALex_hha
Posts: 3
Joined: Fri Jan 10, 2014 2:33 pm

Re: RTMP stream at boot

Sat Jan 11, 2014 10:41 am

I will try and let you know if it's help

ALex_hha
Posts: 3
Joined: Fri Jan 10, 2014 2:33 pm

Re: RTMP stream at boot

Mon Jan 13, 2014 2:24 pm

Doesn't work

Code: Select all

$ omxplayer -o hdmi rtmp://192.168.210.102:1935/live/Test
Video codec omx-h264 width 432 height 240 profile 77 fps 15.000000
have a nice day ;)

User avatar
ekla
Posts: 47
Joined: Wed Apr 09, 2014 9:39 am
Location: Lyon, France

Re: RTMP stream at boot

Mon Nov 10, 2014 10:41 am

just try first :

omxplayer -o hdmi rtmp://12.34.56.78/live/gary_tv --live

after that you can try

while true; do tvservice -c & omxplayer -o hdmi rtmp://12.34.56.78/live/gary_tv --live ; sleep 1 ; done


put this in RC.LOCAL if you want to start it automaticaly at starting,

cheers
our fears are like dragons guarding our most precious treasures

daHawaiian
Posts: 2
Joined: Mon Jan 26, 2015 9:43 am

Re: RTMP stream at boot

Mon Jan 26, 2015 10:06 am

Hey everyone,

tl;dr
----
When I play an RTMP stream the first time via "omxplayer rtmp://127.0.0.1:1935/live/live", everything works. But when I stop streaming to my RTMP server and then try restreaming, "omxplayer rtmp://127.0.0.1:1935/live/live" doesn't work. It appears to be doing somethign in the background, but I can't get a video to show. However if I do "omxplayer some.mp4" I get a video playing.
----

I've managed to get the stream to play automatically after someone starts streaming via nginx-rtmp exec_push. The problem I'm having seems to be with omxplayer. After I stop the stream, omxplayer exits and my nginx script terminates, but when I try to open a new stream, I can't get the video to show up on the monitor. I presume something is hapening in the background... but I get no video. I can't verify if I get audio atm. Even if I kill all the omx processes, remove temporary files, and then open an rtmp stream I get nothing. But opening a .mp4 video works.

I'm guessing there might be a bug with omxplayer so I'm seeing if anyone else has the same problem. :(

Here are my versions
omxplayer -Version : 39e6342
nginx version 1.7.7
Here's the code I'm using,

Code: Select all

sudo kill $(ps -A | grep 'omxplayer' | awk '{print $1}')
sudo rm /tmp/omxplayer*
sleep 2
tvservice -e "CEA 20 HDMI" 
sleep 2
sudo chvt 2
sleep 2
sudo chvt 1
sleep 2
omxplayer rtmp://127.0.0.1:1935/live/live
sleep 2
sudo kill $(ps -A | grep 'omxplayer' | awk '{print $1}')
sudo rm /tmp/omxplayer*
sleep 2
tvservice -o
And my relevant config.txt bits,

Code: Select all

hdmi_ignore_edid=0xa5000080
hdmi_ignore_cec_init=1
hdmi_ignore_cec=1
hdmi_force_hotplug=1
hdmi_group=1
hdmi_mode=20

daHawaiian
Posts: 2
Joined: Mon Jan 26, 2015 9:43 am

Re: RTMP stream at boot

Mon Jan 26, 2015 10:49 am

Well I did up full upgrade of packages (including omxplayer) and firmware and distro and everythign seems to work. Apologies! I had just did a full update a few days before but I mised the distro upgrade!

It's working great. I love it!

Arkon
Posts: 2
Joined: Fri Jun 12, 2015 10:16 pm

Re: RTMP stream at boot

Fri Jun 12, 2015 10:23 pm

If you strugle with omxplayer not starting after the stream started on your pc make sure, that you uncommented the first line in nginx.conf like mentioned in step 2. Take a close look and you will notice it's not just changing the user. You have to delete the #

In addition I addet the full path to omxplayer in the server config. It's now:

Code: Select all

exec_push /usr/bin/omxplayer --live rtmp://localhost:1935/live/stream;
With these two changes the player starts when it receives the stream.

mrmikesalmon
Posts: 10
Joined: Wed Mar 30, 2016 8:54 pm

Re: RTMP stream at boot

Wed Mar 30, 2016 8:57 pm

This I think is exactly what I'm looking to do. I need to stream from OBS to a pi and then over a network. So this set-up seems ideal for what I'm looking to do. Is there a fuller how to, or a chance of getting a copy of the set up as a .zip?

The stream needs to go to phones and tablets. Mostly captions and audio.

Thanks.

clundie_til
Posts: 1
Joined: Sat Jan 28, 2017 4:23 am

Re: RTMP stream at boot

Sat Jan 28, 2017 4:50 am

I am dropping this code at the end of rc.local and it is generating an error https://goo.gl/photos/5fhsX4G3RcL68uNSA

When I run it in terminal I have no issue and it works great am I doing something wrong I am new to this and really excited about getting this working - any help is appeciated

gazlee wrote:Hi notreemedia, I've found it to be much more stable this way, admittedly I'm testing it at the moment with an external professionally encoded RTMP stream (Capital TV) but it's been going for about 3 days and all seems well.

The one thing I have had to do is enclose the omxplayer command in a while loop to make it automatically reconnect if the stream drops out (which seems every so often). There might be a better way of doing this, but this works for me. I put a bit of very basic logging in there too to see when the stream dropped.

Code: Select all

#!/bin/bash

while :
do

echo "------------------------------------------------"
echo ""
echo "Attempting to start Live video stream"
echo ""
echo "------------------------------------------------"

date=`date`

echo "starting on "$date"" >> screen.log

omxplayer -o hdmi rtmp://path/to/stream

echo "EXITED on ".$date."" >> screen.log

done
As far as audio drifting goes, I'm curious as to what your setup is for RTMP back end (encoder, server etc), I'm yet to find a solution that's perfect for me, NGINX RTMP seems pretty stable but the stream drops out every so often and I can't work out wether it's the encoder I'm using or the server it's self. I did notice some issues with using the MP3 audio codec on my setup, but using AAC seems fine.

Cheers,
Gary

LeGreatMaxiking
Posts: 1
Joined: Fri Feb 10, 2017 6:40 am

Re: RTMP stream at boot

Fri Feb 10, 2017 6:45 am

Hi!
I want to use the raspberry as a streaming device to show a video stream directly on our Television system in our building. So at the moment there is just a old i3 Notebook which uses OBS and the preview function to show it via HDMI on the TVs / It converts the hdmi signal to cable-TV signal!

Now I want to find a good solution for that, because the Input for the signal is under the roof and not easy reachable...

Would It possible to put up a raspberry there and stream from local network to the device ? Would it also be possible to show a .jpg or something a .mp4 while the stream isn´t running?

Thanks in advance

Max

Return to “Beginners”