Top Related Projects
RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
RTMP live streaming client for Android
Quick Overview
SopCastComponent is an Android library for live video broadcasting. It provides a simple way to implement real-time video streaming functionality in Android applications, supporting both camera preview and screen recording as video sources.
Pros
- Easy integration with existing Android projects
- Supports both camera and screen recording as video sources
- Customizable video quality and bitrate settings
- Includes built-in UI components for quick implementation
Cons
- Limited documentation, especially for advanced usage
- May not support the latest Android versions or features
- Lacks extensive community support or regular updates
- Some users report stability issues on certain devices
Code Examples
- Initializing the SopCast component:
SopCastBuilder builder = new SopCastBuilder()
.withVideoBitrate(1000 * 1024)
.withVideoResolution(640, 360)
.withVideoFPS(24)
.withAudioBitrate(64 * 1024)
.withAudioSampleRate(44100)
.withAudioChannelCount(1);
mSopCast = builder.build();
- Starting a live stream:
mSopCast.startLive(RTMP_URL);
- Switching between camera and screen recording:
// Switch to front camera
mSopCast.switchCamera(CameraData.FRONT);
// Switch to screen recording
mSopCast.switchToScreenRecorder();
- Stopping the live stream:
mSopCast.stopLive();
Getting Started
- Add the dependency to your
build.gradle
file:
dependencies {
implementation 'com.laifeng:sopcast-sdk:1.0.4'
}
- Initialize SopCast in your activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SopCastBuilder builder = new SopCastBuilder()
.withVideoBitrate(1000 * 1024)
.withVideoResolution(640, 360)
.withVideoFPS(24);
mSopCast = builder.build();
mSopCast.setCameraPreview((CameraPreview) findViewById(R.id.camera_preview));
}
- Start and stop streaming:
// Start streaming
mSopCast.startLive(RTMP_URL);
// Stop streaming
mSopCast.stopLive();
Competitor Comparisons
RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Pros of RootEncoder
- More actively maintained with recent updates
- Supports both RTMP and RTSP protocols
- Offers more customization options for encoding parameters
Cons of RootEncoder
- Less comprehensive documentation compared to SopCastComponent
- May have a steeper learning curve for beginners
- Fewer pre-built UI components for quick implementation
Code Comparison
SopCastComponent:
mLiveCameraView = (CameraLivingView) findViewById(R.id.liveView);
mLiveCameraView.init(this, mVideoConfiguration);
mLiveCameraView.addOutputInfo(new RtmpOutputInfo(mRtmpUrl));
mLiveCameraView.startStreaming();
RootEncoder:
rtmpCamera1 = RtmpCamera1(surfaceView, connectCheckerRtmp)
rtmpCamera1.setReTries(10)
rtmpCamera1.setVideoCodec(VideoCodec.H264)
rtmpCamera1.prepareAudio(AudioSource.MIC, 44100, 128 * 1024, true, false, 0)
rtmpCamera1.startStream(rtmpUrl)
Both libraries provide straightforward methods for initializing and starting RTMP streams, but RootEncoder offers more granular control over encoding parameters and retry attempts.
RTMP live streaming client for Android
Pros of yasea
- More active development with recent updates and contributions
- Supports both RTMP and RTSP protocols for streaming
- Includes a demo application for easier testing and implementation
Cons of yasea
- Less comprehensive documentation compared to SopCastComponent
- Fewer customization options for video encoding and filtering
- Limited support for audio processing features
Code Comparison
SopCastComponent:
mVideoConfiguration = new VideoConfiguration.Builder()
.setSize(640, 360)
.setBitrate(800 * 1000)
.setFps(15)
.setIfi(2)
.build();
yasea:
mPublisher = new SrsPublisher(this);
mPublisher.setEncodeHandler(new SrsEncodeHandler(this));
mPublisher.setRtmpHandler(new RtmpHandler(this));
mPublisher.setRecordHandler(new SrsRecordHandler(this));
mPublisher.setPreviewResolution(640, 360);
Both repositories provide Android streaming solutions, but yasea offers more protocol options and recent updates. SopCastComponent provides more detailed configuration options and better documentation. The code comparison shows that SopCastComponent uses a builder pattern for configuration, while yasea uses separate method calls for setup.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
SopCastComponentSDK
欢è¿å ³æ³¨æ¥ç¯ææºå®åç´æå¼æºé¡¹ç®ï¼è¿æ¯ä¸ä¸ªç±çº¯javaç¼åç项ç®ï¼ä½æ¯æ§è½æ¹é¢ä¾ç¶ä¸éãæ´ä¸ªé¡¹ç®å®æäºééã è§é³é¢å¤çãç¼ç ãæ°æ®åéåå¤çãæ°æ®åéçåè½ãæ´ä¸ªé¡¹ç®æ¯æflvå°å ï¼rtmpä¸ä¼ ï¼å½ç¶ä¹åå¤é¢æä¾äºå°å åä¸ä¼ çç¸å ³æ¥å£ã æ´ä¸ªé¡¹ç®æ¯æ们æ¥ç¯å®åå¢éçåªåç»æï¼ä½æ¯å¯è½æäºå°æ¹ä¾ç¶ä¼æä¸äºä¸è¶³ä¹å¤ï¼æ¬¢è¿æ¨æåºå®è´µçæè§å建议ã
ææ¯ææ¡£
Androidææºç´æï¼ä¸ï¼æ»è§
Androidææºç´æï¼äºï¼æåæº
Androidææºç´æï¼ä¸ï¼å£°é³éé
æ¯æåè½
- 硬ç¼ç
- å¼±ç½ç»ç¯å¢å¤ç
- å¨æç çè°æ´
- æå头åæ°è®¾ç½®
- é³é¢åæ°è®¾ç½®
- è§é¢åæ°è®¾ç½®
- æ¯æä¸åçªå£å°ºå¯¸
- æ¯æåºäºGpuçè§é¢ç¹å¤ç
- æ¯æéé³
- æ¯ærtmpä¸ä¼
- æ¯ææ°´å°
- æ¯ææªå±å½å¶
- æ¯ææå头åæ¢
- æ¯æflvå°å
- æ¯ææå头èªå¨å¯¹ç¦åæå¨å¯¹ç¦åæ¢
- æ¯ææå头缩æ¾
- æ¯æéªå ç¯æä½
- æ¯æé³é¢å声æ¶é¤
è¦æ±
- æå头ç¸å ³æä½: Android sdk çæ¬ 14+
- è§é¢ç´æ: Android sdk çæ¬ 18+
å¦ä½ä½¿ç¨
1. ä¸è½½
使ç¨èµ·æ¥é常æ¹ä¾¿, Gradle:
compile 'com.laifeng:sopcast-sdk:1.0.4'
2. æé
å¨ä½¿ç¨åéè¦æ·»å ç¸åºçæé:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.autofocus" />
注æï¼ å¨Android 6.0以åå¾å¤æééè¦å¨æç³è¯·. å¦æä½ æ³å¿«é使ç¨ï¼å¯ä»¥å°é¡¹ç®çtargetSdkVersion设置å¨23ä¸ä¸ã
3. é¢è§çªå£å¤§å°
CameraLivingViewæ¯æViewåºå®å¤§å°ï¼EXACTLYï¼ç模å¼ï¼å½ç¶ä¹å¯ä»¥å¨xmlä¸å®ä¹çªå£çé¿å®½æ¯ï¼ è¿æ ·çè¯ä¸ä¸ªåæ°è¦è®¾ä¸ºåºå®å¤§å°ï¼å¦å¤ä¸ä¸ªåæ°è®¾ä¸º"wrap_content"ã åè代ç å¦ä¸ï¼
<com.laifeng.sopcastsdk.ui.CameraLivingView
android:id="@+id/liveView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:aspect_ratio="0.8"/>
4. æå头åæ°è®¾ç½®
CameraConfiguration.Builder cameraBuilder = new CameraConfiguration.Builder();
cameraBuilder.setOrientation(CameraConfiguration.Orientation.LANDSCAPE)
.setFacing(CameraConfiguration.Facing.BACK).setPreview(720, 1280)
.setFps(24).setFocusMode(CameraConfiguration.FocusMode.TOUCH);
CameraConfiguration cameraConfiguration = cameraBuilder.build();
mLFLiveView.setCameraConfiguration(cameraConfiguration);
å¨ActivityçonCreateæ¹æ³ä¸è®¾ç½®æå头åæ°ä¿¡æ¯ï¼é£ä¹æå头就ä¼æç §ä½ ç设置è¿è¡æå¼ãå¦æä½ å¨æ¨ªå±çé¢ï¼éè¦å°æå头设置为横å±æ¨¡å¼ã ä½ å¯ä»¥ä¼ å ¥ä¸ä¸ªæå头é¢è§å°ºå¯¸ç大å°ï¼å é¨ä¼æ¾åºåè¿ä¸ªè®¾ç½®ç大å°æå¹é ç尺寸è¿è¡ä½¿ç¨ãå¦ææå头é¢è§å¤§å°åå±å¹æ¾ç¤ºå¤§å°ä¸ä¸è´ï¼åä¼å æ³½ä¸é´é¨åè¿è¡ç¼©æ¾æ¾ç¤ºã å¦æä½ ä½¿ç¨é»è®¤ç设置çè¯ï¼åä¸éè¦è¿è¡ä»»ä½è®¾ç½®ãå¾å¤ææºåç½®æå头éè¦è®¾ç½®fps为15ï¼å¦åå¨å¼±å ä¸ä¼å¾é»ã
é»è®¤è®¾ç½®å¦ä¸:
public static final int DEFAULT_HEIGHT = 1280;
public static final int DEFAULT_WIDTH = 720;
public static final int DEFAULT_FPS = 15;
public static final Facing DEFAULT_FACING = Facing.FRONT;
public static final Orientation DEFAULT_ORIENTATION = Orientation.PORTRAIT;
public static final FocusMode DEFAULT_FOCUSMODE = FocusMode.AUTO;
5. è§é¢åæ°è®¾ç½®
VideoConfiguration.Builder videoBuilder = new VideoConfiguration.Builder();
videoBuilder.setSize(640, 360).setMime(DEFAULT_MIME)
.setFps(15).setBps(300, 800).setIfi(2);
mVideoConfiguration = videoBuilder.build();
mLFLiveView.setVideoConfiguration(mVideoConfiguration);
å¨ç´æä¹åå¯ä»¥è¿è¡è§é¢åæ°è®¾ç½®ï¼å¯ä»¥éè¿setSize()æ¹æ³æ¥è®¾ç½®è§é¢è¾åºç尺寸大å°ï¼å¦æ设置ç尺寸æ¯ä¾ä¸ç¬¦åé¢è§å°ºå¯¸æ¯ä¾ï¼åä¼éæ©ä¸é´åºåè¿è¡ç¼©æ¾è¾åºã å¨ç´æä¹åå¯ä»¥è®¾ç½®è§é¢çæ大åæå°ç çï¼ç´æçæ¶åå 使ç¨æ大ç çï¼åæ¥æ ¹æ®ç½ç»ç¯å¢è¿è¡è°æ´ï¼ä½æ¯ç çå§ç»å¨æ大åæå°ç çä¹é´ãmimeåæ°å°ä¼è®¾ç½®å°ç¡¬ç¼ ç¼ç å¨ï¼è¯·ç¡®ä¿mimeçæ£ç¡®æ§ï¼ifiåæ°ä¹ä¼ä¼ éå°ç¡¬ç¼ç¼ç å¨ãå¦æä½ ä½¿ç¨é»è®¤åæ°ï¼åä¸éè¦è¿è¡ä»»ä½è®¾ç½®ã
é»è®¤è®¾ç½®å¦ä¸ï¼
public static final int DEFAULT_HEIGHT = 640;
public static final int DEFAULT_WIDTH = 360;
public static final int DEFAULT_FPS = 15;
public static final int DEFAULT_MAX_BPS = 1300;
public static final int DEFAULT_MIN_BPS = 400;
public static final int DEFAULT_IFI = 2;
public static final String DEFAULT_MIME = "video/avc";
6. é³é¢åæ°è®¾ç½®
AudioConfiguration.Builder audioBuilder = new AudioConfiguration.Builder();
audioBuilder.setAec(true).setBps(32, 64).setFrequency(16000).setMime(DEFAULT_MIME).
setAacProfile(DEFAULT_AAC_PROFILE).setAdts(DEFAULT_ADTS).
setChannelCount(1).setEncoding(DEFAULT_AUDIO_ENCODING);
AudioConfiguration audioConfiguration = audioBuilder.build();
mLFLiveView.setAudioConfiguration(audioConfiguration);
éè¿'setAec(true)'æ¹æ³å¯ä»¥æå¼å声æ¶é¤åè½ï¼å声æ¶é¤åè½ä» ä» å¨(8000, 16000)éæ ·ç并ä¸å声éä¸æ¯æã mimeåæ°å°ä¼è®¾ç½®å°ç¡¬ç¼ç¼ç å¨ï¼è¯·ä½¿ç¨æ£ç¡®çmimeåæ°ãå¦æ使ç¨é»è®¤åæ°ï¼åä¸éè¦è¿è¡ä»»ä½è®¾ç½®ã
é»è®¤è®¾ç½®å¦ä¸ï¼
public static final int DEFAULT_FREQUENCY = 44100;
public static final int DEFAULT_MAX_BPS = 64;
public static final int DEFAULT_MIN_BPS = 32;
public static final int DEFAULT_ADTS = 0;
public static final String DEFAULT_MIME = "audio/mp4a-latm";
public static final int DEFAULT_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
public static final int DEFAULT_AAC_PROFILE = MediaCodecInfo.CodecProfileLevel.AACObjectLC;
public static final int DEFAULT_CHANNEL_COUNT = 1;
public static final boolean DEFAULT_AEC = false;
7. 设置æå å¨
RtmpPacker packer = new RtmpPacker();
packer.initAudioParams(AudioConfiguration.DEFAULT_FREQUENCY, 16, false);
mLFLiveView.setPacker(packer);
æ们å é¨æä¾äºflvårtmpçæå å¨ï¼ä½ ä¹å¯ä»¥å®ä¹èªå·±çæå å¨ãæå å¨è´è´£å°ç¡¬ç¼åçè§é³é¢è¿è¡æå ï¼ç¶åä¼ éç»åéè è¿è¡åéã
8. 设置åéå¨
String url = "rtmp://[host]:1935/[app]/[stream]";
mRtmpSender = new RtmpSender(url);
mRtmpSender.setVideoParams(640, 360);
mRtmpSender.setAudioParams(AudioConfiguration.DEFAULT_FREQUENCY, 16, false);
mRtmpSender.setSenderListener(mSenderListener);
mLFLiveView.setSender(mRtmpSender);
æ们æä¾äºæ¬å°årtmpçåéå¨ï¼æ¬å°åéå¨å°±æ¯ä¿ææ件å°æ¬å°ï¼ä½ ä¹å¯ä»¥å®ä¹èªå·±çåéå¨ã
9. è§é¢ç¹æ
æ们æä¾äºæ ç¹æåç°è²ä¸¤ç§ç¹æï¼ä½ ä¹å¯ä»¥å®ä¹ç¬¦åèªå·±é£æ ¼çè§é¢ç¹æã
mLFLiveView.setEffect(mGrayEffect);
10. æ°´å°
å¨è¿å¾è§é¢ä¸æ·»å æ°´å°ä¹é常æ¹ä¾¿ï¼è®¾ç½®æ°´å°åé¢è§åè¾åºé½ä¼æ¾ç¤ºç¸åºå°ºå¯¸çæ°´å°ã设置水å°ç大å°åä½ç½®æ¯å± äºè¾åºè§é¢çï¼ é¢è§çé¢ä¼æ ¹æ®è¾åºè§é¢çæ åµçæ¯ä¾æ¾ç¤ºæ°´å°ã请设置è§é¢æ°´å°çé¿å®½æ¯åæ°´å°å¾ççé¿å®½æ¯ä¸è´ã
Bitmap watermarkImg = BitmapFactory.decodeResource(getResources(), R.mipmap.watermark);
Watermark watermark = new Watermark(watermarkImg, 50, 25, WatermarkPosition.WATERMARK_ORIENTATION_BOTTOM_RIGHT, 8, 8);
mLFLiveView.setWatermark(watermark);
11. CameraListener
设置ä¸ä¸ªæå头çå¬å¨ï¼è¿æ ·çè¯ä¼åå°æå头çåè°ã
//设置é¢è§çå¬
mLFLiveView.setCameraOpenListener(new CameraListener() {
@Override
public void onOpenSuccess() {
Toast.makeText(LandscapeActivity.this, "Camera open success", Toast.LENGTH_LONG).show();
}
@Override
public void onOpenFail(int error) {
Toast.makeText(LandscapeActivity.this, "Camera open fail", Toast.LENGTH_LONG).show();
}
@Override
public void onCameraChange() {
Toast.makeText(LandscapeActivity.this, "Camera switch", Toast.LENGTH_LONG).show();
}
});
12. LivingStartListener
设置ç´æå¼å§ççå¬å¨ï¼è¿æ ·çè¯ä¼æ¶å°å¼æçç¸å ³çå¬ã
mLFLiveView.setLivingStartListener(new CameraLivingView.LivingStartListener() {
@Override
public void startError(int error) {
Toast.makeText(LandscapeActivity.this, "Start fail", Toast.LENGTH_SHORT).show();
mLFLiveView.stop();
}
@Override
public void startSuccess() {
Toast.makeText(LandscapeActivity.this, "Start success", Toast.LENGTH_SHORT).show();
}
});
The errors:
public static final int NO_ERROR = 0;
public static final int VIDEO_TYPE_ERROR = 1;
public static final int AUDIO_TYPE_ERROR = 2;
public static final int VIDEO_CONFIGURATION_ERROR = 3;
public static final int AUDIO_CONFIGURATION_ERROR = 4;
public static final int CAMERA_ERROR = 5;
public static final int AUDIO_ERROR = 6;
public static final int AUDIO_AEC_ERROR = 7;
public static final int SDK_VERSION_ERROR = 8;
License
SopCastComponent is released under the BSD license. See LICENSE for details.
Top Related Projects
RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
RTMP live streaming client for Android
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot