ossrs / srs-gb28181

GB28181 server based on SRS
https://ossrs.net
MIT License
83 stars 41 forks source link

GB28181: 大华/海康相机在没有使能音频的情况下,推流到srs后,使用ffplay m3u8, 出现Stream #0:0: Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp #2570 #14

Open winlinvip opened 2 years ago

winlinvip commented 2 years ago

描述(Description) 使用feature/gb28181连接大华或海康的相机,在相机端没有使能音频,让相机推流到srs上,然后使用ffplay播放m3u8,命令如下:

ffplay http://172.16.7.60:8080/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125.m3u8

ffplay显示如下:

[http @ 0x7f4de0001060] No trailing CRLF found in HTTP header.0/0
[http @ 0x7f4de0001020] No trailing CRLF found in HTTP header.0/0
[http @ 0x7f4de052afe0] No trailing CRLF found in HTTP header.
[mpegts @ 0x7f4de00008c0] Could not find codec parameters for stream 0 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[hls,applehttp @ 0x7f4de0009240] Could not find codec parameters for stream 0 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, hls,applehttp, from 'http://172.16.7.60:8080/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125.m3u8':
  Duration: N/A, start: 1.960000, bitrate: N/A
  Program 0
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp
    Stream #0:1: Video: h264 (High) ([27][0][0][0] / 0x001B), yuvj420p(pc, bt470bg/bt470bg/bt709), 1280x720, 25 fps, 25 tbr, 90k tbn, 50 tbc
[swscaler @ 0x7f4dd4605ca0] deprecated pixel format used, make sure you did set range correctly
  1. SRS版本(Version): feature/gb28181
  2. SRS的日志如下(Log):
    
    [2021-09-01 20:06:21.753][Trace][29316][70677254] HTTP #0 172.16.5.242:57304 OPTIONS http://172.16.7.60:1985/api/v1/gb28181?action=sip_invite&id=34020000001320000125&chid=34020000001320000125, content-length=-1
    [2021-09-01 20:06:21.755][Trace][29316][70677254] HTTP #1 172.16.5.242:57304 GET http://172.16.7.60:1985/api/v1/gb28181?action=sip_invite&id=34020000001320000125&chid=34020000001320000125, content-length=-1
    [2021-09-01 20:06:21.755][Trace][29316][70677254] SrsGb28181Manger::create_stream_channel channel_id(34020000001320000125@34020000001320000125),port_mode(fixed)
    [2021-09-01 20:06:21.755][Trace][29316][70677254] SrsGb28181Manger::generate_ssrc id(34020000001320000125@34020000001320000125)
    [2021-09-01 20:06:21.755][Trace][29316][70677254] SrsGb28181Manger::generate_ssrc ssrc(200000125)
    [2021-09-01 20:06:21.755][Trace][29316][70677254] new source, stream_url=/live/34020000001320000125@34020000001320000125
    [2021-09-01 20:06:21.755][Trace][29316][70677254] new source, stream_url=/live/34020000001320000125@34020000001320000125
    [2021-09-01 20:06:21.758][Trace][29316][70677254] RTC bridge from RTMP, discard_aac=0, discard_bframe=1, merge_nalus=0
    [2021-09-01 20:06:21.758][Trace][29316][70677254] hls: win=4000ms, frag=1000ms, prefix=, path=./objs/nginx/html/hls, m3u8=[stream]/[stream].m3u8, ts=[stream]/[stream]-[seq].ts, aof=2.00, floor=0, clean=1, waitk=1, dispose=0ms, dts_directly=1
    [2021-09-01 20:06:21.758][Trace][29316][70677254] ignore disabled exec for vhost=
    [2021-09-01 20:06:21.758][Trace][29316][70677254] gb28181: create new stream channel id:34020000001320000125@34020000001320000125 rtmp url=rtmp://127.0.0.1:1935/live/34020000001320000125@34020000001320000125
    [2021-09-01 20:06:21.758][Trace][29316][70677254] gb28181: SrsGb28181SipService::send_message:INVITE sip:34020000001320000125@3402000000 SIP/2.0
    Via: SIP/2.0/UDP 172.16.7.60:35000;rport;branch=SrsGbB47052612
    From: <sip:34020000002000000060@3402000000>;tag=SrsGbF18238632
    To: <sip:34020000001320000125@172.16.20.125:5060>
    Call-ID: 202081677651
    CSeq: 101 INVITE
    Content-Type: Application/SDP
    Contact: <sip:34020000001320000125@172.16.20.125:5060>
    Max-Forwards: 70
    User-Agent: SRS/5.0.10(Leo)
    Subject: 34020000001320000125:0200000125,34020000002000000060:0
    Content-Length: 162

v=0 o=34020000002000000060 0 0 IN IP4 172.16.7.60 s=Play c=IN IP4 172.16.7.60 t=0 0 m=video 9000 RTP/AVP 96 a=recvonly a=rtpmap:96 PS/90000 y=0200000125

[2021-09-01 20:06:21.759][Trace][29316][3fk32j06] gb28181: client id=34020000001320000125@34020000001320000125, ssrc=0xbebc27d, peer(, 0), rtmp muxer is alive [2021-09-01 20:06:21.765][Trace][29316][750f3313] SrsGb28181SipService::on_udp_packet, peer_ip(172.16.20.125), peer_port(5060) [2021-09-01 20:06:21.766][Trace][29316][750f3313] gb28181:SrsGb28181SipService::on_udp_sip request peer(172.16.20.125, 5060) nbbuf=303 [2021-09-01 20:06:21.766][Trace][29316][750f3313] SrsGb28181SipService::on_udp_sip session_id(34020000001320000125) [2021-09-01 20:06:21.766][Trace][29316][750f3313] SrsGb28181SipService::on_udp_sip gb28181: is_invite request client id=34020000001320000125, peer(172.16.20.125, 5060) [2021-09-01 20:06:21.766][Trace][29316][750f3313] SrsGb28181SipService::on_udp_sip gb28181: is_invite respone method=INVITE, uri=34020000002000000060@3402000000, version=SIP/2.0 [2021-09-01 20:06:21.766][Trace][29316][750f3313] gb28181: INVITE response 34020000001320000125 client status=100 [2021-09-01 20:06:21.766][Trace][29316][750f3313] SrsGb28181SipService::on_udp_packet, peer_ip(172.16.20.125), peer_port(5060) [2021-09-01 20:06:21.766][Trace][29316][750f3313] gb28181:SrsGb28181SipService::on_udp_sip request peer(172.16.20.125, 5060) nbbuf=410 [2021-09-01 20:06:21.766][Trace][29316][750f3313] SrsGb28181SipService::on_udp_sip session_id(34020000001320000125) [2021-09-01 20:06:21.766][Trace][29316][750f3313] SrsGb28181SipService::on_udp_sip gb28181: is_invite request client id=34020000001320000125, peer(172.16.20.125, 5060) [2021-09-01 20:06:21.766][Trace][29316][750f3313] SrsGb28181SipService::on_udp_sip gb28181: is_invite respone method=INVITE, uri=34020000002000000060@3402000000, version=SIP/2.0 [2021-09-01 20:06:21.766][Trace][29316][750f3313] gb28181: INVITE response 34020000001320000125 client status=101 [2021-09-01 20:06:21.771][Trace][29316][750f3313] SrsGb28181SipService::on_udp_packet, peer_ip(172.16.20.125), peer_port(5060) [2021-09-01 20:06:21.771][Trace][29316][750f3313] gb28181:SrsGb28181SipService::on_udp_sip request peer(172.16.20.125, 5060) nbbuf=669 [2021-09-01 20:06:21.771][Trace][29316][750f3313] gb28181: ssrc in y line is 200000125:bebc27d [2021-09-01 20:06:21.771][Trace][29316][750f3313] SrsGb28181SipService::on_udp_sip session_id(34020000001320000125) [2021-09-01 20:06:21.771][Trace][29316][750f3313] SrsGb28181SipService::on_udp_sip gb28181: is_invite request client id=34020000001320000125, peer(172.16.20.125, 5060) [2021-09-01 20:06:21.771][Trace][29316][750f3313] SrsGb28181SipService::on_udp_sip gb28181: is_invite respone method=INVITE, uri=34020000002000000060@3402000000, version=SIP/2.0 [2021-09-01 20:06:21.771][Trace][29316][750f3313] gb28181: INVITE response 34020000001320000125 client status=200 [2021-09-01 20:06:21.771][Trace][29316][750f3313] gb28181: device unique id is 34020000001320000125@34020000001320000125 [2021-09-01 20:06:21.771][Trace][29316][750f3313] gb28181: SrsGb28181SipService::send_message:ACK sip:34020000001320000125@3402000000 SIP/2.0 Via: SIP/2.0/UDP 172.16.7.60:35000;rport;branch=SrsGbB47052612 From: sip:34020000002000000060@3402000000;tag=SrsGbF18238632 To: sip:34020000001320000125@172.16.20.125:5060;tag=6f6ee232c6ae6afe3c3f9b68632ddaeb Call-ID: 202081677651 CSeq: 101 ACK Max-Forwards: 70 User-Agent: SRS/5.0.10(Leo) Content-Length: 0

[2021-09-01 20:06:21.907][Trace][29316][3fk32j06] gb28181: ps map video es_type=h264(1b), es_id=e0, es_info_length=12 [2021-09-01 20:06:21.908][Trace][29316][3fk32j06] 47B video sh, codec(7, profile=High, level=3.1, 1280x720, 0kbps, 0.0fps, 0.0s) [2021-09-01 20:06:22.840][Trace][29316][750f3313] <- GBS gb28181: client_id , peer(172.16.20.125, 9724) ps rtp packet 40B, age=36947487, vt=2/96, sts=214/93600/0xbebc27d, paylod=28B [2021-09-01 20:06:25.896][Trace][29316][a3d8t9la] Hybrid cpu=3.00%,19MB, cid=4,1, timer=62,0,0, clock=0,48,1,1,0,0,0,0,0, objs=(pkt:78,raw:0,fua:78,msg:109,oth:1,buf:1) [2021-09-01 20:06:30.373][Trace][29316][v93v7is0] HTTP #0 172.16.7.60:60342 GET http://172.16.7.60:8080/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125.m3u8, content-length=-1 [2021-09-01 20:06:30.373][Trace][29316][v93v7is0] http match file=./objs/nginx/html/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125.m3u8, pattern=/, upath=/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125.m3u8 [2021-09-01 20:06:30.373][Trace][29316][v93v7is0] TCP: before dispose resource(HttpStream)(0x18f5bc0), conns=2, zombies=0, ign=0, inz=0, ind=0 [2021-09-01 20:06:30.373][Trace][29316][v93v7is0] client finished. [2021-09-01 20:06:30.373][Trace][29316][48y7700u] TCP: clear zombies=1 resources, conns=2, removing=0, unsubs=0 [2021-09-01 20:06:30.373][Trace][29316][v93v7is0] TCP: disposing #0 resource(HttpStream)(0x18f5bc0), conns=2, disposing=1, zombies=0 [2021-09-01 20:06:30.374][Trace][29316][69079r5o] HTTP #0 172.16.7.60:60344 GET http://172.16.7.60:8080/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125-1.ts, content-length=-1 [2021-09-01 20:06:30.374][Trace][29316][69079r5o] http match file=./objs/nginx/html/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125-1.ts, pattern=/, upath=/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125-1.ts [2021-09-01 20:06:30.375][Trace][29316][69079r5o] TCP: before dispose resource(HttpStream)(0x18f5bc0), conns=2, zombies=0, ign=0, inz=0, ind=0 [2021-09-01 20:06:30.375][Trace][29316][69079r5o] client finished. [2021-09-01 20:06:30.375][Trace][29316][48y7700u] TCP: clear zombies=1 resources, conns=2, removing=0, unsubs=0 [2021-09-01 20:06:30.375][Trace][29316][69079r5o] TCP: disposing #0 resource(HttpStream)(0x18f5bc0), conns=2, disposing=1, zombies=0 [2021-09-01 20:06:30.413][Trace][29316][3are8721] HTTP #0 172.16.7.60:60346 GET http://172.16.7.60:8080/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125-2.ts, content-length=-1 [2021-09-01 20:06:30.413][Trace][29316][3are8721] http match file=./objs/nginx/html/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125-2.ts, pattern=/, upath=/hls/34020000001320000125@34020000001320000125/34020000001320000125@34020000001320000125-2.ts [2021-09-01 20:06:30.415][Trace][29316][3are8721] TCP: before dispose resource(HttpStream)(0x19a0ba0), conns=2, zombies=0, ign=0, inz=0, ind=0


1. SRS的配置如下(Config):

listen 1935; max_connections 1000; daemon off; srs_log_tank console;

http_api { enabled on; listen 1985; }

http_server { enabled on; listen 8080; }

stats { network 0; }

