how to setup rtmp wtih ffmpeg and aparat.com?

1.1k Views Asked by At

i am completely new to rtmp and nginx and ubuntu i just want to use a vps to restream my stream to multiple site like twitch, youtube etc... it worked fine for me but recently my main streaming website aparat.com change his system and they don't take push command in /usr/local/nginx/conf/nginx.conf i used this :

application live {
live on;
record off;
push rtmp://live.cdn.asset.aparat.com:443/event/<stream key>;
}

and it work fine with twitch or youtube or mixer but it won't work with aparat.com

don't know why they give me this instead and tell me to use it :

application live {
live on;
record off;
hls off;
dash off;
wait_key on;
exec_publish ffmpeg -i rtmp://127.0.0.1/live/name -async 1 -vsync 1 -c copy -f flv "rtmp://rtmp.cdn.asset.aparat.com:443/event/<stream key>";
}

when i start streaming i get no stream on site. should i change anything beside on the line i highligh? should i install anything on my ubuntu 18.04.4?

please just consider i have no idea about anything there and i just cope paste codes...

i install ffmpeg and stunnel already and config them i also try this :

exec_publish ffmpeg -i rtmp://127.0.0.1/live/name -async 1 -vsync 1 -c copy -f flv "rtmp://live.cdn.asset.aparat.com:443/event/<stream key>";
exec_publish ffmpeg -i rtmp://127.0.0.1:19350/live/name -async 1 -vsync 1 -c copy -f flv "rtmp://live.cdn.asset.aparat.com:443/event/<stream key>";
exec_publish ffmpeg -i rtmp://127.0.0.1:19350/live/name -async 1 -vsync 1 -c copy -f flv "rtmp://rtmp.cdn.asset.aparat.com:443/event/<stream key>";

an i should say everything is ok with twitch and youtube also i use OBS to stream games and everything is fine when i stream directly to aparat.com and using rtmp://rtmp.cdn.asset.aparat.com:443/event

1

There are 1 best solutions below

0
On

The service suggests the following command:

exec_publish ffmpeg -i rtmp://127.0.0.1/live/name -async 1 -vsync 1 -c copy -f flv "rtmp://live.cdn.asset.aparat.com:443/event/<stream key>";

Let's understand the command above:

rtmp://127.0.0.1/live/name - This is a block on your nginx settings. So you must to create a server block listening the localhost, port 1935, because 1935 is the default rtmp protocol port, or you can change to any other port and append this port to the command above, like this:

rtmp://127.0.0.1:port/live/name

rtmp://127.0.0.1/live/name - This is the publishing point and your nginx publish block inside the server block above (this name can be anything that you wish) but it must to exists otherwise the nginx server will drop the connection.

rtmp://127.0.0.1/live/name - This is your streaming name (this name can be anything that you wish) like the publish name above.

Ok. Now you have a new rtmp server block, listening localhost connections, using the port that you wish, the publish name that you wish and the streaming name that you wish. Now, inside this block you must to re-encode your streaming using ffmeg if required by the service destination (aparat) and send it to the stunnel proxy or simply push the stream to the stunnel proxy because this service requires RTMPS. Something like this:

rtmp {

   server {
      listen 127.0.0.1:1935;
      # or 127.0.0.1:yourPort;

      application live {
         live on;
         # i will push the stream name to the stunnel proxy, 
         # without re-encoded it because i believe you can adjust the broadcaster
         # software to send it as your service requires it.
         # Understand that stunnel proxy will be listening localhost connections
         # under the port 1936 or change it to your stunnel settings 
         push rtmp://127.0.0.1:1936/event/streamkey
      }
   }

}

Now, let's understand the push stunnel proxy url:

push rtmp://127.0.0.1:1936/event/streamkey

rtmp://127.0.0.1:1936/event/streamkey - This part is the url where stunnel will listen connections, server(127.0.0.1) and port(1936).

rtmp://127.0.0.1:1936/event/streamkey - This is the path where stunnel will publish your stream on then service destination (aparat).

Now, stunnel will simply replace the 127.0.0.1:1936 by the host and port required by the service (443) and send your stream using RTMPS.

Below, my sugestion for the stunnel.conf:

pid = /var/run/stunnel4/stunnel.pid
output = /var/log/stunnel4/stunnel.log

setuid = stunnel4
setgid = stunnel4

# https://www.stunnel.org/faq.html

socket = r:TCP_NODELAY=1
socket = l:TCP_NODELAY=1

debug = 4

[aparat-live]
client = yes
accept = 127.0.0.1:1936
connect = rtmp.cdn.asset.aparat.com:443
verifyChain = no

Now, on your default pusblish block on your server, add this line, replacing the first command suggested by your remote service:

push rtmp://127.0.0.1:1935/live/name;

The command above inside your default publish block will push the stream to the server block (localhost:1935) and this will send the stream to the stunnel proxy.

Understand that you don't need the new server block to send the stream directly to the stunnel proxy. This is an explanation for your question using the command that you posted.

You can just replace that command by this on your default publish block, and it will send the stream to the stunnel proxy:

Replace

exec_publish ffmpeg -i rtmp://127.0.0.1/live/name -async 1 -vsync 1 -c copy -f flv "rtmp://live.cdn.asset.aparat.com:443/event/<stream key>";

By

push rtmp://127.0.0.1:1936/event/<streamkey>;

You only need a stunnel proxy working fine.

Done, restart nginx and stunnel services and happy stream.