Local RTMP Stream Server

Area for discussing streaming over the Internet, especially as it relates to ATV
Forum rules
This forum is run by the BATC (British Amateur Television Club), it is service made freely available to all interested parties, please do not abuse this privilege.

Thank you
Post Reply
gi7ugv
Posts: 38
Joined: Tue Oct 31, 2017 2:47 pm

Local RTMP Stream Server

Post by gi7ugv » Mon Jul 01, 2019 10:37 pm

I've been using a local RTMP streaming server for a while now to allow me to send video from my mobile phone camera both locally on the network to the likes of OBS and other devices and for sending video in remotely over the cellular network allowing me to walk about the garden sending video to OBS out of WiFi range. I've also got a number of subnets configured locally which complicates things a bit so I can't easily use multicast or things that only work in a local network.

My main use is using the good camera in the mobile phone to stream in to the RTMP server, and any clients like OBS/VLC/ffmpeg etc can connect to the RTMP server to obtain the video.

It's simple enough to set up an RTMP server using NGINX in Linux and it doesn't take up much in the way of resources and runs fine on a Pi while it's doing other stuff. I've been using an NGINX RTMP server on a Pi whilst it is taking the input and sending to ffmpeg and out over SDR.

The quickest way to run one in Linux would be to use Docker. With docker installed the following will download and run an image and make the RTMP service available on 127.0.0.1:1935

Code: Select all

docker run -d -p 1935:1935 --name nginx-rtmp tiangolo/nginx-rtmp
You can then configure your mobile application to stream to rtmp://<ip address>/live/<streamname> and the stream will be available to add in to OBS/VLC/ffmpeg etc with the same URL.

Image

While you could port forwarding to port 1935 from the Internet to allow you to stream in remotely, it would mean that anyone can connect to it. If you want to do this it would be better to use an alternative NGINX configuration file with some more secure options or obscure stream names.

You could do the like of this if you wanted to keep working with Docker, but it might be as easy to install it locally instead.

Code: Select all

git clone https://github.com/tiangolo/nginx-rtmp-docker.git
cd nginx-rtmp-docker/
< Edit nginx.conf to change the application from live to something obscure, or require auth or something else >
docker build -t nginx-rtmp-altered .
docker run -d -p 1935:1935 --name nginx-rtmp-altered nginx-rtmp-altered 
For the iPhone there are a lot of applications that allow you to stream video using RTMP but one of the more configurable free ones is Larix which lets you configure multiple destination sources (could point it to your BATC RTMP streamer URL) and video options, there will be plenty for Android too.

Image Image
Last edited by gi7ugv on Mon Jul 01, 2019 10:50 pm, edited 2 times in total.

gi7ugv
Posts: 38
Joined: Tue Oct 31, 2017 2:47 pm

Re: Local RTMP Stream Server

Post by gi7ugv » Mon Jul 01, 2019 10:47 pm

As mentioned you could also install NGINX with the RTMP module locally on any Linux system. It runs no bother at all on a Pi without using much CPU at all.

Code: Select all

apt-get install -y curl build-essential libpcre3-dev libpcre++-dev zlib1g-dev libcurl4-openssl-dev libssl-dev

mkdir nginx_src
cd nginx_src
git clone https://github.com/arut/nginx-rtmp-module.git
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0/
./configure --prefix=/var/www --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_ssl_module --without-http_proxy_module --add-module=../nginx-rtmp-module
make
sudo make install
If the configure fails on Raspbian with "cc1: all warnings being treated as errors", add --with-cc-opt="-Wimplicit-fallthrough=0" to the ./configure line.

Edit the /etc/nginx/nginx.conf file to remove the http section to disable the http service on port 80 and possibly alter the application name if you like to change the default URL, a very basic configuration could be:

Code: Select all

worker_processes auto;
rtmp_auto_push on;
events {}
rtmp {
    server {
        listen 1935;
        listen [::]:1935 ipv6only=on;

        application live {
            live on;
            record off;
        }
    }
}

g0mjw
Posts: 888
Joined: Sat Sep 20, 2014 9:15 am

Re: Local RTMP Stream Server

Post by g0mjw » Fri Aug 30, 2019 9:01 am

The above instructions work on the Jetson-nano.

I am now hoping to stream from OBS to the Jetson to allow it to send via a LimeSDR. This would eliminate the need for an LKV373 HDMI extender, but more usefully reduce the flood of broadcast UDP packets on my network. Even better if OBS could be coaxed into my PC doing the heavy lifting part of H265 encoding because then this would presumably work on the Portsdown too.

In order to do this on the Nano I need to modify Evariste's dvbsdr (or the Portsdown equivalent) use something like:

gst-launch-1.0 -vvv rtmpsrc location='rtmp://127.0.0.1/live/obs' !flvdemux name=demux ! \
! demux.video ! h264parse ! omxh264dec ! nvvidconv ! \
! "video/x-raw(memory:NVMM), width=(int)$VIDEO_RESX, height=(int)$VIDEO_RESY, format=(string)I420" \
! omxh265enc vbv-size=15 control-rate=4 bitrate=$VIDEOBITRATE peak-bitrate=$VIDEOPEAKBITRATE preset-level=3 iframeinterval=$VIDEO_GOP \
! "video/x-h265, level=(string)main3.1, stream-format=(string)byte-stream" ! queue \
! demux.audio ! audioconvert ! voaacenc bitrate=$AUDIO_BITRATE \
! queue ! mux. mpegtsmux alignment=7 name=mux !queue max-size-time=10000000000 max-size-bytes=0 max-size-buffers=0 ! fdsink \
| ffmpeg -i - -ss 8 -c:v copy -max_delay $PCR_PTS -muxrate $BITRATE_TS -c:a copy -f mpegts -pat_period 0.2 -metadata service_provider="QO-100" -metadata service_name=$CALL -streamid 0:256 $ffmpegoutput

Is this correct? No! I can see my rtmp stream in OBS but can't pipe it into dvbsdr

Mike

gi7ugv
Posts: 38
Joined: Tue Oct 31, 2017 2:47 pm

Re: Local RTMP Stream Server

Post by gi7ugv » Sun Sep 01, 2019 4:59 pm

For transmitting on the PC and the Pi I'm using ffmpeg for the transcoding and just taking the input as: ffmpeg -i rtmp://127.0.0.1/live/obs

Here's a full command:

ffmpeg -i rtmp://127.0.0.1/live/obs -c:v libx264 -x264-params "nal-hrd=cbr:force-cfr=1:keyint=500" -preset slow -pix_fmt yuv420p -r 25 -s 640x360 -qmin 2 -qmax 50 -g 50 -b:v 289229 -minrate 289229 -maxrate 289229 -bufsize 115691 -muxrate 429037 -c:a aac -b:a 24000 -ar 48000 -ac 1 -f mpegts -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 -mpegts_service_id 1 -mpegts_pmt_start_pid 4096 -streamid 0:256 -metadata service_provider="DATV" -metadata service_name=GI7UGV -flush_packets 0 -f mpegts -async 1 -vsync 1 - | /home/r/radio/video/dvbsdr/bin/limesdr_dvb -s 333000 -f 2/3 -r 2 -m DVBS2 -c QPSK -v -t 2409.25e6 -g 0.79 -q 1

I'd assume gstreamer would take RTMP input fine, think you said the RTMP server bit's fine? You can also view it in VLC. I'll have a look at it with gstreamer.

g0mjw
Posts: 888
Joined: Sat Sep 20, 2014 9:15 am

Re: Local RTMP Stream Server

Post by g0mjw » Sun Sep 01, 2019 5:37 pm

Well almost - but this is not using the hardware encoder. In Evariste's script it is something like:

ffmpeg -i rtmp://127.0.0.1/live/obs -c:v libx264 -x264-params "nal-hrd=cbr:force-cfr=1:keyint=500" -preset slow -pix_fmt yuv420p -r 25 -vf scale=$VIDEO_RESX:$VIDEO_RESY -qmin 2 -qmax 50 -g 50 -b:v $VIDEOBITRATE -minrate $VIDEOBITRATE -maxrate $VIDEOPEAKBITRATE -bufsize 115691 -muxrate $BITRATE_TS -c:a aac -b:a $AUDIO_BITRATE -ar 48000 -ac 1 -f mpegts -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 -mpegts_service_id 1 -mpegts_pmt_start_pid 4096 -streamid 0:256 -metadata service_provider="QO-100" -metadata service_name=$CALL -flush_packets 0 -f mpegts -async 1 -vsync 1 $ffmpegoutput

g0mjw
Posts: 888
Joined: Sat Sep 20, 2014 9:15 am

Re: Local RTMP Stream Server

Post by g0mjw » Sun Sep 01, 2019 6:11 pm

I got this working - in H264 only but its flakey. However, this is using the CPU for coding and pretty much maxes it out. H265 doesn't work at all.

I can't understand why Gstreamer won't work but it fails to capture the stream, or perhaps something else is wrong. What would be better would be to do the low rate encoding on the PC and just have the Nano or PI send it. Then I could use my fast graphics card to do the encoding.

Mike

Edit - this works, sometimes. but has the same problem with ffmpeg not capturing the stream as the pi camera at low frame rates - I am beginning to think ffmpeg is the problem as the symptom is always underflow.

gst-launch-1.0 -v rtmpsrc location=rtmp://127.0.0.1/live/obs ! flvdemux name=demux \
demux.audio ! queue ! decodebin ! audioconvert ! voaacenc bitrate=$AUDIO_BITRATE ! mux. \
demux.video ! queue ! decodebin ! videoconvert ! video/x-raw,format=I420 ! \
omxh265enc vbv-size=15 control-rate=4 bitrate=$VIDEOBITRATE peak-bitrate=$VIDEOPEAKBITRATE preset-level=3 iframeinterval=$VIDEO_GOP ! "video/x-h265, stream-format=(string)byte-stream" ! \
mux. mpegtsmux alignment=7 name=mux ! \
fdsink | ffmpeg -i - -ss 8 -c:v copy -max_delay $PCR_PTS -muxrate $BITRATE_TS -c:a copy -f mpegts -pat_period 0.2 -metadata service_provider="QO-100" -metadata service_name=$CALL -streamid 0:256 -flush_packets 0 -async 1 -vsync 1 $ffmpegoutput

Post Reply

Return to “Streaming”