Android平台RTMP推流或轻量级RTSP服务(摄像头或同屏)编码前数据接入类型总结

很多开发者在做Android平台RTMP推流或轻量级RTSP服务(摄像头或同屏)时,总感觉接口不够用,以大牛直播SDK为例 (Github) 我们来总结下,我们常规需要支持的编码前音视频数据有哪些类型:

1. Android摄像头前后camera通过OnPreviewFrame()回调的数据接口:

    @Overridepublic void onPreviewFrame(byte[] data, Camera camera) {frameCount++;if (frameCount % 3000 == 0) {Log.i("OnPre", "gc+");System.gc();Log.i("OnPre", "gc-");}if (data == null) {Parameters params = camera.getParameters();Size size = params.getPreviewSize();int bufferSize = (((size.width | 0x1f) + 1) * size.height * ImageFormat.getBitsPerPixel(params.getPreviewFormat())) / 8;camera.addCallbackBuffer(new byte[bufferSize]);} else {if (isRTSPPublisherRunning || isPushingRtmp || isRecording || isPushingRtsp) {libPublisher.SmartPublisherOnCaptureVideoData(publisherHandle, data, data.length, currentCameraType, currentOrigentation);}camera.addCallbackBuffer(data);}}

 对应接口定义:

/*** Set live video data(no encoded data).** @param cameraType: CAMERA_FACING_BACK with 0, CAMERA_FACING_FRONT with 1* * @param curOrg:* PORTRAIT = 1;    //竖屏* LANDSCAPE = 2;    //横屏 home键在右边的情况* LANDSCAPE_LEFT_HOME_KEY = 3; //横屏 home键在左边的情况** @return {0} if successful*/public native int SmartPublisherOnCaptureVideoData(long handle, byte[] data, int len, int cameraType, int curOrg);

2. 部分定制设备,只支持YV12的数据:

    /*** YV12数据接口** @param data: YV12 data** @param width: 图像宽** @param height: 图像高** @param y_stride:  y面步长** @param v_stride: v面步长** @param u_stride: u面步长** rotation_degree: 顺时针旋转, 必须是0, 90, 180, 270** @return {0} if successful*/public native int SmartPublisherOnYV12Data(long handle, byte[] data, int width, int height, int y_stride,  int v_stride, int u_stride, int rotation_degree);

3. 支持NV21数据接口:

nv21数据接口,除了用于常规的camera数据接入外,部分定制摄像头出来的数据发生翻转,这个接口也支持。

    /*** NV21数据接口** @param data: nv21 data** @param len: data length** @param width: 图像宽** @param height: 图像高** @param y_stride:  y面步长** @param uv_stride:  uv面步长** rotation_degree: 顺时针旋转, 必须是0, 90, 180, 270** @return {0} if successful*/public native int SmartPublisherOnNV21Data(long handle, byte[] data, int len, int width, int height, int y_stride,  int uv_stride, int rotation_degree);/*** NV21数据接口** @param data: nv21 data** @param len: data length** @param width: 图像宽** @param height: 图像高** @param y_stride:  y面步长** @param uv_stride:  uv面步长** rotation_degree: 顺时针旋转, 必须是0, 90, 180, 270** @param  is_vertical_flip: 是否垂直翻转, 0不翻转, 1翻转** @param  is_horizontal_flip:是否水平翻转, 0不翻转, 1翻转** @return {0} if successful*/public native int SmartPublisherOnNV21DataV2(long handle, byte[] data, int len, int width, int height, int y_stride,  int uv_stride, int rotation_degree,int is_vertical_flip, int is_horizontal_flip);

4. 支持YUV数据接入:

    /*** Set live video data(no encoded data).** @param data: I420 data* * @param len: I420 data length* * @param yStride: y stride* * @param uStride: u stride* * @param vStride: v stride** @return {0} if successful*/public native int SmartPublisherOnCaptureVideoI420Data(long handle,  byte[] data, int len, int yStride, int uStride, int vStride);


5. 支持RGBA数据接入(支持裁剪后数据接入,主要用于同屏场景):

    /*** Set live video data(no encoded data).** @param data: RGBA data* * @param rowStride: stride information* * @param width: width* * @param height: height** @return {0} if successful*/public native int SmartPublisherOnCaptureVideoRGBAData(long handle,  ByteBuffer data, int rowStride, int width, int height);/*** 投递裁剪过的RGBA数据** @param data: RGBA data** @param rowStride: stride information** @param width: width** @param height: height** @param clipedLeft: 左;  clipedTop: 上; clipedwidth: 裁剪后的宽; clipedHeight: 裁剪后的高; 确保传下去裁剪后的宽、高均为偶数** @return {0} if successful*/public native int SmartPublisherOnCaptureVideoClipedRGBAData(long handle,  ByteBuffer data, int rowStride, int width, int height, int clipedLeft, int clipedTop, int clipedWidth, int clipedHeight);/*** Set live video data(no encoded data).** @param data: ABGR flip vertical(垂直翻转) data** @param rowStride: stride information** @param width: width** @param height: height** @return {0} if successful*/public native int SmartPublisherOnCaptureVideoABGRFlipVerticalData(long handle,  ByteBuffer data, int rowStride, int width, int height);

