项目作者: maiduoduo

项目描述 :
Library to stream in rtmp and rtsp for Android. All code in Java。Android:搭建开源的RTSP服务器,Android推流,VLC播放
高级语言: Java
项目地址: git://github.com/maiduoduo/Android-client-rtmp-rtsp-stream.git
创建时间: 2020-06-15T08:34:42Z
项目社区:https://github.com/maiduoduo/Android-client-rtmp-rtsp-stream

开源协议:Apache License 2.0

下载


Android-client-rtmp-rtsp-stream

运行测试环境(成功编译)

  • AndroidStudio3.0+

    gradle:4.6+

  • Android 10 API29

一.RTSP框架似乎很少

试着搭建RTSP直播的框架,发现可参考RTSP的直播框架很少。
一开始以为live55可以的,但最后发现这个框架只支持播放本地文件,虽然可以定制,但是明显有点麻烦。
后来又看vlc,发现搭建都是用图形界面的,而且推流的资料很少。
还有苹果的Darwin,资料更是少得可怜。
主要是现在貌似直播都是用RTMP,RTSP的框架基本没有

二.最终结果

考虑到开源编译定制,后面选择了下面的搭配:

服务端:https://github.com/EasyDarwin/EasyDarwin

推流端:https://github.com/maiduoduo/Android-client-rtmp-rtsp-stream

客户端:VLC

Android Arsenal
Release

Library for stream in RTMP and RTSP. All code in Java.

If you need a player see this project:

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

Wiki

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

Permissions:

  1. <uses-permission android:name="android.permission.INTERNET" ></uses-permission>
  2. <uses-permission android:name="android.permission.RECORD_AUDIO" ></uses-permission>
  3. <uses-permission android:name="android.permission.CAMERA" ></uses-permission>
  4. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>
  5. <!--Optional for play store-->
  6. <uses-feature android:name="android.hardware.camera" android:required="false" ></uses-feature>
  7. <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" ></uses-feature>

Compile

To use this library in your project with gradle add this to your build.gradle:

  1. allprojects {
  2. repositories {
  3. maven { url 'https://jitpack.io' }
  4. }
  5. }
  6. dependencies {
  7. implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:1.8.3'
  8. }

Features:

  • Android min API 16.
  • Support camera1 and camera2 API
  • Encoder type buffer to buffer.
  • Encoder type surface to buffer.
  • RTMP/RTSP auth.
  • Audio noise suppressor.
  • Audio echo cancellation.
  • Disable/Enable video and audio while streaming.
  • Switch camera while streaming.
  • Change video bitrate while streaming (API 19+).
  • [X] Get upload bandwidth used.
  • [X] Record MP4 file while streaming (API 18+).
  • H264, H265 and AAC hardware encoding.
  • Force H264 and AAC Codec hardware/software encoding (Not recommended).
  • RTSP TCP/UDP.
  • Stream from video files like mp4, webm, etc (Limited by device decoders). More info
  • Stream device display(API 21+).
  • [X] Set Image, Gif or Text to stream on real time.
  • [X] OpenGL real time filters. More info
  • [X] RTMPS and RTSPS
  • [X] RTSP H265 support (Waiting FLV official packetization to add RTMP support).

https://github.com/pedroSG94/RTSP-Server

https://github.com/pedroSG94/AndroidReStreamer

https://github.com/pedroSG94/Stream-USB-test

Use example:

This code is a basic example.
I recommend you go to Activities in app module and see all examples.

RTMP:

  1. //default
  2. //create builder
  3. RtmpCamera1 rtmpCamera1 = new RtmpCamera1(surfaceView, connectCheckerRtmp);
  4. //start stream
  5. if (rtmpCamera1.prepareAudio() && rtmpCamera1.prepareVideo()) {
  6. rtmpCamera1.startStream("rtmp://yourEndPoint");
  7. } else {
  8. /**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)*/
  9. }
  10. //stop stream
  11. rtmpCamera1.stopStream();
  12. //with params
  13. //create builder
  14. RtmpCamera1 rtmpCamera1 = new RtmpCamera1(surfaceView, connectCheckerRtmp);
  15. //start stream
  16. if (rtmpCamera1.prepareAudio(int bitrate, int sampleRate, boolean isStereo, boolean echoCanceler,
  17. boolean noiseSuppressor) && rtmpCamera1.prepareVideo(int width, int height, int fps, int bitrate, boolean hardwareRotation, int rotation)) {
  18. rtmpCamera1.startStream("rtmp://yourEndPoint");
  19. } else {
  20. /**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)*/
  21. }
  22. //stop stream
  23. rtmpCamera1.stopStream();

RTSP:

  1. //default
  2. //create builder
  3. //by default TCP protocol.
  4. RtspCamera1 rtspCamera1 = new RtspCamera1(surfaceView, connectCheckerRtsp);
  5. //start stream
  6. if (rtspCamera1.prepareAudio() && rtspCamera1.prepareVideo()) {
  7. rtspCamera1.startStream("rtsp://yourEndPoint");
  8. } else {
  9. /**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)*/
  10. }
  11. //stop stream
  12. rtspCamera1.stopStream();
  13. //with params
  14. //create builder
  15. RtspCamera1 rtspCamera1 = new RtspCamera1(surfaceView, connectCheckerRtsp);
  16. rtspCamera1.setProtocol(protocol);
  17. //start stream
  18. if (rtspCamera1.prepareAudio(int bitrate, int sampleRate, boolean isStereo, boolean echoCanceler,
  19. boolean noiseSuppressor) && rtspCamera1.prepareVideo(int width, int height, int fps, int bitrate, boolean hardwareRotation, int rotation)) {
  20. rtspCamera1.startStream("rtsp://yourEndPoint");
  21. } else {
  22. /**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)*/
  23. }
  24. //stop stream
  25. rtspCamera1.stopStream();

来源于

pedroSG94