how to reduce latency ngix rtmp server? - rtmp

I would like to create a rtmp server with minimal latency.
I'm using nginx with ngix with the following configuration file
rtmp {
server {
listen 1935;
ping 30s;
# chunk_size 4096;
# chunk_size 8192;
buflen 100ms;
publish_time_fix off;
application vod {
play /usr/local/nginx/rtmp;
}
application live {
live on;
record off;
exec ffmpeg -i rtmp://localhost/live/drone -threads 1 -c:v libx264 -profile:v baseline -preset:v faster -tune zerolatency -an -b:v 300K -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/live360p/drone;
}
application live360p {
live on;
record off;
}
}
}
In Playback I'm using
ffplay -fflags nobuffer rtmp://127.0.0.1/live/drone -loglevel verbose
I'm not sticking with anything except Linux and the video source that is streaming rtmp. So, replace ngix, decrease quality, change playback format are all fine. The most important thing is to reduce latency?
Best Regards

Related

Rabbitmq mqtt broker uses a lot of memory

I am evaluating rabbitmq as mqtt broker and currently doing benchmark tests to check performance. Using benchmark tool https://github.com/takanorig/mqtt-bench I tried publishing 1 byte messages for 10000 clients. The memory consumption by rabbitmq for these numbers is 2gb and it's the same for 10000 subscriptions as well. Here are the consumption details provided by rabbitmq-diagnostics memory_breakdown
connection_other: 1.1373 gb (55.89%)
other_proc: 0.3519 gb (17.29%)
allocated_unused: 0.1351 gb (6.64%)
other_system: 0.0706 gb (3.47%)
quorum_ets: 0.0675 gb (3.32%)
plugins: 0.0555 gb (2.73%)
binary: 0.0482 gb (2.37%)
mgmt_db: 0.035 gb (1.72%)
This means that the broker server is taking 200KB per connection, which seems to me a big number, considering that we need to scale our system to 1million connections in future and then we would need to provide around 200gb for just rabbitmq.
I have tried playing with some settings in my conf file and docker command
mqtt.allow_anonymous=false
ssl_options.cacertfile=/certs/ca_certificate.pem
ssl_options.certfile=/certs/server_certificate.pem
ssl_options.keyfile=/certs/server_key.pem
ssl_options.verify=verify_peer
ssl_options.fail_if_no_peer_cert=false
mqtt.listeners.ssl.default=8883
mqtt.listeners.tcp.default=1883
web_mqtt.ws_path = /mqtt
web_mqtt.tcp.port = 15675
collect_statistics_interval = 240000
management.rates_mode = none
mqtt.tcp_listen_options.sndbuf = 1000
mqtt.tcp_listen_options.recbuf = 2000
mqtt.tcp_listen_options.buffer = 1500
Below is the docker command where I've tried to reduce tcp_rmem and tcp_wmem size as well
docker run -d --rm -p 8883:8883 -p 1883:1883 -p 15675:15675 -p 15672:15672 -v /home/ubuntu/certs:/certs --sysctl net.core.somaxconn=32768 --sysctl net.ipv4.tcp_max_syn_backlog=4096 --sysctl net.ipv4.tcp_rmem='1024 4096 500000' --sysctl net.ipv4.tcp_wmem='1024 4096 500000' -e RABBITMQ_VM_MEMORY_HIGH_WATERMARK=0.9 -e RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="+P 2000000" -t probusdev/hes-rabbitmq:latest
Are there any other settings I can try to reduce the memory consumption?
Update: I used the same benchmark test against Emq broker and it took only 400mb for the same numbers. So is Rabbitmq mqtt more memory consuming then Emq?

Apprtc with coturn STUN/TURN server

Simply, I am going run locally popular example of WEBRTC app:
github.com/webrtc/apprtc
The apprtc installed, and even works locally without turn server ( "Same origin policy" don't allow use Google TURN server, which works only from apprtc.appspot.com: access-control-allow-origin:"https://apprtc.appspot.com").
But I know that in real internet world (nats and firewalls) I need turn server. So I have decided to use own STUN/TURN server:
code.google.com/p/coturn/
I am trying integrate my apprtc with coturn:
+apprtc: http://localhost:8080/?wstls=false
+coturn: http://localhost: 3478
and I have questions:
a) Do I need execute some turnadmin commands, which are described in INSTALL guide?
Or it will be enaugh to run turnserver from example:
my_name#my_machine:~/WEBRTC/turnserver-4.4.5.2/examples/scripts/restapi$ ./secure_relay_secret.sh
which contains:
if [ -d examples ] ; then
cd examples
fi
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/
PATH="./bin/:../bin/:../../bin/:${PATH}" turnserver -v --syslog -a -L 127.0.0.1 -L ::1 -E 127.0.0.1 -E ::1 --max-bps=3000000 -f -m 3 --min-port=32355 --max-port=65535 --use-auth-secret --static-auth-secret=logen --realm=north.gov --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout -q 100 -Q 300 --cipher-list=ALL $#
b) When I open localhost: 3478 in browser I see:
"TURN Server
use https connection for the admin session:
What uri is for rest API?
c) In rest API I need pass some parameters: username and key. Is it enough?
Will be enough to simply add extra -u switch to turnserver command? Need I some extra configurations?
e) How solve "Same origin policy"? I am not going experiment with the same ports and nginx, but simply set "access-control-allow-origin" header to turnserver response. How do it without nginx proxy? Or maby some others solutions?
d) Are some other important issues, which person running apprtc app and coturn server should know?
edit
For me the most problem was thinking that Coturn has own api method which return TURN servers - but has not. So it is requird to do it myself - on own http server. Below is example in python/django:
from hashlib import sha1
import hmac
TURN_SERVER_SECRET_KEY = 'my_pass'
def get_turn_servers(request):
if 'username' not in request.GET.keys():
return HttpResponseForbidden()
unix_timestamp_tomorrow = int(time()) + (24*60*60)
new_username = str(unix_timestamp_tomorrow)+':'+request.GET['username']
hashed = hmac.new(TURN_SERVER_SECRET_KEY, new_username, sha1)
password = hashed.digest().encode("base64").rstrip('\n')
turn_udp_uri = 'turn:%s:3478?transport=udp' % settings.DOMAIN.split(':')[0] #bez portu
turn_tcp_uri = 'turn:%s:3478?transport=tcp' % settings.DOMAIN.split(':')[0]
return JsonResponse({
'username':new_username,
'password':password,
'uris':[turn_udp_uri,
turn_tcp_uri,
]
})
Helpful will be groups:
https://groups.google.com/forum/#!forum/turn-server-project-rfc5766-turn-server
https://groups.google.com/forum/#!forum/discuss-webrtc
If sombody needs webrtc in django code, please write to me.

