Convert Figma logo to code with AI

pili-engineering logoPLDroidMediaStreaming

PLDroidMediaStreaming 是七牛推出的一款适用于 Android 平台的推流 SDK,支持 RTMP 推流,h.264 和 AAC 编码,硬编、软编支持。具有丰富的数据和状态回调,方便用户根据自己的业务定制化开发。具有直播场景下的重要功能,如:美颜、背景音乐、水印等功能。PLDroidMediaStreaming 是现在目前重点维护的版本,自带采集模块也支持用户自己做采集端。

1,451
460
1,451
139

Top Related Projects

32,417

Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support.

4,870

RTMP live streaming client for Android

该项目不再维护,仅供学习参考

业内为数不多致力于极致体验的超强全自研跨平台(windows/linux/android/iOS)流媒体内核,通过模块化自由组合,支持实时RTMP推流、RTSP推流、RTMP播放器、RTSP播放器、录像、多路流媒体转发、音视频导播、动态视频合成、音频混音、直播互动、内置轻量级RTSP服务等,比快更快,业界真正靠谱的超低延迟直播SDK(1秒内,低延迟模式下200~400ms)。

Quick Overview

PLDroidMediaStreaming is an Android SDK for live video streaming. It provides a comprehensive solution for capturing, processing, and broadcasting live video content from Android devices. The SDK offers features like camera preview, video encoding, and RTMP streaming.

Pros

  • Easy integration with Android applications
  • Supports both hardware and software encoding
  • Offers various video effects and filters
  • Provides real-time statistics and quality monitoring

Cons

  • Limited to Android platform only
  • May require additional setup for certain advanced features
  • Documentation primarily in Chinese, which may be challenging for non-Chinese speakers
  • Potential licensing restrictions for commercial use

Code Examples

  1. Initializing the streaming manager:
PLMediaStreamingManager mMediaStreamingManager = new PLMediaStreamingManager(this, mCameraPreviewView, mEncodingConfig);
mMediaStreamingManager.prepare(mCameraStreamingSetting, mMicrophoneStreamingSetting, null);
  1. Starting the stream:
mMediaStreamingManager.startStreaming();
  1. Applying a video filter:
mMediaStreamingManager.setVideoFilter(new PLBuiltinFilter(PLBuiltinFilter.FILTER_BEAUTY));
  1. Stopping the stream:
mMediaStreamingManager.stopStreaming();

Getting Started

  1. Add the SDK dependency to your build.gradle file:
dependencies {
    implementation 'com.qiniu.pili:pldroid-media-streaming:2.3.5'
}
  1. Initialize the streaming manager in your activity:
PLMediaStreamingManager mMediaStreamingManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    PLMediaStreamingConfiguration config = new PLMediaStreamingConfiguration();
    mMediaStreamingManager = new PLMediaStreamingManager(this, findViewById(R.id.cameraPreview), config);
    mMediaStreamingManager.prepare(new PLCameraStreamingSetting(), new PLMicrophoneStreamingSetting(), null);
}
  1. Start streaming when ready:
mMediaStreamingManager.startStreaming();

Competitor Comparisons

32,417

Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support.

Pros of ijkplayer

  • Cross-platform support (Android, iOS, macOS, Windows)
  • Based on FFmpeg, providing extensive codec and format support
  • Active community and frequent updates

Cons of ijkplayer

  • Steeper learning curve due to its lower-level API
  • Larger binary size compared to PLDroidMediaStreaming
  • May require more manual configuration for specific use cases

Code Comparison

PLDroidMediaStreaming:

StreamingManager mStreamingManager = new StreamingManager(this);
mStreamingManager.setStreamingProfile(profile);
mStreamingManager.prepare(mCameraPreviewView);
mStreamingManager.startStreaming();

ijkplayer:

IjkMediaPlayer ijkMediaPlayer = new IjkMediaPlayer();
ijkMediaPlayer.setDataSource(url);
ijkMediaPlayer.prepareAsync();
ijkMediaPlayer.start();

Key Differences

  • PLDroidMediaStreaming focuses on live streaming, while ijkplayer is primarily a media player
  • ijkplayer offers more flexibility and control over media playback
  • PLDroidMediaStreaming provides a higher-level API for easier implementation of streaming functionality

Use Cases

  • Choose PLDroidMediaStreaming for quick implementation of live streaming in Android apps
  • Opt for ijkplayer when cross-platform support and advanced media playback features are required
4,870

RTMP live streaming client for Android

Pros of yasea

  • Lightweight and easy to integrate
  • Open-source with an active community
  • Supports both RTMP streaming and local recording

Cons of yasea

  • Limited documentation compared to PLDroidMediaStreaming
  • Fewer advanced features and customization options
  • May require more manual configuration for complex use cases

