rtmp_streaming 1.0.7
rtmp_streaming: ^1.0.7 copied to clipboard
A Flutter plugin for Camera and Microphone streaming library via RTMP.
rtmp_streaming #
π Overview #
rtmp_streaming is a Flutter plugin designed to provide unified RTMP streaming and video recording capabilities for Android and iOS.
It addresses the lack of suitable Flutter RTMP plugins on pub.dev: existing plugins are either no longer maintained or rely on outdated dependencies, making them unsuitable for modern mobile applications.
βοΈ Technical Foundation #
- Android: Based on
com.github.pedroSG94.RootEncoder:library:2.7.5 - iOS: Based on HaishinKit 2.2.5
By leveraging these mature libraries, rtmp_streaming provides a consistent cross-platform API interface, reducing development complexity.
β Why This Plugin #
- No suitable Flutter RTMP plugin exists on pub.dev.
- Existing plugins suffer from:
- Long-term lack of maintenance.
- Outdated dependencies, incompatible with the latest Flutter and platform SDKs.
Therefore, the goal of rtmp_streaming is to deliver a modern, stable, and maintainable RTMP streaming solution.
π οΈ Supported Methods #
π Common Methods (Android & iOS) #
- π· Get available cameras:
availableCameras - βοΈ Initialize plugin:
initialize - π¬ Prepare for streaming (optional, recommended on iOS):
prepareForVideoStreaming - π₯ Start local video recording:
startVideoRecording - βΉοΈ Stop local video recording:
stopRecording - π‘ Start recording and streaming:
startVideoRecordingAndStreaming - βΉοΈ Stop recording or streaming:
stopRecordingOrStreaming - π‘ Start video streaming:
startVideoStreaming - βΉοΈ Stop video streaming:
stopStreaming - π Switch camera:
switchCamera - π Toggle mic capture on/off:
switchAudio - π Temporary mute while streaming:
getHasAudio/setHasAudio - π₯ Temporary video mute while streaming:
getHasVideo/setHasVideo - ποΈ Audio bitrate:
setAudioSettings - ποΈ Video encoder settings:
setVideoSettings - π¬ Frame rate:
setFrameRate - π‘ Toggle flashlight:
switchFlashLight - π Stream statistics:
getStreamStatistics - ποΈ Dispose plugin:
dispose - πΈ Snapshot while streaming:
takePicture
π iOS Exclusive Methods #
Since HaishinKit supports RTMP playback as well as publishing:
- βΈοΈ Pause stream playback:
pauseVideoStreamPlay(pauseStream)Note: pauses playback, not publishing.
- βΆοΈ Resume stream playback:
resumeVideoStreamPlay(resumeStream) - π± Multitasking camera:
setMultitaskingCameraAccessEnabled(HaishinKit 2.2.5+, iOS 17+ when supported) - βοΈ Session preset:
setSessionPreset - πΌοΈ Screen dimensions:
setScreenSettings - ποΈ
setVideoSettingsextras:expectedFrameRate,bitRateMode(2.2.1+ / 2.2.2+),profileLevel
π€ Android Exclusive Methods #
- βΈοΈ Pause recording:
pauseVideoRecording - βΆοΈ Resume recording:
resumeVideoRecording - π¨ Apply filter:
setFilterβ see CameraNativeView.kt fortypevalues - β Remove filter:
removeFilter - π¨ BT.709 encoding:
setForceBt709Color(RootEncoder 2.7.0+) - πΆ RTMP ping / RTT:
setRtmpShouldSendPings(RootEncoder 2.7.0+)
π API Usage #
Recommended streaming flow (cross-platform) #
final cameras = await availableCameras();
final controller = CameraController(
ResolutionPreset.high,
enableAudio: true,
);
await controller.initialize(cameras.first);
// iOS: pre-attach audio to reduce start latency
await controller.prepareForVideoStreaming();
await controller.setAudioSettings(128 * 1024); // bps
await controller.setVideoSettings(bitrate: 1500 * 1024);
await controller.setFrameRate(30);
if (Platform.isAndroid) {
await controller.setForceBt709Color(true);
await controller.setRtmpShouldSendPings(true);
}
if (Platform.isIOS) {
await controller.setMultitaskingCameraAccessEnabled(true);
await controller.setVideoSettings(
expectedFrameRate: 30,
bitRateMode: 'average',
);
}
await controller.startVideoStreaming('rtmp://your-server/live/stream-key');
prepareForVideoStreaming() #
- Purpose: Pre-warm the capture session for streaming. On iOS, attaches audio early; on Android, no-op (safe to call for shared code).
- When: After
initialize, beforestartVideoStreaming.
switchAudio vs setHasAudio #
| Method | Behavior | Use case |
|---|---|---|
switchAudio(false) |
Detach / re-attach mic capture | Fully stop mic input |
setHasAudio(false) |
Temporary mute while still capturing | Quick mute without teardown |
await controller.setHasAudio(false);
final sending = await controller.getHasAudio(); // false
await controller.switchAudio(false);
getHasVideo / setHasVideo #
- Purpose: Temporarily stop or resume sending video while streaming.
- Platform: Android sends black frames via OpenGL; iOS uses mixer video mute.
- When: While streaming.
await controller.setHasVideo(false);
final hasVideo = await controller.getHasVideo();
await controller.setHasVideo(true);
setAudioSettings(int bitrate) #
- Purpose: AAC encoder bitrate in bps.
- When: After
initialize, before starting stream/record.
await controller.setAudioSettings(128 * 1024);
await controller.startVideoStreaming(url);
setVideoSettings({ ... }) #
| Parameter | Cross-platform | Notes |
|---|---|---|
bitrate |
β | Android can hot-update while live via setVideoBitrateOnFly. |
width / height |
Partial | Prefer before go-live. |
frameInterval |
Mostly iOS | Keyframe interval (seconds). |
profileLevel |
iOS only | H.264 profile/level string. |
expectedFrameRate |
iOS only | RTMP onMetaData framerate (2.2.2+). |
bitRateMode |
iOS only | average / constant (iOS 16+) / variable (iOS 26+). |
await controller.setVideoSettings(bitrate: 1200 * 1024);
await controller.setVideoSettings(bitrate: 800 * 1024); // hot update on Android
await controller.setVideoSettings(
expectedFrameRate: 30,
bitRateMode: 'average',
);
setFrameRate(int frameRate) #
- Purpose: Target capture/encode frame rate.
- When: After
initialize, before streaming.
await controller.setFrameRate(30);
await controller.startVideoStreaming(url);
getStreamStatistics() #
Returns StreamStatistics while streaming. Key fields:
| Field | Description |
|---|---|
bitrate, fps, width, height |
Stream metrics |
cacheSize |
Send buffer size |
sentAudioFrames / sentVideoFrames |
Android |
droppedAudioFrames / droppedVideoFrames |
Android |
isAudioMuted / isVideoMuted |
Both platforms (1.0.7+) |
rttMicros |
Android RTT (requires setRtmpShouldSendPings) |
bytesSend |
Bytes sent |
final stats = await controller.getStreamStatistics();
Android: setForceBt709Color(bool enabled) #
await controller.setForceBt709Color(true);
await controller.startVideoStreaming(url);
Android: setRtmpShouldSendPings(bool enabled) #
await controller.setRtmpShouldSendPings(true);
await controller.startVideoStreaming(url);
final stats = await controller.getStreamStatistics();
print(stats.rttMicros);
iOS: setMultitaskingCameraAccessEnabled(bool enabled) #
await controller.setMultitaskingCameraAccessEnabled(true);
await controller.startVideoStreaming(url);
π Conclusion #
rtmp_streaming provides cross-platform RTMP streaming and recording for Flutter.
Since 1.0.7, temporary audio/video mute, encoder settings, and frame rate APIs are aligned on both platforms; iOS retains playback and multitasking extras, Android retains filters, BT.709, and RTT.