stream_caster { enabled on; caster gb28181;

# 转发流到rtmp服务器地址与端口
# TODO: https://github.com/ossrs/srs/pull/1679/files#r400875104
# [stream] is VideoChannelCodecID(视频通道编码ID) for sip
# 自动创建的道通[stream] 是‘chid[ssrc]’ [ssrc]是rtp的ssrc
# [ssrc] rtp中的ssrc
output              rtmp://127.0.0.1:1935/live/[stream];

# 接收设备端rtp流的多路复用端口
# 媒体服务端(播放器,收流端的端口) by chao
listen              9000;
# 多路复用端口类型,on为tcp,off为udp
# 默认:on
#tcp_enable            on;
tcp_enable            off; # rtp荷载的ps流,底层是udp by chao

# rtp接收监听端口范围,最小值
rtp_port_min        58200;
# rtp接收监听端口范围,最大值
rtp_port_max        58300;

# 是否等待关键帧之后,再转发,
# off:不需等待,直接转发
# on:等第一个关键帧后,再转发
wait_keyframe       on;

# rtp包空闲等待时间,如果指定时间没有收到任何包
# rtp监听连接自动停止,发送BYE命令
rtp_idle_timeout    30;

# 是否转发音频流
# 目前只支持aac格式,所以需要设备支持aac格式
# on:转发音频
# off:不转发音频,只有视频
# *注意*!!!:flv 只支持11025  22050  44100 三种
# 如果设备端没有三种中任何一个,转发时为自动选择一种格式
# 同时也会将adts的头封装在flv aac raw数据中
# 这样的话播放器为自动通过adts头自动选择采样频率
# 像ffplay, vlc都可以,但是flash是没有声音,
# 因为flash,只支持11025 22050 44100
audio_enable        off;

# 是否开启rtp缓冲
# 开启之后能有效解决rtp乱序等问题
# tcp模式建议关闭
jitterbuffer_enable  off;

# 服务器主机号,可以域名或ip地址
# 也就是设备端将媒体发送的地址,如果是服务器是内外网
# 需要写外网地址,
# 调用api创建stream session时返回ip地址也是host
# $CANDIDATE 是系统环境变量,从环境变量获取地址,如果没有配置,用*
# *代表指定stats network 的网卡号地址,如果没有配置network,默认则是第0号网卡地址
# TODO: https://github.com/ossrs/srs/pull/1679/files#r400917594
#host       $CANDIDATE;
host       172.16.7.60; # 配置成145,可以在145上通过tcpdump来抓视频流
#host       172.16.5.189;  # 收流端的ip地址(可以是程序所在的机器也可以是其他ip) by chao

#根据收到ps rtp包自带创建rtmp媒体通道,不需要api接口创建
#rtmp地址参数[stream] 就是通道id  格式chid[ssrc]
auto_create_channel   off;

sip {
    # 是否启用srs内部sip信令
    # 为on信令走srs, off 只转发ps流
    enabled on;

    # 此框架没有对注册过来的设备进行鉴权 by chao

    # sip监听udp端口
    #listen              5060;
    listen              35000; # sip服务器的端口

    # SIP server ID(SIP服务器ID).
    # 设备端配置编号需要与该值一致,否则无法注册
    #serial              34020000002000000001;
    serial              34020000002000000060;

    # SIP server domain(SIP服务器域)
    realm               3402000000;

    # 服务端发送ack后,接收回应的超时时间,单位为秒
    # 如果指定时间没有回应,认为失败
    ack_timeout         30;

    # 设备心跳维持时间,如果指定时间内(秒)没有接收一个心跳
    # 认为设备离线
    keepalive_timeout   120;

    # 注册之后是否自动给设备端发送invite
    # on: 是  off 不是,需要通过api控制
    #auto_play           on; # by chao
    auto_play           off;
    # 设备将流发送的端口,是否固定
    # on 发送流到多路复用端口 如9000
    # off 自动从rtp_mix_port - rtp_max_port 之间的值中
    # 选一个可以用的端口
    invite_port_fixed     on;

    # 向设备或下级域查询设备列表的间隔,单位(秒)
    # 默认60秒
    query_catalog_interval  60;
}

}

rtc_server { enabled on;

Listen at udp://8000

listen          8000;
#
# The $CANDIDATE means fetch from env, if not configed, use * as default.
#
# The * means retrieving server IP automatically, from all network interfaces,
# @see https://github.com/ossrs/srs/issues/307#issuecomment-599028124
candidate       $CANDIDATE;

}

vhost defaultVhost { rtc { enabled on; bframe discard; }

http_remux {
    enabled     on;
    mount       [vhost]/[app]/[stream].flv;
}

    hls {
    enabled on;
    hls_path ./objs/nginx/html/hls;
    hls_m3u8_file [stream]/[stream].m3u8;
    hls_ts_file [stream]/[stream]-[seq].ts;
    hls_fragment 1;
    hls_window 4;
}

}



**重现(Replay)**

> 重现Bug的步骤(How to replay bug?)

大华或海康的相机,在没有使能音频的情况,接入srs,流推送到srs上,使用ffplay 播放m3u8,ffplay终端有Could not find codec parameters for stream 0 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Stream #0:0: Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp的信息

**期望行为(Expect)**

> srs源码中有保存h264文件的宏,将宏定义打开,保存h264文件,然后使用ffplay播放,没有上述音频信息,而直接使用ffplay m3u8文件,确认Audio的信息,请问是什么原因,如何解决,谢谢