gnolizuh / BLSS

NGINX-based Live Media Streaming Server
Other
196 stars 73 forks source link

RTMP Pull #114

Open warlock135 opened 5 years ago

warlock135 commented 5 years ago

Hi, I'm trying to implement an edge server with your module. Unfortunately, I couldn't figure out how to use the pull command with your module, to pull rtmp stream from origin server. This is the configuration I tried: My origin server is 10.58.201.130 with nginx rtmp. Streaming to it works fine - url: rtmp://10.58.201.130/live/test2. My edge server is the localhost. Here is my nginx config:

rtmp {
    server {
        listen 1935 reuseport;
        chunk_size 4096;                       
        allow play all;

        service cctv {
            hostname direct-bi proto-all localhost 127.0.0.1;
            application edgelive {
                live on;
                meta copy;
                pull rtmp://10.58.201.130/ app=live;
            }
            application edgelive1 {
                live on;
                meta copy;
                pull rtmp://127.0.0.1/ app=live;
            }
            application edgelive2 {
                live on;
                meta copy;
                exec_pull ffmpeg -i rtmp://10.58.201.130/live/$name -c copy -f flv rtmp://127.0.0.1/$app/$name;
            }
            application live {
                live on;

                gop_cache on;
                gop_cache_count 5;  # cache 5 GOPs

                hls on;
                hls_fragment 10s;
                hls_playlist_length 30s;
            }
      }
   }
}

With this configuration, I can play the stream from the origin server with edgelive2 application which uses exec_pull and ffmpeg. Streaming locally into live application and using edgelive1 to play also works. But the edgelive application does not work, ffplay show this error _"RTMPReadPacket, failed to read RTMP packet header" when I try the url: ./ffplay rtmp://127.0.0.1/edgelive/test2 Here is the nginx log:

2018/10/03 19:49:36 [info] 7922#0: *1 client connected '127.0.0.1'
2018/10/03 19:49:36 [info] 7922#0: *1 connect: host='127.0.0.1' app='edgelive' args='' flashver='' swf_url='' tc_url='rtmp://127.0.0.1/edgelive' page_url='' acodecs=3191 vcodecs=252 object_encoding=0, client: 127.0.0.1, server: 0.0.0.0:1935
2018/10/03 19:49:36 [info] 7922#0: *1 createStream, client: 127.0.0.1, server: 0.0.0.0:1935
2018/10/03 19:49:36 [info] 7922#0: *1 play: name='test2' args='' start=0 duration=0 reset=0 silent=0, client: 127.0.0.1, server: 0.0.0.0:1935
2018/10/03 19:49:36 [info] 7922#0: *1 relay: create pull name='test2' app='live' playpath='' url='10.58.201.130/', client: 127.0.0.1, server: 0.0.0.0:1935
2018/10/03 19:49:36 [info] 7922#0: *1 gop cache play: name='test2' start=0 duration=0 reset=0, client: 127.0.0.1, server: 0.0.0.0:1935
2018/10/03 19:49:36 [info] 7922#0: *2 gop cache publish: name='test2' type='', client: 10.58.201.130/, server: ngx-relay
2018/10/03 19:50:15 [info] 7922#0: *1 disconnect, client: 127.0.0.1, server: 0.0.0.0:1935
2018/10/03 19:50:15 [info] 7922#0: *1 deleteStream, client: 127.0.0.1, server: 0.0.0.0:1935

How can I use the pull command to get the stream from a server rather than localhost? Is there any problem with the configuration? I really appreciate any help you can provide!

Edit: Seems like adding 10.58.201.130 to hostname solves the problem. However, It only works with standard rtmp port. When I tried to pull from a source with different port, for instance 10.58.201.130:9030, I still get the same error. How can I modify the config to pull from a specific port?

LancCJ commented 2 years ago
    #this is right 
    application mypull_a {
        live on;
        pull rtmp://10.58.201.130/live/test2 name=testa;
    }

you can use url : rtmp:127.0.0.1:port/mypull_a/testa