Library to stream in rtmp and rtsp for Android. All code in Java。Android:搭建开源的RTSP服务器,Android推流,VLC播放
AndroidStudio3.0+
gradle:4.6+
Android 10 API29
试着搭建RTSP直播的框架,发现可参考RTSP的直播框架很少。
一开始以为live55可以的,但最后发现这个框架只支持播放本地文件,虽然可以定制,但是明显有点麻烦。
后来又看vlc,发现搭建都是用图形界面的,而且推流的资料很少。
还有苹果的Darwin,资料更是少得可怜。
主要是现在貌似直播都是用RTMP,RTSP的框架基本没有
考虑到开源编译定制,后面选择了下面的搭配:
服务端:https://github.com/EasyDarwin/EasyDarwin
推流端:https://github.com/maiduoduo/Android-client-rtmp-rtsp-stream
客户端:VLC
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
https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/wiki
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO" ></uses-permission>
<uses-permission android:name="android.permission.CAMERA" ></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>
<!--Optional for play store-->
<uses-feature android:name="android.hardware.camera" android:required="false" ></uses-feature>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" ></uses-feature>
To use this library in your project with gradle add this to your build.gradle:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:1.8.3'
}
https://github.com/pedroSG94/RTSP-Server
https://github.com/pedroSG94/AndroidReStreamer
https://github.com/pedroSG94/Stream-USB-test
This code is a basic example.
I recommend you go to Activities in app module and see all examples.
//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();