自学内容网 自学内容网

从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)
    

原文地址:https://blog.csdn.net/WriteBug001/article/details/142329520

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!