RTSP播放器网页web无插件直播流媒体音视频播放器EasyPlayer-RTSP-Android解码获取视频帧的方法

应用场景

EasyPlayer-RTSP在多年与VLC的对标过程中,积累了广泛的应用场景,EasyPlayer-RTSP底层与上层全部自主开发,自主知识产权,可实战测试。

EasyPlayer-RTSP播放器

EasyPlayer-RTSP播放器是一套RTSP专用的播放器,包括有:Windows(支持IE插件,npapi插件)、Android、iOS三个平台,是由青犀TSINGSEE开放平台开发和维护的区别于市面上大部分的通用播放器,EasyPlayer-RTSP系列从2014年初发展至今得到了各行各业(尤其是安防行业)的广泛应用,其主要原因是EasyPlayer-RTSP更加精炼、更加专注,具备非常低的延时,非常高RTSP协议兼容性,编码数据解析等方面,都有非常大的优势。

EasyPlayer-RTSP-Android解码获取视频帧

提出问题

EasyPlayer-RTSP-Android如何获取解码后的视频帧?

分析问题

有的客户需要拿到解码后的视频帧,用来实现人脸识别。

解决问题

视频播放的实现在PlayFragment.java中,其中有一个子类YUVExportFragment.java,实现了接口EasyPlayerClient.I420DataCallback,在onI420Data方法中可以拿到解码后的视频帧:

深入阅读代码,会发现在EasyPlayerClient.java中,硬解码和软解码的方式,都将解码后的视频帧传入onI420Data了:

ByteBuffer buf = mDecoder.decodeFrameYUV(frameInfo, size);
if (i420callback != null && buf != null)
    i420callback.onI420Data(buf);
if (buf != null)
    mDecoder.releaseBuffer(buf);
ByteBuffer outputBuffer;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    outputBuffer = mCodec.getOutputBuffer(index);
} else {
    outputBuffer = mCodec.getOutputBuffers()[index];
}
if (i420callback != null && outputBuffer != null) {
    if (sliceHeight != realHeight) {
        ByteBuffer tmp = ByteBuffer.allocateDirect(realWidth*realHeight*3/2);
        outputBuffer.clear();
        outputBuffer.limit(realWidth*realHeight);
        tmp.put(outputBuffer);

        outputBuffer.clear();
        outputBuffer.position(realWidth * sliceHeight);
        outputBuffer.limit((realWidth * sliceHeight + realWidth*realHeight /4));
        tmp.put(outputBuffer);

        outputBuffer.clear();
        outputBuffer.position(realWidth * sliceHeight + realWidth*realHeight/4);
        outputBuffer.limit((realWidth * sliceHeight + realWidth*realHeight/4 + realWidth*realHeight /4));
        tmp.put(outputBuffer);

        tmp.clear();
        outputBuffer = tmp;
    }

if (mColorFormat == COLOR_FormatYUV420SemiPlanar 
        || mColorFormat == COLOR_FormatYUV420PackedSemiPlanar
        || mColorFormat == COLOR_TI_FormatYUV420PackedSemiPlanar) {
        JNIUtil.yuvConvert2(outputBuffer, realWidth, realHeight, 4);
}
i420callback.onI420Data(outputBuffer);
}
发布了59 篇原创文章 · 获赞 0 · 访问量 3772

猜你喜欢

转载自blog.csdn.net/weixin_43194037/article/details/103873439