Skip to content

http重定向到rtmp,ijkplayer无法播放视频 #3990

Open
@bruceshu

Description

@bruceshu

ijk版本k0.8.4

错误日志如下:
01-30 11:46:50.076 29667-29712/tv.danmaku.ijk.media.example I/IJKMEDIA: Add dns cache hostname = qq.kingshoster.com, ip = 185.102.218.76
01-30 11:46:50.076 29667-29712/tv.danmaku.ijk.media.example D/IJKMEDIA: request: GET /live/wisdom/wisdom/855.m3u8 HTTP/1.1
User-Agent: Lavf/57.71.100
Accept: /
Range: bytes=0-
Connection: close
Host: qq.kingshoster.com:25461
Icy-MetaData: 1
01-30 11:46:50.517 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: header='HTTP/1.1 302 Found'
01-30 11:46:50.518 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: http_code=302
01-30 11:46:50.518 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: header='Server: nginx'
01-30 11:46:50.518 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: header='Date: Tue, 30 Jan 2018 11:46:50 GMT'
01-30 11:46:50.518 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: header='Content-Type: text/html; charset=UTF-8'
01-30 11:46:50.518 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: header='Connection: close'
01-30 11:46:50.518 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: header='Access-Control-Allow-Origin: *'
01-30 11:46:50.519 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: header='Location: rtmp://ns8.indexforce.com/alsharqiyalive/mystream'
01-30 11:46:50.519 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: header=''
01-30 11:46:50.519 29667-29712/tv.danmaku.ijk.media.example E/IJKMEDIA: bruce >>> http_code=302,location=1

                                                                    [ 01-30 11:46:50.540  5009: 5009 D/         ]
                                                                    ----------------week = 3

01-30 11:46:51.876 29667-29712/tv.danmaku.ijk.media.example I/IJKMEDIA: Add dns cache hostname = ns8.indexforce.com, ip = 188.138.57.138
01-30 11:46:51.876 29667-29712/tv.danmaku.ijk.media.example D/IJKMEDIA: request: GET /alsharqiyalive/mystream HTTP/1.1
User-Agent: Lavf/57.71.100
Accept: /
Range: bytes=0-
Connection: close
Host: ns8.indexforce.com
Icy-MetaData: 1
01-30 11:46:52.235 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: header='HTTP/1.1 404 Not Found'
01-30 11:46:52.235 29667-29712/tv.danmaku.ijk.media.example V/IJKMEDIA: http_code=404
01-30 11:46:52.235 29667-29712/tv.danmaku.ijk.media.example W/IJKMEDIA: HTTP error 404 Not Found

查看底层代码发现,在 http_open_cnx 函数中,如果接收到重定向状态码,并且location_changed = 1,就会再次以http的方式发送rtmp的地址请求,这个就有问题,最后就返回了404状态码。
代码如下:
if ((s->http_code == 301 || s->http_code == 302 ||
s->http_code == 303 || s->http_code == 307) &&
location_changed == 1) {
/* url moved, get next /
ffurl_closep(&s->hd);
if (redirects++ >= MAX_REDIRECTS)
return AVERROR(EIO);
/
Restart the authentication process with the new target, which
* might use a different auth mechanism. */
memset(&s->auth_state, 0, sizeof(s->auth_state));
attempts = 0;
location_changed = 0;
goto redo;
}
在这个分支中,是否应该对s->location(rtmp地址)做rtmp连接处理,通过调用 ffurl_open_whitelist 函数,望官方维护人员解答,谢谢~

Activity

CarGuo

CarGuo commented on Jan 31, 2018

@CarGuo

我再http和https的切换中,是通过IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_clear", 1 解决error,但是在切换rtsp中,也会出现404问题,不知道是不是也是这个问题,mark下等待回复

zhanggao

zhanggao commented on Apr 3, 2018

@zhanggao

#3700
应该和这同一个问题,没想到过这么久还没解决,我改成缓存 域名+端口号 好了。http、https、rtmp的端口号不同

ened

ened commented on May 11, 2018

@ened
Contributor

@CarGuo Thank you so much for your comment.
This code:

ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_clear", 1);

... will resolve playback issues when streaming HTTP streams with this player.

nicolasiJasica

nicolasiJasica commented on Mar 13, 2020

@nicolasiJasica

mark

szNightFury

szNightFury commented on Dec 28, 2023

@szNightFury

请问问题解决了吗?我尝试了dns cache clear=1没有起到效果,而且http的ip地址和rtmp的ip地址不相同也有同样的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ened@nicolasiJasica@zhanggao@CarGuo@bruceshu

        Issue actions

          http重定向到rtmp,ijkplayer无法播放视频 · Issue #3990 · bilibili/ijkplayer