Code Comparison

PLDroidMediaStreaming:

mMediaStreamingManager = new MediaStreamingManager(this, mCameraPreviewFrameView, mEncodingConfig);
mMediaStreamingManager.prepare(mCameraStreamingSetting, mMicrophoneStreamingSetting, null, mProfile);
mMediaStreamingManager.startStreaming();

yasea:

mPublisher = new SrsPublisher(this);
mPublisher.setEncodeHandler(new SrsEncodeHandler(this));
mPublisher.setRtmpHandler(new RtmpHandler(this));
mPublisher.startCamera();
mPublisher.startPublish(rtmpUrl);

Both libraries offer straightforward initialization and streaming setup. PLDroidMediaStreaming provides a more comprehensive configuration approach, while yasea focuses on simplicity and ease of use. PLDroidMediaStreaming may be better suited for complex projects requiring fine-tuned control, whereas yasea could be ideal for quick implementations or smaller-scale applications.

该项目不再维护,仅供学习参考

Pros of SopCastComponent

  • Lightweight and focused on live streaming functionality
  • Easy to integrate into existing Android projects
  • Open-source with an active community

Cons of SopCastComponent

  • Less comprehensive feature set compared to PLDroidMediaStreaming
  • May require additional libraries for advanced functionality
  • Limited documentation and examples

Code Comparison

SopCastComponent:

CameraListener cameraListener = new CameraListener() {
    @Override
    public void onOpenSuccess() {
        // Camera opened successfully
    }
};
mCameraManager.setCameraOpenListener(cameraListener);

PLDroidMediaStreaming:

mMediaStreamingManager = new MediaStreamingManager(this, avsOptions, cameraStreamingSetting, microphoneStreamingSetting);
mMediaStreamingManager.setStreamingStateListener(new StreamingStateListener() {
    @Override
    public void onStateChanged(StreamingState state, Object extra) {
        // Handle streaming state changes
    }
});

SopCastComponent provides a more straightforward approach to camera management, while PLDroidMediaStreaming offers a more comprehensive streaming management system with additional options and settings.

Both libraries aim to simplify live streaming for Android developers, but PLDroidMediaStreaming generally offers more features and flexibility at the cost of increased complexity. SopCastComponent may be a better choice for simpler projects or developers looking for a lightweight solution, while PLDroidMediaStreaming is more suitable for advanced streaming applications with complex requirements.

业内为数不多致力于极致体验的超强全自研跨平台(windows/linux/android/iOS)流媒体内核,通过模块化自由组合,支持实时RTMP推流、RTSP推流、RTMP播放器、RTSP播放器、录像、多路流媒体转发、音视频导播、动态视频合成、音频混音、直播互动、内置轻量级RTSP服务等,比快更快,业界真正靠谱的超低延迟直播SDK(1秒内,低延迟模式下200~400ms)。

Pros of SmarterStreaming

  • More comprehensive feature set, including both push and pull streaming capabilities
  • Better support for low-latency streaming and real-time communication
  • More active development and frequent updates

Cons of SmarterStreaming

  • Less documentation and examples compared to PLDroidMediaStreaming
  • Steeper learning curve due to more complex architecture
  • Potentially higher resource usage due to advanced features

Code Comparison

SmarterStreaming:

SmartPublisherJni.SmartPublisherInit(width, height, frameRate, bitRate);
SmartPublisherJni.SmartPublisherSetVideoEncodeType(videoEncodeType);
SmartPublisherJni.SmartPublisherStartPublish(rtmpUrl);

PLDroidMediaStreaming:

mMediaStreamingManager = new MediaStreamingManager(this, mCameraPreviewView);
mMediaStreamingManager.prepare(mProfile);
mMediaStreamingManager.startStreaming();

SmarterStreaming offers more granular control over streaming parameters, while PLDroidMediaStreaming provides a simpler, more abstracted API. SmarterStreaming's approach allows for finer tuning but requires more setup code. PLDroidMediaStreaming's streamlined interface may be easier for beginners but offers less customization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

PLDroidCameraStreaming

PLDroidCameraStreaming 是一个适用于 Android 的 RTMP 直播推流 SDK,可高度定制化和二次开发。特色是同时支持 H.264 软编/硬编和 AAC 软编/硬编。支持 Android Camera 画面捕获,并进行 H.264 编码,以及支持 Android 麦克风音频采样并进行 AAC 编码;还实现了一套可供开发者选择的编码参数集合,以便灵活调节相应的分辨率和码率;同时,SDK 提供数据源回调接口,用户可进行 Filter 处理。借助 PLDroidCameraStreaming ,开发者可以快速构建一款类似 Meerkat 或 Periscope 的 Android 直播应用。

功能特性

  • 支持 H.264 和 AAC 软编(推荐)
  • 支持 H.264、H.265 和 AAC 硬编
  • 软编支持 Android Min API 15(Android 4.0.3)及其以上版本
  • 硬编支持 Android Min API 18(Android 4.3)及其以上版本
  • 支持构造带安全授权凭证的 RTMP 推流地址
  • 支持 RTMP 封包及推流
  • 支持 RTMP 推流自适应网络质量动态切换码率或自定义策略
  • 支持内置美颜,以及可动态调节美颜效果
  • 支持数据源回调接口,可自定义 Filter (滤镜) 特效处理
  • 支持前后置摄像头,以及动态切换
  • 支持自动对焦
  • 支持手动对焦
  • 支持 Encoding Mirror 设置
  • 支持 Zoom 操作
  • 支持 Mute/Unmute
  • 支持闪光灯操作
  • 支持纯音频推流,以及后台运行
  • 支持截帧功能
  • 支持动态更改 Encoding Orientation
  • 支持动态切换横竖屏
  • 支持动态水印
  • 支持动态文字与贴图
  • 支持蓝牙麦克风
  • 支持后台推流
  • 支持双声道立体声
  • 支持 QUIC 推流
  • 支持 ARM, ARMv7a, ARM64v8a, X86 主流芯片体系架构
  • 支持 SEI 信息发送
  • 支持 SRT 推流

PLDroidCameraStreaming 文档

详细的开发指南请参考官方文档

设备以及系统要求

  • 设备要求:搭载 Android 系统的设备
  • 系统要求:Android 4.3(API 18) 及其以上

版本升级须知

v3.1.5

  • 从 v3.1.5 版本开始,将不再支持 armeabi 架构

v3.1.3

  • 从 v3.1.3 版本开始,HappyDNS 库务必升级到 1.0.0 版本

v3.1.2

  • 从 v3.1.2 版本开始,SDK 将不再强制要求获取 READ_PHONE_STATE 和 ACCESS_FINE_LOCATION 的权限

v3.1.1

  • 从 v3.1.1 版本开始,HappyDNS 库务必升级到 0.2.18 版本

v3.0.2

  • 从 v3.0.2 版本开始,请务必添加 android.arch.lifecycle:extensions:x.y.z 的依赖
  • 从 v3.0.2 版本开始,StreamingEnv.init(Context context) 已被弃用,请更新到 StreamingEnv.init(Context contex, String userId) 进行环境的初始化,其中,userId 代表用户的唯一标识符,用于区分不同的用户

v3.0.1

  • 从 v3.0.1 版本开始,如果您使用了 Happy DNS 库,请务必升级到 0.2.17 版本

v3.0.0

  • 从 v3.0.0 版本开始,七牛直播推流 SDK 需要先获取授权才能使用。授权分为试用版和正式版,可通过 400-808-9176 转 2 号线联系七牛商务咨询,或者 通过工单 联系七牛的技术支持。
  • v3.0.0 之前的版本不受影响,请继续放心使用。
  • 老客户升级 v3.0.0 版本之前,请先联系七牛获取相应授权,以免发生鉴权不通过的现象。
  • 基于 114 dns 解析的不确定性,使用该解析可能会导致解析的网络 ip 无法做到最大的优化策略,进而出现推流质量不佳的现象。因此建议使用非 114 dns 解析

v2.4.1

  • 从 v2.4.1 开始,VideoProfile 对 H264 格式配置的参数由 annexb 改为 avcc,之前设置为 false 的客户,需要将配置改为 true。

例如目前设有如下配置的客户:

StreamingProfile.VideoProfile vProfile =
	new StreamingProfile.VideoProfile(20, 1000 * 1024, 60, false);

需将参数调整为:

StreamingProfile.VideoProfile vProfile =
	new StreamingProfile.VideoProfile(20, 1000 * 1024, 60, true);

v2.3.0

  • 从 v2.3.0 版本开始,增加 libpldroid_streaming_puic.so 库
  • libpldroid_streaming_core.so 依赖于 libpldroid_streaming_puic.so,无论是否启用 QUIC 推流,都需要包含 libpldroid_streaming_puic.so 库

v2.2.0

  • 从 v2.2.0 版本开始,须要在 build.gradle 中删除 QoS 依赖
dependencies {
    ...
    compile 'com.qiniu.pili:pili-android-qos:0.8.+'
    ...
}

v2.1.0

  • 使用录屏功能前,须要在 AndroidManifest.xml 中注册 SDK 内置的 Activity:
<activity
        android:name="com.qiniu.pili.droid.streaming.screen.ScreenCaptureRequestActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" >
</activity>
  • pili-android-qos 最新版本为 0.8.13

  • 更新 StreamingPreviewCallback#onPreviewFrame

StreamingPreviewCallback#onPreviewFrame(byte[] data, int width, int height)

调整为

/**
* Called if the {@link StreamingPreviewCallback} registered.
*
* @param data the contents of the preview frame in fmt format
* @param width the width of the frame
* @param height the height of the frame
* @param rotation set the clockwise rotation of frame in degrees to achieve the same effect of preview display.
* @param fmt the format of the frame. See also {@link com.qiniu.pili.droid.streaming.av.common.PLFourCC}
* @param tsInNanoTime the timestamp of the frame
*
* */
boolean StreamingPreviewCallback#onPreviewFrame(byte[] data, int width, int height, int rotation, int fmt, long tsInNanoTime);

v2.0.1

从 v2.0.1 开始:

  • 删掉废弃的 CameraStreamingManager,可使用 MediaStreamingManager
  • 须在宿主项目中的 build.gradle 中加入如下语句:
dependencies {
    ...
    compile 'com.qiniu:happy-dns:0.2.+'
    compile 'com.qiniu.pili:pili-android-qos:0.8.+'
    ...
}
  • 废弃的 StreamingPreviewCallback#onPreviewFrame(byte[] bytes, Camera camera) 被删掉,可使用 StreamingPreviewCallback#onPreviewFrame(byte[] bytes, int width, int height)

  • AudioSourceCallback#onAudioSourceAvailable(ByteBuffer byteBuffer, int size, boolean eof) 接口回调中增加时间戳信息,更改为 AudioSourceCallback#onAudioSourceAvailable(ByteBuffer byteBuffer, int size, long tsInNanoTime, boolean eof)

v2.0.0 Beta

从 v2.0.0 Beta 开始,SDK 由 PLDroidCameraStreaming 更名为 PLDroidMediaStreaming,将会提供更丰富的功能接口。有如下重大更新:

  • 新增 MediaStreamingManager,废弃 CameraStreamingManager 且不再被维护
  • 新增一些辅助类并废弃相关的类
    • 新增 StreamingStateChangedListener,并废弃 CameraStreamingManager#StreamingStateListener
    • 新增 StreamingState,并废弃 CameraStreamingManager#STATE
    • 新增 StreamingSessionListener,并废弃 CameraStreamingManager#StreamingSessionListener
    • 新增 AVCodecType,并废弃 CameraStreamingManager#EncodingType
  • 包名更新为 com.qiniu.pili.droid.streaming.*;,因此需要更新混淆相关代码

v1.6.1

从 v1.6.1 开始,为了便于用户更好地定制化,将 TransformMatrix 信息加入到 SurfaceTextureCallback#onDrawFrame。因此更新到 v1.6.1 版本之后,若实现了 SurfaceTextureCallback 接口,需要将

int onDrawFrame(int texId, int texWidth, int texHeight);

更改为:

int onDrawFrame(int texId, int texWidth, int texHeight, float[] transformMatrix);

v1.6.0

从 v1.6.0 开始,在使用 SDK 之前,需要保证 StreamingEnv 被正确初始化 ,否则在构造核心类 CameraStreamingManager 的阶段会抛出异常。具体可参看 Demo。

StreamingEnv.init(getApplicationContext());

v1.4.6

从 v1.4.6 版本开始,需要在宿主项目中的 build.gradle 中加入如下语句:

dependencies {
    ...
    compile 'com.qiniu:happy-dns:0.2.7'
    ...
}

否则,在运行时会发生找不到 happydns 相关类的错误。

v1.6.0

从 v1.6.0 开始,在使用 SDK 之前,需要保证 StreamingEnv 被正确初始化 ,否则在构造核心类 CameraStreamingManager 的阶段会抛出异常。具体可参看 Demo。

StreamingEnv.init(getApplicationContext());

v1.6.1

从 v1.6.1 开始,为了便于用户更好地定制化,将 TransformMatrix 信息加入到 SurfaceTextureCallback#onDrawFrame。因此更新到 v1.6.1 版本之后,若实现了 SurfaceTextureCallback 接口,需要将

int onDrawFrame(int texId, int texWidth, int texHeight);

更改为:

int onDrawFrame(int texId, int texWidth, int texHeight, float[] transformMatrix);

反馈及意见

当你遇到任何问题时,可以通过在 GitHub 的 repo 提交 issues 来反馈问题,请尽可能的描述清楚遇到的问题,如果有错误信息也一同附带,并且在 Labels 中指明类型为 bug 或者其他。

通过这里查看已有的 issues 和提交 Bug。