ossrs / srs

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
25.28k stars 5.33k forks source link

RTMP: Nginx-rtmp streaming to SRS failed for dropping AMF0 message. #958

Open juntaoliu opened 7 years ago

juntaoliu commented 7 years ago

The origin server uses Nginx-rtmp to push the stream to SRS, but an error occurs and the video cannot be played. However, if SRS pulls the stream from Nginx-rtmp, there is no problem and it can be played.

SRS version related information: server:SRS/2.0.243(ZhouGuowen) server_version:2.0.243

Video related information: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf55.18.100 Duration: 00:09:56.50, start: 0.021333, bitrate: 598 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 854x480 [SAR 1280:1281 DAR 16:9], 464 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default) Metadata:

The following is the error log:

[2017-08-18 23:04:01.927][trace][5327][2198] identify ignore messages except AMF0/AMF3 command message. type=0x8 [2017-08-18 23:04:01.927][trace][5327][2198] identify ignore messages except AMF0/AMF3 command message. type=0x9 [2017-08-18 23:04:01.927][trace][5327][598] identify ignore messages except AMF0/AMF3 command message. type=0x8 [2017-08-18 23:04:01.927][trace][5327][598] identify ignore messages except AMF0/AMF3 command message. type=0x9 [2017-08-18 23:04:01.927][trace][5327][598] identify ignore messages except AMF0/AMF3 command message. type=0x8 [2017-08-18 23:04:01.927][trace][5327][598] identify ignore messages except AMF0/AMF3 command message. type=0x9 [2017-08-18 23:04:01.927][trace][5327][570] identify ignore messages except AMF0/AMF3 command message. type=0x8 [2017-08-18 23:04:01.927][trace][5327][570] identify ignore messages except AMF0/AMF3 command message. type=0x9 [2017-08-18 23:04:01.927][trace][5327][570] identify ignore messages except AMF0/AMF3 command message. type=0x8 [2017-08-18 23:04:01.927][trace][5327][570] identify ignore messages except AMF0/AMF3 command message. type=0x9 [2017-08-18 23:04:01.927][trace][5327][542] identify ignore messages except AMF0/AMF3 command message. type=0x8

TRANS_BY_GPT3

juntaoliu commented 7 years ago

Other logs to add:

[2017-08-19 20:55:15.940][trace][2693][107] RTMP client ip=127.0.0.1 [2017-08-19 20:55:15.940][trace][2693][107] srand initialized the random. [2017-08-19 20:55:15.969][trace][2693][107] complex handshake success [2017-08-19 20:55:16.010][trace][2693][107] discovery hostname=CentOs6.6Dev [2017-08-19 20:55:16.010][trace][2693][107] connect app, tcUrl=rtmp://127.0.0.1:1936/live, pageUrl=, swfUrl=, schema=rtmp, vhost=defaultVhost, port=1936, app=live, args=null [2017-08-19 20:55:16.058][trace][2693][107] client identified, type=Flash-Publish, stream_name=gaoxiao, duration=-1.00 [2017-08-19 20:55:16.081][trace][2693][107] source url=/live/gaoxiao, ip=127.0.0.1, cache=1, is_edge=0, source_id=-1[-1] [2017-08-19 20:55:16.093][trace][2693][107] http: mount flv stream for vhost=/live/gaoxiao, mount=/live/gaoxiao.flv [2017-08-19 20:55:16.104][trace][2693][107] start publish mr=0/350, p1stpt=20000, pnt=5000, tcp_nodelay=0, rtcid=111 [2017-08-19 20:55:17.012][trace][2693][107] got metadata, width=544, height=720, vcodec=7, acodec=10 [2017-08-19 20:55:17.012][trace][2693][107] protocol in.buffer=0, in.ack=5000000, out.ack=2500000, in.chunk=4096, out.chunk=60000 [2017-08-19 20:55:17.012][trace][2693][107] 44B video sh, codec(7, profile=High, level=3, 544x720, 0kbps, 0fps, 0s) [2017-08-19 20:55:17.012][trace][2693][107] 4B audio sh, codec(10, profile=LC, 1channels, 0kbps, 44100HZ), flv(16bits, 2channels, 44100HZ) [2017-08-19 20:55:17.012][trace][2693][107] 44B video sh, codec(7, profile=High, level=3, 544x720, 0kbps, 0fps, 0s) [2017-08-19 20:55:17.012][trace][2693][107] 4B audio sh, codec(10, profile=LC, 1channels, 0kbps, 44100HZ), flv(16bits, 2channels, 44100HZ) [2017-08-19 20:55:17.012][trace][2693][107] flash flash publish finished. [2017-08-19 20:55:17.013][trace][2693][107] cleanup when unpublish [2017-08-19 20:55:17.013][trace][2693][107] control message(unpublish) accept, retry stream service. [2017-08-19 20:55:17.013][trace][2693][107] identify ignore messages except AMF0/AMF3 command message. type=0x8 [2017-08-19 20:55:17.013][trace][2693][107] identify ignore messages except AMF0/AMF3 command message. type=0x8 [2017-08-19 20:55:17.013][trace][2693][107] identify ignore messages except AMF0/AMF3 command message. type=0x8 [2017-08-19 20:55:17.013][trace][2693][107] identify ignore messages except AMF0/AMF3 command message. type=0x9 [2017-08-19 20:55:17.022][trace][2693][107] identify ignore messages except AMF0/AMF3 command message. type=0x8 [2017-08-19 20:55:17.022][trace][2693][107] identify ignore messages except AMF0/AMF3 command message. type=0x8

TRANS_BY_GPT3

juntaoliu commented 7 years ago

Summary of the following four usage scenarios, recorded here:

  1. ffmpge pushes the stream to SRS, and SRS directly forwards it to Nginx-Rtmp. Both sides can play without any issues.
  2. ffmpge pushes the stream to Nginx-Rtmp, and SRS specifies the edge mode. It pulls the stream from Nginx-Rtmp by specifying the origin as Nginx-Rtmp. Both sides can play without any issues.
  3. ffmpge pushes the stream to SRS, and Nginx-Rtmp uses the pull command to specify SRS as the source for pulling the stream. It cannot play the stream (but SRS can play it).
  4. ffmpge pushes the stream to Nginx-Rtmp, and Nginx-Rtmp uses the push command to push it to SRS. Nginx-Rtmp fails to forward the stream (but Nginx-Rtmp can play it).

TRANS_BY_GPT3

juntaoliu commented 7 years ago

The aforementioned issues, two of which cannot be played, have been identified with approximate reasons.

Regarding the aforementioned issue 3, the reason is that nginx-rtmp is configured with the option "idle_streams on," which causes the origin request to fail when nginx-rtmp is used as an edge server. This option should not be used in this scenario.

As for the aforementioned issue 4, the reason is that the user added first frame caching in nginx-rtmp (added by the user themselves), which caused compatibility issues.

There is no problem with SRS and nginx-rtmp pushing and pulling streams from each other.

TRANS_BY_GPT3

juntaoliu commented 7 years ago

When pushing the stream from nginx-rtmp to srs, the flash publish mode is used. This mode works fine in version 3.0 but has issues in version 2.0.

Commenting out the "return ERROR_CONTROL_REPUBLISH;" in the following code can make it compatible.

int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg, bool is_fmle, bool vhost_is_edge)
{
    int ret = ERROR_SUCCESS;

    // process publish event.
    if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
        SrsPacket* pkt = NULL;
        if ((ret = rtmp->decode_message(msg, &pkt)) != ERROR_SUCCESS) {
            srs_error("fmle decode unpublish message failed. ret=%d", ret);
            return ret;
        }
        SrsAutoFree(SrsPacket, pkt);

        // for flash, any packet is republish.
        if (!is_fmle) {
            // flash unpublish.
            // TODO: maybe need to support republish.
            srs_trace("flash flash publish finished.");
            //return ERROR_CONTROL_REPUBLISH;
        }

TRANS_BY_GPT3

winlinvip commented 5 months ago

Reopen this issue for it may exists in 5.0, see #3620