sammy44nts/rtmp-rtsp-stream-client-java


Library to stream in rtmp and rtsp for Android. All code in Java

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.sammy44nts:rtmp-rtsp-stream-client-java:1.3.1'
	}
	dependencies {
		implementation("com.github.sammy44nts:rtmp-rtsp-stream-client-java:1.3.1")
	}
	<dependency>
	    <groupId>com.github.sammy44nts</groupId>
	    <artifactId>rtmp-rtsp-stream-client-java</artifactId>
	    <version>1.3.1</version>
	</dependency>

                            
    libraryDependencies += "com.github.sammy44nts" % "rtmp-rtsp-stream-client-java" % "1.3.1"
        
        

                            
    :dependencies [[com.github.sammy44nts/rtmp-rtsp-stream-client-java "1.3.1"]]
        
        

Readme


rtmp-rtsp-stream-client-java

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:

<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" />

Compile

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

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

Features:

  • [x] Android min API 16.
  • [x] Support camera1 and camera2 API
  • [x] Encoder type buffer to buffer.
  • [x] Encoder type surface to buffer.
  • [x] RTMP/RTSP auth wowza.
  • [x] Audio mode suppressor.
  • [x] Audio echo cancellation.
  • [x] Disable/Enable video and audio while streaming.
  • [x] Switch camera while streaming.
  • [x] Change video bitrate while streaming (API 19+).
  • [X] Record MP4 file while streaming (API 18+).
  • [x] H264 and AAC hardware encoding.
  • [x] RTSP TCP/UDP.
  • [x] Stream from MP4 file (only video, no sound, API 18+).
  • [x] Stream device display(API 21+).
  • [X] Set Image, Gif or Text to stream on real time.
  • [X] RTMPS and RTSPS

Backlog

  • H265 support

Use example:

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

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();

RTSP:


//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();