Android rtmp和rtsp流的库, 都是Java代码

・6 分钟阅读

  • 源代码名称: rtmp-rtsp-stream-client-java
  • 源代码网址: https://www.github.com/pedroSG94/rtmp-rtsp-stream-client-java
  • rtmp-rtsp-stream-client-java的文档
  • rtmp-rtsp-stream-client-java的源代码下载
  • Git URL:
    git://www.github.com/pedroSG94/rtmp-rtsp-stream-client-java.git
  • Git Clone代码到本地:
    git clone https://www.github.com/pedroSG94/rtmp-rtsp-stream-client-java
  • Subversion代码到本地:
    $ svn co --depth empty https://www.github.com/pedroSG94/rtmp-rtsp-stream-client-java
                              Checked out revision 1.
                              $ cd repo
                              $ svn up trunk
              
  • rtmp-rtsp-stream-client-java

    Android ArsenalRelease

    用于RTMP和RTSP流的库, 所有代码都是Java。

    如果你需要播放器,请查看这个项目:

    https://github.com/pedroSG94/vlc-example-streamplayer

    维基

    https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/wiki

    权限:

    
    
    
    
    <uses-permission android:name="android.permission.INTERNET"/>
    
    
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    
    
    <uses-permission android:name="android.permission.CAMERA"/>
    
    
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
    
    <!--some devices need it-->
    
    
    <uses-feature android:name="android.hardware.camera"/>
    
    
    <uses-feature android:name="android.hardware.camera2.full"/>
    
    
    <uses-feature android:name="android.hardware.camera2.autofocus"/>
    
    
    
    

    编译

    要在你的项目中将这里库使用 gradle,请将它的添加到你的build.gradle 中:

    
    
    
    
    allprojects {
    
    
     repositories {
    
    
     maven { url 'https://jitpack.io' }
    
    
     }
    
    
    }
    
    
    dependencies {
    
    
     compile 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:1.3.9'
    
    
    }
    
    
    
    
    

    插件功能:

    • Android min API 16.
    • 支持 camera1camera2 API
    • 编码器类型缓冲区到缓冲区。
    • 编码器类型表面缓冲。
    • rtmp/rtsp wowza认证 。
    • 音频模式抑制器。
    • 音频回声消除。
    • 播放时禁用/启用视频和音频。
    • 流式传输时切换相机。
    • 在流媒体( API 19 + ) 中更改视频比特率。
    • 获取上传带宽。
    • 在流式传输时记录MP4文件(API 18)。
    • H264和AAC硬件编码。
    • 强制H264和AAC编解码器硬件/软件编码(不推荐)。
    • RTSP/udp。
    • 从视频文件流式传输,如mp4,webm等(受设备解码器限制)。 更多信息。
    • 流设备显示(API 21)。
    • 设置图像,Gif或文本以实时流式传输。
    • OpenGL实时过滤器。更多信息
    • RTMPS和 RTSPS

    Backlog

    • 支持 H265

    示例:

    这里代码是一个基本示例。 我建议你去app模块中的Activities,看看所有的例子。

    用户定义的RTMP:

    
    
    
    
    //default
    
    
    
    //create builder
    
    
    RtmpCamera1 rtmpCamera1 = new RtmpCamera1(surfaceView, connectCheckerRtmp);
    
    
    //start stream
    
    
    if (rtmpCamera1.prepareAudio() && rtmpCamera1.prepareVideo()) {
    
    
     rtmpCamera1.startStream("rtmp://yourEndPoint");
    
    
    } else {
    
    
     /**This device cant init encoders, this could be for 2 reasons: The encoder selected doesnt support any configuration setted or your device hasnt a H264 or AAC encoder (in this case you can see log error valid encoder not found)*/
    
    
    }
    
    
    //stop stream
    
    
    rtmpCamera1.stopStream();
    
    
    
    //with params
    
    
    
    //create builder
    
    
    RtmpCamera1 rtmpCamera1 = new RtmpCamera1(surfaceView, connectCheckerRtmp);
    
    
    //start stream
    
    
    if (rtmpCamera1.prepareAudio(int bitrate, int sampleRate, boolean isStereo, boolean echoCanceler,
    
    
     boolean noiseSuppressor) && rtmpCamera1.prepareVideo(int width, int height, int fps, int bitrate, boolean hardwareRotation, int rotation)) {
    
    
     rtmpCamera1.startStream("rtmp://yourEndPoint");
    
    
    } else {
    
    
     /**This device cant init encoders, this could be for 2 reasons: The encoder selected doesnt support any configuration setted or your device hasnt a H264 or AAC encoder (in this case you can see log error valid encoder not found)*/
    
    
    }
    
    
    //stop stream
    
    
    rtmpCamera1.stopStream();
    
    
    
    
    

    :

    
    
    
    
    //default
    
    
    
    //create builder
    
    
    //by default TCP protocol.
    
    
    RtspCamera1 rtspCamera1 = new RtspCamera1(surfaceView, connectCheckerRtsp);
    
    
    //start stream
    
    
    if (rtspCamera1.prepareAudio() && rtspCamera1.prepareVideo()) {
    
    
     rtspCamera1.startStream("rtsp://yourEndPoint");
    
    
    } else {
    
    
     /**This device cant init encoders, this could be for 2 reasons: The encoder selected doesnt support any configuration setted or your device hasnt a H264 or AAC encoder (in this case you can see log error valid encoder not found)*/
    
    
    }
    
    
    //stop stream
    
    
    rtspCamera1.stopStream();
    
    
    
    //with params
    
    
    
    //create builder
    
    
    RtspCamera1 rtspCamera1 = new RtspCamera1(surfaceView, connectCheckerRtsp);
    
    
    rtspCamera1.setProtocol(protocol);
    
    
    //start stream
    
    
    if (rtspCamera1.prepareAudio(int bitrate, int sampleRate, boolean isStereo, boolean echoCanceler,
    
    
     boolean noiseSuppressor) && rtspCamera1.prepareVideo(int width, int height, int fps, int bitrate, boolean hardwareRotation, int rotation)) {
    
    
     rtspCamera1.startStream("rtsp://yourEndPoint");
    
    
    } else {
    
    
     /**This device cant init encoders, this could be for 2 reasons: The encoder selected doesnt support any configuration setted or your device hasnt a H264 or AAC encoder (in this case you can see log error valid encoder not found)*/
    
    
    }
    
    
    //stop stream
    
    
    rtspCamera1.stopStream();
    
    
    
    
    
    讨论
    Fansisi profile image