IP camera with RTSP on the web, RED5 and ffmpeg

i have a ip camera with rtsp protocol and i want to stream on the web using flash video. I know i can use vlc but i do not want to use that.
I installed red5 and ffmpeg for convert RTSP to RTMP
ffmpeg -i "rtsp://46.13.85.43:8020/ch0.h264" -f flv -r 25 -s 640x480 -an "rtmp://localhost/live"
and result is: UDP timeout. retrying with TCP
Any idea where is the problem ?
You have to specify that tcp protocol is used, or at least that helped me. Please add this parameter -rtsp_transport tcp to your ffmpeg command.

Livestream with crtmpserver - I can't find the live file

I use crtmpserver to make my RTMP server. I use Adobe Flash Media Live Encoder 3.2 to publish the livestream to the server. It is OK. I use a webflash player to receive the live stream. It is OK.
Now, I want to find the live file in the server, but I can't find the file. Which folder is the livestream?
If you want to stream a .flv file:
In every crtmpserver application there is a property called mediaFolder that by default refers to folder media.
mediaFolder="./media",
Then the streaming URL of the file is as:
rtmp://<server IP address>/<application name>/<file name>
If you want to stream a live stream:
When you define an stream acceptor in the acceptors section, you can specify the name of the stream by localStreamName as:
{
ip="0.0.0.0",
port=9005,
protocol="inboundTcpTs",
localStreamName="tcpchan5"
},
Then the URL of this stream is as:
rtmp://<server IP address>/<application name>/tcpchan5
To receive the input stream and feed the RTMP server, you may use FFmpeg:
ffmpeg -i <input_stream> -vcodec libx264 -s 320x240 -vb 512k -async 1 -acodec libvo_aacenc -ab 32k -ac 1 -f mpegts tcp://<server IP address>:<server feed port>
For example:
ffmpeg -i udp://224.11.11.11:2000 -vcodec libx264 -s 320x240 -vb 512k -async 1 -acodec libvo_aacenc -ab 32k -ac 1 -f mpegts tcp://127.0.0.1:9000

How to test Berkley socket (BSD) API?

I'd like to test the correctness and the completeness of an implementation of the BSP API.
The test set has to be cross-compiled for an ARM sam7x.
I don't know if this would be of any interest to you, but here are two links to presentations from NYC BSD Conference 2008: Detecting TCP regressions with tcpdiff (FreeBSD) and An introduction to the Automated Testing Framework (ATF) for NetBSD. Both were pretty good.
There is a public domain Benchmarking tool for TCP and UDP performance measurement.
It has a some amount of control available. You might be able to use it for testing.
Remember, this is not testing the API, but the implementation performance, you will need more than this.
The PCATTCP tool includes several options that are controlled by parameters passed on the command line when the program is started. To see the available options, run the PCATTCP application with the "-h" option. Here is what you would see:
pcattcp -h
PCAUSA Test TCP Utility V2.01.01.08
Usage: pcattcp -t [-options] host [ < in ]
pcattcp -r [-options > out]
Common options:
-l ## length of bufs read from or written to network (default 8192)
-u use UDP instead of TCP
-p ## port number to send to or listen at (default 5001)
-s toggle sinkmode (enabled by default)
sinkmode enabled:
-t: source (transmit) fabricated pattern
-r: sink (discard) all received data
sinkmode disabled:
-t: reads data to be transmitted from stdin
-r: writes received data to stdout
-A align the start of buffers to this modulus (default 16384)
-O start buffers at this offset from the modulus (default 0)
-v verbose: print more statistics
-d set SO_DEBUG socket option
-b ## set socket buffer size (if supported)
-f X format for rate: k,K = kilo{bit,byte}; m,M = mega; g,G = giga
-c -t: send continuously
-r: accept multiple connections sequentially
-R concurrent TCP/UDP multithreaded receiver
.
Options specific to -t:
-n ## number of source bufs written to network (default 2048)
-D don't buffer TCP writes (sets TCP_NODELAY socket option)
-w ## milliseconds of delay before each write (default 0)
-L ## desired transmit data rate in bytes/second
Options specific to -r:
-B for -s, only output full blocks as specified by -l (for TAR)
-T "touch": access each byte as it's read