Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Excessive number of chunks when streaming to MediaMTX

Aperta
#2,099 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
15/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
android, kotlin

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Kotlin
Stelle
3k
Fork
946
Merge medio
5g 1h
PR unite (30g)
6

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pedroSG94/RootEncoder

Tutte le issue di pedroSG94/RootEncoder

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.