6. 支持RGB565数据接入(主要用于同屏场景):

    /*** Set live video data(no encoded data).** @param data: RGB565 data** @param row_stride: stride information** @param width: width** @param height: height** @return {0} if successful*/public native int SmartPublisherOnCaptureVideoRGB565Data(long handle,ByteBuffer data, int row_stride, int width, int height);

7. 支持camera数据接入(主要用于camera2接口对接):
    

/**  专门为android.media.Image的android.graphics.ImageFormat.YUV_420_888格式提供的接口** @param  width: 必须是8的倍数** @param  height: 必须是8的倍数** @param  crop_left: 剪切左上角水平坐标, 一般根据android.media.Image.getCropRect() 填充** @param  crop_top: 剪切左上角垂直坐标, 一般根据android.media.Image.getCropRect() 填充** @param  crop_width: 必须是8的倍数, 填0将忽略这个参数, 一般根据android.media.Image.getCropRect() 填充** @param  crop_height: 必须是8的倍数, 填0将忽略这个参数,一般根据android.media.Image.getCropRect() 填充** @param y_plane 对应android.media.Image.Plane[0].getBuffer()** @param y_row_stride 对应android.media.Image.Plane[0].getRowStride()** @param u_plane 对应android.media.Image.Plane[1].getBuffer()** @param v_plane 对应android.media.Image.Plane[2].getBuffer()** @param uv_row_stride 对应android.media.Image.Plane[1].getRowStride()** @param uv_pixel_stride 对应android.media.Image.Plane[1].getPixelStride()** @param  rotation_degree: 顺时针旋转, 必须是0, 90, 180, 270** @param  is_vertical_flip: 是否垂直翻转, 0不翻转, 1翻转** @param  is_horizontal_flip:是否水平翻转, 0不翻转, 1翻转** @param  scale_width: 缩放宽,必须是8的倍数, 0不缩放** @param  scale_height: 缩放高, 必须是8的倍数, 0不缩放** @param  scale_filter_mode: 缩放质量, 范围必须是[1,3], 传0使用默认速度** @return {0} if successful*/public native int SmartPublisherOnImageYUV420888(long handle, int width, int height,int crop_left, int crop_top, int crop_width, int crop_height,ByteBuffer y_plane, int y_row_stride,ByteBuffer u_plane, ByteBuffer v_plane, int uv_row_stride, int uv_pixel_stride,int rotation_degree, int is_vertical_flip, int is_horizontal_flip,int scale_width, int scale_height, int scale_filter_mode);

8. 支持PCM数据接入:
 

    /*** 传递PCM音频数据给SDK, 每10ms音频数据传入一次* *  @param pcmdata: pcm数据, 需要使用ByteBuffer.allocateDirect分配, ByteBuffer.isDirect()是true的才行.*  @param size: pcm数据大小*  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}, 推荐44100*  @param channel: 通道, 当前通道支持单通道(1)和双通道(2),推荐单通道(1)*  @param per_channel_sample_number: 这个请传入的是 sample_rate/100*/public native int SmartPublisherOnPCMData(long handle, ByteBuffer pcmdata, int size, int sample_rate, int channel, int per_channel_sample_number);/*** 传递PCM音频数据给SDK, 每10ms音频数据传入一次**  @param pcmdata: pcm数据, 需要使用ByteBuffer.allocateDirect分配, ByteBuffer.isDirect()是true的才行.*  @param offset: pcmdata的偏移*  @param size: pcm数据大小*  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}, 推荐44100*  @param channel: 通道, 当前通道支持单通道(1)和双通道(2),推荐单通道(1)*  @param per_channel_sample_number: 这个请传入的是 sample_rate/100*/public native int SmartPublisherOnPCMDataV2(long handle, ByteBuffer pcmdata, int offset, int size, int sample_rate, int channel, int per_channel_sample_number);/*** 传递PCM音频数据给SDK, 每10ms音频数据传入一次**  @param pcm_short_array: pcm数据, short是native endian order*  @param offset: 数组偏移*  @param len: 数组项数*  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}, 推荐44100*  @param channel: 通道, 当前通道支持单通道(1)和双通道(2),推荐单通道(1)*  @param per_channel_sample_number: 这个请传入的是 sample_rate/100*/public native int SmartPublisherOnPCMShortArray(long handle, short[] pcm_short_array, int offset, int len, int sample_rate, int channel, int per_channel_sample_number);

9. 支持远端PCM数据接入和混音后PCM数据接入(主要用于一对一互动):    

/*** Set far end pcm data* * @param pcmdata : 16bit pcm data* @param sampleRate: audio sample rate* @param channel: auido channel* @param per_channel_sample_number: per channel sample numbers* @param is_low_latency: if with 0, it is not low_latency, if with 1, it is low_latency* @return {0} if successful*/public native int SmartPublisherOnFarEndPCMData(long handle,  ByteBuffer pcmdata, int sampleRate, int channel, int per_channel_sample_number, int is_low_latency);/*** 传递PCM混音音频数据给SDK, 每10ms音频数据传入一次**  @param stream_index: 当前只能传1, 传其他返回错误*  @param pcm_data: pcm数据, 需要使用ByteBuffer.allocateDirect分配, ByteBuffer.isDirect()是true的才行.*  @param offset: pcmdata的偏移*  @param size: pcm数据大小*  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}*  @param channels: 通道, 当前通道支持单通道(1)和双通道(2)*  @param per_channel_sample_number: 这个请传入的是 sample_rate/100*/public native int SmartPublisherOnMixPCMData(long handle, int stream_index, ByteBuffer pcm_data, int offset, int size, int sample_rate, int channels, int per_channel_sample_number);/*** 传递PCM混音音频数据给SDK, 每10ms音频数据传入一次**  @param stream_index: 当前只能传1, 传其他返回错误*  @param pcm_short_array: pcm数据, short是native endian order*  @param offset: 数组偏移*  @param len: 数组项数*  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}*  @param channels: 通道, 当前通道支持单通道(1)和双通道(2)*  @param per_channel_sample_number: 这个请传入的是 sample_rate/100*/public native int SmartPublisherOnMixPCMShortArray(long handle, int stream_index, short[] pcm_short_array, int offset, int len, int sample_rate, int channels, int per_channel_sample_number);

总结:

以上只是编码前数据接口,一个产品如果想做的足够通用,需要对接的太多了,你觉得呢?

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/553114.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

作业帮口算批改怎么开 作业帮口算批改如何用

作业帮口算批改功能怎么用?作业帮最近全新改版的消息传的很火,新增了口算批改的功能,很吸引人。但是还有很多用户不是很清楚作业帮口算批改功能怎么用,下面是小编整理的关于作业帮口算批改功能怎么用的相关资讯,快来看看吧! 作业…

RTSP播放器或RTMP播放器常用的事件回调设计

很多开发者在开发RTSP或RTMP播放器的时候,不晓得哪些event回调事件是有意义的,针对此,我们以大牛直播SDK(github)的Android平台RTSP/RTMP直播播放端为例,简单介绍下常用的event id,总的来说&…

Windows平台RTMP多实例推送探讨

之前,我们博客 https://blog.csdn.net/renhui1112/article/details/105624392 提到,Android平台RTMP多实例推送的几种情况探讨,简单来说有以下三种情况: 多路编码,多个实例分别推送到不同的RTMP URL(如And…

Win7蓝屏代码0x000000001e怎么解决

蓝屏问题,是所有系统都会遇到的最普遍的电脑故障问题,电脑蓝屏是因为系统与硬件或软件不兼容冲突引起的,不同的提示代码表示了不同的蓝屏原因,那么Win7蓝屏代码0x000000001e怎么解决?为此问题困扰的用户,请来看看Win7…

开发个好的RTMP播放器到底难在哪里?RTMP播放器对标和考察指标

好多开发者提到,RTMP播放器,不知道有哪些对标和考察指标,以下大概聊聊我们的一点经验,感兴趣的,可以关注 github: 1. 低延迟:大多数RTMP的播放都面向直播场景,如果延迟过大&#xf…

Android平台RTMP/RTSP播放器开发系列之解码和绘制

本文主要抛砖引玉,粗略介绍下Android平台RTMP/RTSP播放器中解码和绘制相关的部分(Github)。 解码 提到解码,大家都知道软硬解,甚至一些公司觉得硬解码已经足够通用,慢慢抛弃软解了,如果考虑到设备匹配,软…

Win7图片查看器打印不了图片怎么办

当我们想浏览电脑中的图片文件时,可以选择系统自带的图片查看器或者第三方看图工具打开,但是有些win7用户发现自己想通过windows图片查看器打印图片却没有反应,Win7图片查看器打印不了图片怎么办?就此剖,下面小编就来教教大家解决…

Android平台屏幕/摄像头或外部数据采集及RTMP推送接口设计描述

好多开发者提到,为什么大牛直播SDK的Android平台RTMP推送接口怎么这么多?不像一些开源或者商业RTMP推送一样,就几个接口,简单明了。 不解释,以Android平台RTMP推送模块常用接口,看看这些接口有没有存在的意…

钉钉怎么设置考勤打卡规则

1、首先在电脑上登陆钉钉后台,然后点击如图所示的钉钉考勤打卡 钉钉后怎么设置考勤打卡规则? 2、比如一个公司生产型企业 互联网部门上班时间是 周一到周五上班时间 8:30-5:30 周六上班 8:30-12:00 以此作为案例说明 钉钉后怎么设置考勤打卡规则? 3、首先设…

变废为宝:使用废旧手机实现实时监控方案

随着手机淘汰的速度越来越快,大多数手机功能性能很强劲就不再使用了,以大牛直播SDK现有方案为例,本文探讨下,如何用废旧手机实现实时监控方案(把手机当摄像头做监控之用): 本方案需要准备一个手…

企业微信登录不了怎么办 企业微信无法登录的原因及解决方法

企业微信无法登陆怎么办?企业微信为什么登陆不了?应该怎么解决?企业微信一个很好用的基础办公沟通工具,现在很多朋友都在使用。那么,如果遇到企业微信登不上的情况应该怎么办呢?接下来小编就给大家带来企业微信无法登录的原因及解决方法,…

RTSP鉴权认证之基础认证和摘要认证

RTSP认证类型 基本认证(basic authentication):http 1.0提出的认证方案,其消息传输不经过加密转换因此存在严重的安全隐患;摘要认证(digest authentication):http 1.1提出的基本认证…

播放器之争:VLC VS SmartPlayer

好多开发者跟我们交流的时候提到,为什么有了VLC这种开源播放器,大牛直播SDK还要开发SmartPlayer?以下就针对VLC和SmartPlayer功能支持和涉及侧重,做个大概的比较: VLC VLC的全名是Video Lan Client,是一个…

网易邮箱大师如何屏蔽邮件 屏蔽垃圾邮件的方法步骤

网易邮箱大师是我们日常使用邮箱的好帮手,但是如果频频收到垃圾邮件而不知道怎么屏蔽,相信大家一定会非常烦恼,这就是今天这篇文章主要讲的内容,那么一起跟着小编往下面看看吧。 操作步骤如下: 1、打开网易邮箱大师&…

Windows平台摄像头或屏幕RTMP推送:OBS VS SmartPublisher

好多开发者问道,既然有了OBS,你们为什么还要开发SmartPublisher? 的确,在我们进行Windows平台RTMP推送模块开发之前,市面上为数不多的Windows平台RTMP推流工具当属OBS了,不得不说,OBS是一款很好…

微信公众号怎么快速导出一个月的文章数据

运营微信公众号肯定要分析文章数据,该怎么一次性导出历史文章数据呢?下面我们就来看看详细的教程。 1、在电脑上登录你的微信公众号,看到这样的页面,然后一直往下拉 微信公众号怎么快速导出一个月的文章数据? 2、在左侧导航栏的统计里面…

轻量级RTSP服务和内置RTSP网关的区别和联系

好多开发者疑惑,什么是内置RTSP网关,和轻量级RTSP服务又有什么区别和联系?本文就以上问题,做个简单的介绍: 轻量级RTSP服务 为满足内网无纸化/电子教室等内网超低延迟需求,避免让用户配置单独的服务器&am…

RTMP/RTSP推送端和RTMP/RTSP播放端录像设计探讨

好多开发者认为,无论是RTSP/RTMP推送端还是RTSP/RTMP播放端,涉及到录像,只要2个接口足矣:开始录像、停止录像。 实际场景下,一个好的录像模块,2个接口远远不够, 本文以大牛直播SDK(…

Win7提示文件太大无法放入回收站怎么办

我们经常会将没有的文件拖到回收站去,但是有时候会遇到文件拖进回收站时,系统提示该文件太大无法放进回收站,那么Win7提示文件太大无法放入回收站怎么办呢?今天小编就跟大家分享Win7系统提示文件太大无法放入回收站的解决方法。 Win7提示文…

内网无纸化会议/智慧教室实时同屏RTSP组播技术方案思考

内网环境下,为了满足内网无纸化/电子教室等内网超低延迟需求,避免让用户配置单独的服务器,好多开发者希望有RTSP的技术方案,用于小并发场景,特别是在组网环境好的有线环境下,使用RTSP服务配合组播&#xff…