Go语言实现Onvif客户端:6、获取rtsp流地址

Go语言实现Onvif客户端:6、获取rtsp流地址


1、代码

获取并选择Profile token后获取rtsp流地址也是调用接口即可:

/**
 * @Description: 获取rtsp流媒体信息
 * @time: 2021-03-30 11:22:06
 * @receiver client
 * @return returnInfo:结果Code码和Info信息,Code码为0则成功,否则失败,通过获取Info查看失败原因
 */
func (client *GoOnvifClient) GetStreamUri() returnInfo {
	if client.localSelectProfileToken == "" {
		return returnInfo{GetStreamUriErr, "profile token is nil."}
	}

	return client.getStreamUri()
}

/**
 * @Description: 根据选中的Profile token获取码流rtsp地址等
 * @time: 2021-03-25 14:28:46
 * @receiver client
 * @return returnInfo
 */
func (client *GoOnvifClient) getStreamUri() returnInfo {
	mediaUrlReq := media.GetStreamUri{}
	mediaUrlReq.ProfileToken = onvif.ReferenceToken(client.localSelectProfileToken)

	return client.sendReqGetResp(GetStreamUriErr, mediaUrlReq)
}

2、结果:

获取到的xml信息如下:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:tst="http://www.onvif.org/ver10/storage/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:dn="http://www.onvif.org/ver10/network/wsdl" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl" xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12" xmlns:http="http://schemas.xmlsoap.org/wsdl/http" xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsadis="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wsntw="http://docs.oasis-open.org/wsn/bw-2" xmlns:wsrf-rw="http://docs.oasis-open.org/wsrf/rw-2" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:tnshik="http://www.hikvision.com/2011/event/topics" xmlns:hikwsd="http://www.onvifext.com/onvif/ext/ver10/wsdl" xmlns:hikxsd="http://www.onvifext.com/onvif/ext/ver10/schema" xmlns:tas="http://www.onvif.org/ver10/advancedsecurity/wsdl" xmlns:tr2="http://www.onvif.org/ver20/media/wsdl" xmlns:axt="http://www.onvif.org/ver20/analytics">
	<env:Body>
		<trt:GetStreamUriResponse>
			<trt:MediaUri>
				<tt:Uri>rtsp://40.40.40.101:554/Streaming/Channels/101?transportmode=unicast&amp;profile=Profile_1</tt:Uri>
				<tt:InvalidAfterConnect>false</tt:InvalidAfterConnect>
				<tt:InvalidAfterReboot>false</tt:InvalidAfterReboot>
				<tt:Timeout>PT60S</tt:Timeout>
			</trt:MediaUri>
		</trt:GetStreamUriResponse>
	</env:Body>
</env:Envelope>

3、查看

使用vlc播放器播放即可,比如我们上面获取的url为:rtsp://40.40.40.101:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1

则通过打开网络串流播放:

在这里插入图片描述

如果url正确则播放正常,这里显示的码流和你选择的Profile token相关:

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 16
    评论
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昵称系统有问题

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值