Giter Site home page Giter Site logo

luohaohaha / rtmpx Goto Github PK

View Code? Open in Web Editor NEW
30.0 3.0 3.0 7.13 MB

RTMPX是一个android的rtmp推流库,采集使用camerax,支持60fps,编码使用mediacodec硬编码,推流使用了librtmp。RTMPX is an android rtmp streaming library. It uses camerax for acquisition and supports 60fps. The encoding uses mediacodec hard coding, and the streaming uses librtmp.

License: Apache License 2.0

Java 15.05% CMake 0.25% C 37.87% Makefile 0.33% Roff 0.79% HTML 0.96% C++ 44.74%
android camerax mediacodec librtmp rtmp rtmp-push 60fps

rtmpx's Introduction

RTMPX

English doc

RTMPX是一个android的rtmp推流库,采集使用camerax,支持60fps,编码使用mediacodec硬编码,推流使用了librtmp。

30fps.mp4
60fps.mp4

支持的功能

  • 60帧预览、推流(理论上支持更高,只要手机支持,目前pixel2最高设置240fps,但是没效果)
  • 边推流边录制(保存到本地)

已知问题

  • 部分机型在竖屏推流60fps的时候性能不够,导致libyuv旋转需要很长时间(例如pixel2,I帧旋转要12ms),导致达不到60fps
  • 等你发现

待优化

  • 添加注释
  • 支持滤镜
  • 竖屏libyuv旋转时长优化

怎么使用(参考示例app)

1. 依赖

1) 下载aar(这种集成aar文件的方式,camerax库是必须依赖)
  def camerax_version = "1.0.0"
// CameraX core library using camera2 implementation
    implementation "androidx.camera:camera-camera2:$camerax_version"
// CameraX Lifecycle Library
    implementation "androidx.camera:camera-lifecycle:$camerax_version"
// CameraX View class
    implementation "androidx.camera:camera-view:1.0.0-alpha24"

or

2) mavenCentral远程依赖
implementation 'io.github.luohaohaha:rtmpx:latest'

2. 将CameraXImplView 放入布局

...
 <com.rtmpx.library.camera.widget.CameraXImplView
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
...

3. 设置推流配置

  Config config = new Config.ConfigBuilder()
                .withBitRate(1000 * 5000) //码率
                .withPublishUrl("rtmp://192.168.50.170:18888/test/live") //推流url
                .withFrameRate(60)//帧率
                .withVideoWidth(1080)//视频宽 
                .withVideoHeight(1920) //视频高
                .withRecordVideo(false)//是否录制
                .withRecordVideoPath("sdcard/dump.mp4")//录制文件保存文件
                .build();

4. 绑定预览控件

 CameraXImplView mPreview = findViewById(R.id.preview);
 mPreview.setPreviewRange(mConfig.getFrameRate(),mConfig.getFrameRate());
 mPreview.setTargetResolution(mConfig.getVideoWidth(), mConfig.getVideoHeight());
 
 PublisherX mPublisher = new PublisherX(mConfig);
 mPublisher.bindCamera(mPreview);
 mPublisher.setPublishListener(this);
 

5. 开启预览 & 开始推流 / 停止预览 & 停止推流

mPreview.startPreview();
mPublisher.startPublish();

or

mPreview.stopPreview();
mPublisher.stopPublish();

IPublishListener 回调

    /**
     * rtmp连接中
     */
    void onConnecting();

    /**
     * rtmp 连接建立成功
     */
    void onConnected();

    /**
     * rtmp 连接失败
     * @param code error code 失败错误码
     */
    void onConnectedFailed(int code);

    /**
     * 开始推流
     */
    void onStartPublish();

    /**
     * 结束推流
     */
    void onStopPublish();

    /**
     * 开始录制
     */
    void onStartRecord();

    /**
     * 结束录制
     */
    void onStopRecord();

    /**
     * 发送平均帧率统计(带宽不足的情况下会低于设置帧率)
     * @param fps avg fps
     */
    void onFpsStatistic(int fps);

    /**
     * rtmp 断开连接
     */
    void onRtmpDisconnect();

Thanks

LibRtmp-Client-for-Android

rtmpx's People

Contributors

luohaohaha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rtmpx's Issues

how to properly receive?

I am trying to receive the RTMP stream

running ffmpeg as rtmp server via ffmpeg -re -f flv -listen 1 -i rtmp://10.10.10.50:8080/live/app -vcodec copy -f flv -listen 1 rtmp://10.10.10.50:1935/live/app

app is configured to publish to rtmp://10.10.10.50:8080/live/app

then i connect the rtmp client via

rtmpdump -r rtmp://10.10.10.50:1935/live/app -R -o - | ffplay -

but all I see is a black screen ...

what setup are you using for devel / testing as for the rtmp server / client?

thx

為什麼我手機螢幕多旋轉成橫向或直向幾次後,會出現以下的crash?

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.Display.getRotation()' on a null object reference
at com.rtmpx.library.camera.widget.CameraXImplView.setAnalyzer(CameraXImplView.java:226)
at com.rtmpx.library.camera.widget.CameraXImplView.lambda$null$0$com-rtmpx-library-camera-widget-CameraXImplView(CameraXImplView.java:177)
at com.rtmpx.library.camera.widget.CameraXImplView$$ExternalSyntheticLambda0.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7870)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

我直播的XML layout Design tag預覽頁面整個Activity 所有View元件都看不到

我直播的XML layout Design tag預覽頁面整個Activity 所有View元件都會消失看不到
,但其他Activity跟Fragment都正常。
然後在Message會顯示下面的錯誤:
java.lang.IllegalStateException: CameraX is not configured properly. The most likely cause is you did not include a default implementation in your build such as 'camera-camera2'.   at androidx.camera.core.CameraX.<init>(CameraX.java:109)   at androidx.camera.lifecycle.ProcessCameraProvider.getOrCreateCameraXInstance(ProcessCameraProvider.java:181)   at androidx.camera.lifecycle.ProcessCameraProvider.getInstance(ProcessCameraProvider.java:167)   at com.rtmpx.library.camera.widget.CameraXImplView.setUpCamera(CameraXImplView.java:159)   at com.rtmpx.library.camera.widget.CameraXImplView.onAttachedToWindow(CameraXImplView.java:154)   at android.view.View.dispatchAttachedToWindow(View.java:20753)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3490)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)   at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:58)

但是我gradle有加:

implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
// If you want to additionally use the CameraX Lifecycle library
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
// If you want to additionally use the CameraX View class
implementation "androidx.camera:camera-view:${camerax_version}"

不知道是什麼原因?

stream directly from camera not via capturing preview

would it be possible to stream directly from camera?

aka not going thru the preview at all, the preview limits fps at my device (oneplus 8T) to only 30fps even if the sensor supports up to 240fps on full hd ...

Publish(ed) App?

It seems like this could provide a simple, effective, open source alternative to DroidCam.

Have y'all considered making a slightly more advanced Android app with options for the user to specify the publish URL, rather than how it's hard-coded now?

Or is there an app that is built with this? It seems too good! :)

thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.