Excessive number of chunks when streaming to MediaMTX
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 15/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Quiet
- Domain
- mobile-dev, networking
Research direction
The report gives no reproduction steps beyond streaming to MediaMTX, so start by reading the code it quotes: GenericStream setup, getStreamClient().setBitrateExponentialFactor(0.5f), the BitrateAdapter callback calling setVideoBitrateOnFly, and startStreaming calling genericStream.startStream. Done would mean identifying which of these changes bitrate or chunk sizing under poor LTE conditions, backed by a reproduction or test. The thread has no maintainer decision yet, so confirm the approach in the comments before writing code.
Written by the indexing model from the issue text.
Description
Describe the bug
When streaming to MediaMTX we see randomly excessive number of chunks recorded.
When streaming from an application created with RootEncoder we are randomly seeing excessive number of chunks (about 7000 in one instance) when recording the streaming. The same is observed on HLS streamed from the server.
The client (device) is an android phone with RootEncoder app. It is streaming over LTE(4g) mobile network with h264/720p/1.6 Mbps CBR.
The behaviour is observed on different quality of network connectivity (not only poor). We do not have control over location, quality of connectivity of the device doing the streaming.
We have 60 ingest servers (mediamtx handling incomming rtmp traffic) and the clinets are more or less equally distributed on them. Top planned load per server is 200 streams, and we are doing extremely minimal processing (e.g. appending a bit of metadata with ffmpeg, calling few curls to external services). Servers in and of themselves are not overloaded. Usuall observed load is in the range of 90% - 95%
code is mostly:
/**
* StreamActivity is responsible for handling the camera preview and video streaming functionality.
* It utilizes the RootEncoder library for streaming video and audio data.
* This activity implements the ConnectChecker interface to handle streaming connection events.
*/
class StreamActivity : ComponentActivity(), ConnectChecker, Loggable {
//region PROPERTIES ⤵
private lateinit var viewModel: StreamActivityViewModel
/**
* Lazy-loaded instance of GenericStream, used for handling video and audio streaming.
* Sets automatic orientation handling and adjusts bitrate based on network conditions.
*/
val genericStream: GenericStream by lazy {
GenericStream(this, this).apply {
getGlInterface().autoHandleOrientation = true
getStreamClient().setBitrateExponentialFactor(0.5f)
}
}
private var _binding: ActivityStreamBinding? = null
private val binding get() = _binding!!
private val width = 1280 // Video resolution width
private val height = 720 // Video resolution height
private val vBitrate = 1500 * 1000 // Video bitrate in bps
private var rotation = 0 // Video rotation angle
private val sampleRate = 44100 // Audio sample rate
private val isStereo = false // Stereo audio configuration(Mono)
private val aBitrate = 48 * 1000 // Audio bitrate in kbps
private var recordPath = "" // Path for saving recorded video
private val fps = 20 // Frames per second
private var timerJob: Job? = null
private var broadcastStartTime: Long = 0L
private var checkBatteryLevelTimer: Timer? = null
private val handler = Handler(Looper.getMainLooper())
private val orientationHelper = OrientationHelper()
private val section: Section = getCurrentSection()
private val backPressHandler = Handler(Looper.getMainLooper())
private var currentToast: Toast? = null
private var backPressedOnce = false
private var soundLevelJob: Job? = null
private var microphoneSourceWrapper: MicrophoneSourceWrapper? = null
private var startingTime: Date = Date()
// Bitrate adapter to dynamically adjust bitrate based on bandwidth conditions
private val bitrateAdapter = BitrateAdapter {
genericStream.setVideoBitrateOnFly(it)
}.apply {
setMaxBitrate(vBitrate + aBitrate)
}
/**
* Initiates streaming if not already active.
*
* @param rtmpUrl The RTMP URL to stream to.
*
*/
private fun startStreaming(rtmpUrl: String) {
logInfo("Start streaming to -> $rtmpUrl")
if (!genericStream.isStreaming) {
binding.apply {
genericStream.startStream(rtmpUrl)
}
}
}
To Reproduce
Start streaming against mediamtx
Expected behavior
Normal streaming with no chunking except in extremely lossy conditions (e.g. very bad 4/5G connectivity)
Smartphone (please complete the following information):
- Library version: 2.6.1
- Device: motorola moto e13
- OS: android 13
- Media server: MediaMTX 1.7.0
- Class used [e.g. RtmpCamera1]
Additional context
Cross posted to Mediamtx: https://github.com/bluenviron/mediamtx/issues/5810
- Dominant language
- Kotlin
- Stars
- 3k
- Forks
- 946
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 9
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pedroSG94/RootEncoder
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
pedroSG94/RootEncoder#2213 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
pedroSG94/RootEncoder#2207 · 1 reaction ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
pedroSG94/RootEncoder#2203 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
pedroSG94/RootEncoder#2192 · 2 comments ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
pedroSG94/RootEncoder#2177 · 44 comments ·
Maintainers usually reply within 2 days
All issues in pedroSG94/RootEncoder
Similar issues
-
Dev
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ankidroid/Anki-Android#22555 ·
Maintainers usually reply within 1 day
-
enhancement good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
core: RAC_LLM_OPTIONS_DEFAULT.min_p disagrees with the IDL's annotated defaultPossibly taken A pull request linked to this issue is open or already merged. Openbug core p3
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
RunanywhereAI/runanywhere-sdks#1083 ·
Maintainers usually reply within 5 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Java and Kotlin (JVM): parse gradle/wrapper/gradle-wrapper.properties with exact line locationsOpenarea: detector eco: java help wanted lane: free-agent roadmap size: S type: parser
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
arminazimi/evergreen#355 ·
Maintainers usually reply within 1 day