├── .DS_Store ├── .gitignore ├── README.md ├── libvlc-3.0.0-null.aar └── vlcdemo ├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── libs │ └── libvlc-3.0.0-null.aar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── frank │ │ └── vlcdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── frank │ │ │ └── vlcdemo │ │ │ ├── MainActivity.java │ │ │ ├── MyApplication.java │ │ │ ├── RtspHelper.java │ │ │ └── RtspSurfaceRender.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── frank │ └── vlcdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── inuker │ │ └── library │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── inuker │ │ │ └── library │ │ │ ├── BitmapUtils.java │ │ │ ├── MyContext.java │ │ │ ├── RGBProgram.java │ │ │ ├── ResourceUtils.java │ │ │ ├── ShaderHelper.java │ │ │ ├── ShaderProgram.java │ │ │ ├── Task.java │ │ │ ├── TaskUtils.java │ │ │ ├── encoder │ │ │ ├── AndroidMuxer.java │ │ │ ├── AudioEncoderCore.java │ │ │ ├── BaseMovieEncoder.java │ │ │ ├── CameraHelper.java │ │ │ ├── EglCore.java │ │ │ ├── EglSurfaceBase.java │ │ │ ├── GlUtil.java │ │ │ ├── MediaEncoderCore.java │ │ │ ├── MovieEncoder1.java │ │ │ ├── VideoEncoderCore.java │ │ │ ├── WindowSurface.java │ │ │ └── YUVProgram.java │ │ │ └── utils │ │ │ ├── ImageUtils.java │ │ │ ├── LogUtils.java │ │ │ └── MD5Utils.java │ └── res │ │ ├── raw │ │ ├── rect_fragment.glsl │ │ ├── rect_vertex.glsl │ │ ├── rgb_fragment.glsl │ │ ├── rgb_vertex.glsl │ │ ├── tex_fragment.glsl │ │ ├── tex_vertex.glsl │ │ ├── yuv_fragment.glsl │ │ └── yuv_vertex.glsl │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── inuker │ └── library │ └── ExampleUnitTest.java └── settings.gradle /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingjikerbo/Android-RTSP/2c5feea369a3b4bbbfe27dd385a17a3ee3cc7800/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /.idea 4 | /vlcdemo/.idea/ 5 | /local.properties 6 | /.idea/workspace.xml 7 | /.idea/libraries 8 | .DS_Store 9 | /build 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android RTSP Related Demos and Researches 2 | 3 | ### **Support following features:** 4 | 5 | - Capture Screen 6 | - Record Video 7 | - Rotate and Crop Video 8 | - Filter or extra rendering 9 | -------------------------------------------------------------------------------- /libvlc-3.0.0-null.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingjikerbo/Android-RTSP/2c5feea369a3b4bbbfe27dd385a17a3ee3cc7800/libvlc-3.0.0-null.aar -------------------------------------------------------------------------------- /vlcdemo/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /vlcdemo/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /vlcdemo/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /vlcdemo/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /vlcdemo/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /vlcdemo/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /vlcdemo/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /vlcdemo/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /vlcdemo/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.2" 6 | defaultConfig { 7 | applicationId "com.example.frank.vlcdemo" 8 | minSdkVersion 19 9 | targetSdkVersion 21 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | ndk { 15 | abiFilters "armeabi-v7a" 16 | } 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | repositories { 27 | flatDir { 28 | dirs 'libs' 29 | } 30 | } 31 | 32 | dependencies { 33 | compile fileTree(dir: 'libs', include: ['*.jar']) 34 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 35 | exclude group: 'com.android.support', module: 'support-annotations' 36 | }) 37 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 38 | testCompile 'junit:junit:4.12' 39 | 40 | compile(name:'libvlc-3.0.0-null', ext:'aar') 41 | compile project(path: ':library') 42 | } 43 | -------------------------------------------------------------------------------- /vlcdemo/app/libs/libvlc-3.0.0-null.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingjikerbo/Android-RTSP/2c5feea369a3b4bbbfe27dd385a17a3ee3cc7800/vlcdemo/app/libs/libvlc-3.0.0-null.aar -------------------------------------------------------------------------------- /vlcdemo/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/frank/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /vlcdemo/app/src/androidTest/java/com/example/frank/vlcdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.frank.vlcdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.frank.vlcdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vlcdemo/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /vlcdemo/app/src/main/java/com/example/frank/vlcdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.frank.vlcdemo; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Bitmap; 5 | import android.net.Uri; 6 | import android.opengl.GLSurfaceView; 7 | import android.os.Bundle; 8 | import android.util.Log; 9 | import android.view.SurfaceHolder; 10 | import android.view.SurfaceView; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.ImageView; 14 | 15 | import org.videolan.libvlc.IVLCVout; 16 | import org.videolan.libvlc.LibVLC; 17 | import org.videolan.libvlc.Media; 18 | import org.videolan.libvlc.MediaPlayer; 19 | 20 | import java.nio.ByteBuffer; 21 | import java.nio.ByteOrder; 22 | import java.util.ArrayList; 23 | 24 | public class MainActivity extends Activity { 25 | 26 | // public static final String URL = "rtsp://admin:admin123@10.31.11.79:554/cam/realmonitor?channel=1@subtype=0"; 27 | 28 | public static final String URL = "rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov"; 29 | 30 | // public static final String URL = "rtsp://10.31.0.61:8554/test.mkv"; 31 | 32 | private GLSurfaceView mSurfaceView; 33 | private RtspSurfaceRender mRender; 34 | 35 | private Button mButton; 36 | private boolean mRecording; 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.activity_main); 42 | 43 | mSurfaceView = findViewById(R.id.surface); 44 | mSurfaceView.setEGLContextClientVersion(3); 45 | 46 | mRender = new RtspSurfaceRender(mSurfaceView); 47 | mRender.setRtspUrl(URL); 48 | 49 | mButton = findViewById(R.id.btn); 50 | mButton.setOnClickListener(new View.OnClickListener() { 51 | 52 | @Override 53 | public void onClick(View v) { 54 | if (mRecording) { 55 | mButton.setText("start"); 56 | mRender.stopRecording(); 57 | } else { 58 | mButton.setText("stop"); 59 | mRender.startRecording(); 60 | } 61 | mRecording = !mRecording; 62 | } 63 | }); 64 | 65 | mSurfaceView.setRenderer(mRender); 66 | mSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); 67 | } 68 | 69 | @Override 70 | protected void onResume() { 71 | super.onResume(); 72 | mSurfaceView.onResume(); 73 | } 74 | 75 | @Override 76 | protected void onPause() { 77 | super.onPause(); 78 | mSurfaceView.onPause(); 79 | } 80 | 81 | @Override 82 | protected void onDestroy() { 83 | mRender.onSurfaceDestoryed(); 84 | super.onDestroy(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /vlcdemo/app/src/main/java/com/example/frank/vlcdemo/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.frank.vlcdemo; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.inuker.library.MyContext; 7 | 8 | /** 9 | * Created by liwentian on 2017/10/12. 10 | */ 11 | 12 | public class MyApplication extends Application { 13 | 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | MyContext.setContext(this); 18 | } 19 | 20 | public static Context getContext() { 21 | return MyContext.getContext(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /vlcdemo/app/src/main/java/com/example/frank/vlcdemo/RtspHelper.java: -------------------------------------------------------------------------------- 1 | package com.example.frank.vlcdemo; 2 | 3 | import android.net.Uri; 4 | import android.provider.SyncStateContract; 5 | 6 | import org.videolan.libvlc.LibVLC; 7 | import org.videolan.libvlc.Media; 8 | import org.videolan.libvlc.MediaPlayCallback; 9 | import org.videolan.libvlc.MediaPlayer; 10 | 11 | import java.nio.ByteBuffer; 12 | import java.nio.ByteOrder; 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by liwentian on 2017/10/12. 17 | */ 18 | 19 | public class RtspHelper { 20 | 21 | private MediaPlayer mMediaPlayer; 22 | 23 | private LibVLC mVlc; 24 | 25 | private static RtspHelper sInstance = new RtspHelper(); 26 | 27 | private ByteBuffer mByteBuffer; 28 | 29 | public static RtspHelper getInstance() { 30 | return sInstance; 31 | } 32 | 33 | public interface RtspCallback { 34 | void onPreviewFrame(ByteBuffer buffer, int width, int height); 35 | } 36 | 37 | private RtspHelper() { 38 | 39 | } 40 | 41 | public void createPlayer(String url, final int width, final int height, final RtspCallback callback) { 42 | releasePlayer(); 43 | 44 | mByteBuffer = ByteBuffer.allocateDirect(width * height * 4) 45 | .order(ByteOrder.nativeOrder()); 46 | 47 | try { 48 | ArrayList options = new ArrayList(); 49 | options.add("--aout=opensles"); 50 | options.add("--audio-time-stretch"); // time stretching 51 | options.add("-vvv"); // verbosity 52 | mVlc = new LibVLC(MyApplication.getContext(), options); 53 | 54 | // Create media player 55 | mMediaPlayer = new MediaPlayer(mVlc); 56 | mMediaPlayer.setVideoFormat("RGBA", width, height, width * 4); 57 | mMediaPlayer.setVideoCallback(mByteBuffer, new MediaPlayCallback() { 58 | @Override 59 | public void onDisplay(final ByteBuffer byteBuffer) { 60 | callback.onPreviewFrame(byteBuffer, width, height); 61 | } 62 | }); 63 | 64 | Media m = new Media(mVlc, Uri.parse(url)); 65 | int cache = 1500; 66 | m.addOption(":network-caching=" + cache); 67 | m.addOption(":file-caching=" + cache); 68 | m.addOption(":live-cacheing=" + cache); 69 | m.addOption(":sout-mux-caching=" + cache); 70 | m.addOption(":codec=mediacodec,iomx,all"); 71 | mMediaPlayer.setMedia(m); 72 | mMediaPlayer.play(); 73 | } catch (Throwable e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | 78 | public void releasePlayer() { 79 | if (mVlc == null) { 80 | return; 81 | } 82 | 83 | mMediaPlayer.setVideoCallback(null, null); 84 | mMediaPlayer.stop(); 85 | 86 | mVlc.release(); 87 | mVlc = null; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /vlcdemo/app/src/main/java/com/example/frank/vlcdemo/RtspSurfaceRender.java: -------------------------------------------------------------------------------- 1 | package com.example.frank.vlcdemo; 2 | 3 | import android.opengl.EGL14; 4 | import android.opengl.GLSurfaceView; 5 | 6 | import com.inuker.library.RGBProgram; 7 | import com.inuker.library.encoder.BaseMovieEncoder; 8 | import com.inuker.library.encoder.CameraHelper; 9 | import com.inuker.library.encoder.MovieEncoder1; 10 | import com.inuker.library.utils.LogUtils; 11 | 12 | import java.io.File; 13 | import java.nio.ByteBuffer; 14 | import java.nio.ByteOrder; 15 | 16 | import javax.microedition.khronos.egl.EGLConfig; 17 | import javax.microedition.khronos.opengles.GL10; 18 | 19 | import static android.opengl.GLES20.GL_COLOR_BUFFER_BIT; 20 | import static android.opengl.GLES20.GL_DEPTH_BUFFER_BIT; 21 | import static android.opengl.GLES20.glClear; 22 | import static android.opengl.GLES20.glClearColor; 23 | 24 | /** 25 | * Created by liwentian on 2017/10/12. 26 | */ 27 | 28 | public class RtspSurfaceRender implements GLSurfaceView.Renderer, RtspHelper.RtspCallback { 29 | 30 | private ByteBuffer mBuffer; 31 | 32 | private GLSurfaceView mGLSurfaceView; 33 | 34 | private RGBProgram mProgram; 35 | 36 | private String mRtspUrl; 37 | 38 | private BaseMovieEncoder mVideoEncoder; 39 | 40 | public RtspSurfaceRender(GLSurfaceView glSurfaceView) { 41 | mGLSurfaceView = glSurfaceView; 42 | } 43 | 44 | public void setRtspUrl(String url) { 45 | mRtspUrl = url; 46 | } 47 | 48 | @Override 49 | public void onSurfaceCreated(GL10 gl, EGLConfig config) { 50 | } 51 | 52 | public void startRecording() { 53 | mGLSurfaceView.queueEvent(new Runnable() { 54 | @Override 55 | public void run() { 56 | if (!mVideoEncoder.isRecording()) { 57 | File output = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO, ""); 58 | LogUtils.v(String.format("startRecording: %s", output)); 59 | mVideoEncoder.startRecording(new BaseMovieEncoder.EncoderConfig(output, EGL14.eglGetCurrentContext())); 60 | } 61 | } 62 | }); 63 | } 64 | 65 | public void stopRecording() { 66 | mGLSurfaceView.queueEvent(new Runnable() { 67 | @Override 68 | public void run() { 69 | if (mVideoEncoder.isRecording()) { 70 | mVideoEncoder.stopRecording(); 71 | } 72 | } 73 | }); 74 | } 75 | 76 | @Override 77 | public void onSurfaceChanged(GL10 gl, int width, int height) { 78 | LogUtils.v(String.format("onSurfaceChanged: width = %d, height = %d", width, height)); 79 | mProgram = new RGBProgram(mGLSurfaceView.getContext(), width, height); 80 | mBuffer = ByteBuffer.allocateDirect(width * height * 4).order(ByteOrder.nativeOrder()); 81 | mVideoEncoder = new MovieEncoder1(mGLSurfaceView.getContext(), width, height); 82 | RtspHelper.getInstance().createPlayer(mRtspUrl, width, height, this); 83 | } 84 | 85 | public void onSurfaceDestoryed() { 86 | RtspHelper.getInstance().releasePlayer(); 87 | } 88 | 89 | @Override 90 | public void onDrawFrame(GL10 gl) { 91 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 92 | glClearColor(1f, 1f, 1f, 1f); 93 | 94 | mProgram.useProgram(); 95 | 96 | synchronized (mBuffer) { 97 | mProgram.setUniforms(mBuffer.array(), 90); 98 | } 99 | 100 | mProgram.draw(); 101 | } 102 | 103 | @Override 104 | public void onPreviewFrame(final ByteBuffer buffer, int width, int height) { 105 | synchronized (mBuffer) { 106 | mBuffer.rewind(); 107 | 108 | buffer.rewind(); 109 | mBuffer.put(buffer); 110 | } 111 | 112 | mGLSurfaceView.post(new Runnable() { 113 | @Override 114 | public void run() { 115 | mVideoEncoder.frameAvailable(buffer.array(), System.nanoTime()); 116 | } 117 | }); 118 | 119 | mGLSurfaceView.requestRender(); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /vlcdemo/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 14 |