1 Star 0 Fork 8

释冰翼 / AndroidInstantVideo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README_EN.md 6.35 KB
一键复制 编辑 原始数据 按行查看 历史
ChillingVan” 提交于 2017-06-11 12:00 . update readme

AndroidInstantVideo

Show the stream of Android video hardware encode, including video processing and video publishing.

  1. Use MediaCodec for H264 encoding.
  2. Use MediaCodec for AAC encoding.
  3. Use RTMP for video publishing.

Thanks for these projects

LibRtmp-Client-for-Android

Requirement

  • Android API >= 18

Usage

Gradle dependency

sample:

// in root build.gradle
allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

// module build.gradle
dependencies {
    compile 'com.github.ChillingVan:AndroidInstantVideo:v1.0.1.0'
}

Feature

  • MediaCodec Hardware encoding for H264 + Video Processing

    Sample: TestVideoEncoder The Video Processing Part:

public class TestVideoEncoder {
//...
    public void prepareEncoder() {
    //...
        h264Encoder.setOnDrawListener(new H264Encoder.OnDrawListener() {
            @Override
            public void onGLDraw(ICanvasGL canvasGL, SurfaceTexture producedSurfaceTexture, RawTexture rawTexture, @Nullable SurfaceTexture outsideSurfaceTexture, @Nullable BasicTexture outsideTexture) {
                // 此处可以使用canvasGL的drawTexture, drawBitmap等方法实现对视频帧的处理.
                // 
                // 
            }
        });
    //...
    }
//...
}

The key for video frame processing : android-opengl-canvas

H264 test file: /storage/sdcard/Android/data/com.chillingvan.instantvideo.sample/files/test_h264_encode.h264,可以在代码里修改输出路径

public class TestVideoEncoder {
    public TestVideoEncoder(Context ctx, final EglContextWrapper eglCtx) {
        try {
            os = new FileOutputStream(ctx.getExternalFilesDir(null) + File.separator + "test_h264_encode.h264");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

You can use PotPlayer to play the test files.

  • Camera

    I wrap a class for simple usage InstantVideoCamera Not work well at my 4.4 phone but fine on my 6.0 phone.

  • AAC Audio

    Sample: TestAudioEncoder

    Test file directory:/storage/sdcard/Android/data/com.chillingvan.instantvideo.sample/files/test_aac_encode.aac",可以在代码里修改输出路径 You can use PotPlayer to play the test files.

  • LibRtmp for RTMP Stream

    Use nginx-rtmp-module for your Nginx test local server. Use OBS for comparing effect. And player can be VLC,PotPlayer,ffplay. Make sure you use player open stream first because of the simple test server.

    Sample: TestCameraPublisherActivity


public class TestCameraPublisherActivity extends AppCompatActivity {
    ...
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        handler = new Handler(handlerThread.getLooper()) {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                StreamPublisher.StreamPublisherParam streamPublisherParam = new StreamPublisher.StreamPublisherParam();
                streamPublisher.prepareEncoder(streamPublisherParam, new H264Encoder.OnDrawListener() {
                    @Override
                    public void onGLDraw(ICanvasGL canvasGL, SurfaceTexture surfaceTexture, RawTexture rawTexture, @Nullable SurfaceTexture outsideSurfaceTexture, @Nullable BasicTexture outsideTexture) {

                        // Here you can do video process
                        // 此处可以视频处理,例如加水印等等
                        canvasGL.drawSurfaceTexture(outsideTexture, outsideSurfaceTexture, 0, 0, outsideTexture.getWidth(), outsideTexture.getHeight());
                        Loggers.i("DEBUG", "gl draw");
                    }
                });
                try {
                    streamPublisher.startPublish(addrEditText.getText().toString(), streamPublisherParam.width, streamPublisherParam.height);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };

//        streamPublisher = new CameraStreamPublisher(new RTMPStreamMuxer(), cameraPreviewTextureView, instantVideoCamera);
        String filename = getExternalFilesDir(null) + "/test_flv_encode.flv";
        streamPublisher = new CameraStreamPublisher(new RTMPStreamMuxer(filename), cameraPreviewTextureView, instantVideoCamera);
    }
    ...
}

TODO

  1. Android Default Muxer. Please implement IMuxer

  2. RTSP Stream.

Pull Request

Welcome. Please add sample code to sample module. Add your license comment.

License

Copyright 2017 ChillingVan.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Donate

Thanks for your support !!! alipay alipay wechat pay wechat pay

Java
1
https://gitee.com/chenwenbin_admin/AndroidInstantVideo.git
git@gitee.com:chenwenbin_admin/AndroidInstantVideo.git
chenwenbin_admin
AndroidInstantVideo
AndroidInstantVideo
master

搜索帮助