从IPC摄像机读取视频帧解码并转化为YUV数据到转化为Bitmap
前言
本文主要介绍根据IPC的RTSP视频流地址,连接摄像机,并持续读取相机视频流,进一步进行播放实时画面,或者处理视频帧,将每一帧数据转化为安卓相机同格式数据,并保存为bitmap。
示例
val rtspClientListener = object: RtspClient.RtspClientListener {
override fun onRtspConnecting() {
}
override fun onRtspConnected(sdpInfo: SdpInfo) {
}
override fun onRtspVideoNalUnitReceived(data: ByteArray, offset: Int, length: Int, timestamp: Long) {
// 发送原始H264/H265 NAL单元到解码器
}
override fun onRtspAudioSampleReceived(data: ByteArray, offset: Int, length: Int, timestamp: Long) {
// 发送原始音频到解码器
}
override fun onRtspDisconnected() {
}
override fun onRtspFailedUnauthorized() {
Log.e(TAG, "RTSP failed unauthorized");
}
override fun onRtspFailed(message: String?) {
Log.e(TAG, "RTSP failed with message '$message'")
}
}
val uri = Uri.parse("rtsp://192.168.43.23:554/ch01.264?dev=1")
val username = "admin"
val password = ""
val stopped = new AtomicBoolean(false)
val socket: Socket = NetUtils.createSocketAndConnect(uri.host.toString(), port, 5000)
val rtspClient = RtspClient.Builder(socket, uri.toString(), stopped, rtspClientListener)
.requestVideo(true)
.requestAudio(true)
.withDebug(false)
.withUserAgent("RTSP client")
.withCredentials(username, password)