pedroSG94 / RootEncoder-iOS

RootEncoder iOS (rtmp-rtsp-stream-client-swift) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP and SRT with all code written in Swift
Apache License 2.0
114 stars 34 forks source link

RTMP Display Streaming #23

Closed prikshitgupta closed 2 months ago

prikshitgupta commented 3 months ago

youtube audio is doing stuttering, how i can fix that? how i can mute and unmute mic? its likely encoding issue

prikshitgupta commented 3 months ago

Hi Pedro, Any update?

pedroSG94 commented 3 months ago

Hello,

Mute audio feature is not available for now. I will add this feature in the next days. About audio stuttering. Can you tell me audio configuration? I will try reproduce the case today and fix it.

prikshitgupta commented 3 months ago

Hello,

Mute audio feature is not available for now. I will add this feature in the next days. About audio stuttering. Can you tell me audio configuration? I will try reproduce the case today and fix it.

Hello,

Mute audio feature is not available for now. I will add this feature in the next days. About audio stuttering. Can you tell me audio configuration? I will try reproduce the case today and fix it.

private func startStreaming(endpoint: String) {
    guard let rtmpDisplay = rtmpDisplay else { return }
    rtmpDisplay.setAudioCodec(codec: .AAC)
    rtmpDisplay.setVideoCodec(codec: .H264)

    // Set the audio and video parameters
    let audioBitrate = 256 * 1024
    let audioSampleRate = 48000
    let isStereo = true
    let videoFPS = 30
    let videoBitrate = 13500
    let iFrameInterval = 2
    let rotation = 0

    // Prepare audio and video
    if rtmpDisplay.prepareAudio(bitrate: audioBitrate, sampleRate: audioSampleRate, isStereo: isStereo) && rtspDisplay.prepareVideo(fps: videoFPS, bitrate: videoBitrate, iFrameInterval: iFrameInterval, rotation: rotation) {

        do {
            // Configure and activate the audio session
            try AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: [.defaultToSpeaker, .mixWithOthers])
            try AVAudioSession.sharedInstance().setActive(true)
        } catch {
            print("Failed to set audio session category: \(error)")
        }

        // Start the stream
        rtmpDisplay.startStream(endpoint: endpoint)
    } else {
        print("Failed to prepare audio or video.")
    }

}

here is my config. I tried few different configs but issue is constant.

when you go live on youtube and add rtmp url and stream key to startStream you will hear stuttering in live stream on youtube.

prikshitgupta commented 3 months ago

Hi @pedroSG94, Did you check the issue?

pedroSG94 commented 3 months ago

Hello,

I will start with this today

prikshitgupta commented 3 months ago

Hello,

I will start with this today

thank you

prikshitgupta commented 3 months ago

private func writeNaluSize(buffer: inout [UInt8], offset: Int, size: Int) { // Check if size is within the range of a 32-bit unsigned integer guard size <= UInt32.max else { fatalError("Size exceeds maximum value of a 32-bit unsigned integer") }

buffer[offset] = UInt8(size >> 24 & 0xFF)
buffer[offset + 1] = UInt8(size >> 16 & 0xFF)
buffer[offset + 2] = UInt8(size >> 8 & 0xFF)
buffer[offset + 3] = UInt8(size & 0xFF)

}

I Fixed this in RtmpH264Packet if you can implement it in next release library was making app crash

pedroSG94 commented 3 months ago

Hello,

Thank for the report but that fix will throw an error anyway. It is not a valid fix.

About the main issue. I was able to reproduce the audio issue and I'm working on it. Also, I added mute/unmute feature in the last commit: https://github.com/pedroSG94/RootEncoder-iOS/commit/cbf7c1f9edc5fcbafc97274124c5987fa890a3ec

prikshitgupta commented 3 months ago

Hello,

Thank for the report but that fix will throw an error anyway. It is not a valid fix.

About the main issue. I was able to reproduce the audio issue and I'm working on it. Also, I added mute/unmute feature in the last commit: cbf7c1f

great to hear mute option is here, waiting for youtube audio fix and if you fix the issue with writeNaluSize as well please

prikshitgupta commented 3 months ago

Hello,

Thank for the report but that fix will throw an error anyway. It is not a valid fix.

About the main issue. I was able to reproduce the audio issue and I'm working on it. Also, I added mute/unmute feature in the last commit: cbf7c1f

new update is not being fetched by SPM

pedroSG94 commented 3 months ago

Hello, Thank for the report but that fix will throw an error anyway. It is not a valid fix. About the main issue. I was able to reproduce the audio issue and I'm working on it. Also, I added mute/unmute feature in the last commit: cbf7c1f

new update is not being fetched by SPM

I just upload version 0.0.3 for the mute feature. (I was waiting until finish the fix for the audio)

prikshitgupta commented 3 months ago

Hello, Thank for the report but that fix will throw an error anyway. It is not a valid fix. About the main issue. I was able to reproduce the audio issue and I'm working on it. Also, I added mute/unmute feature in the last commit: cbf7c1f

new update is not being fetched by SPM

I just upload version 0.0.3 for the mute feature. (I was waiting until finish the fix for the audio)

i can download 0.0.3 now. Mute Unmute is working fine now.

prikshitgupta commented 3 months ago

i saw you fixed "[rtmp fix send video packets too large]"

but spm not showing any update

prikshitgupta commented 3 months ago

i saw you fixed "[rtmp fix send video packets too large]"

but spm not showing any update

Hi @pedroSG94 any update in this?

pedroSG94 commented 3 months ago

Hello,

I haven't done any uploads. I'm with the audio fix and I will upload a version after that.

prikshitgupta commented 3 months ago

Hello,

I haven't done any uploads. I'm with the audio fix and I will upload a version after that.

ok thank you

pedroSG94 commented 2 months ago

Hello,

I finally found the error about audio shuttering in YT but this fix breaks others features so it is not ready yet. I will report back when all is ready and I will upload a new version

prikshitgupta commented 2 months ago

Hello,

I finally found the error about audio shuttering in YT but this fix breaks others features so it is not ready yet. I will report back when all is ready and I will upload a new version

thank you for the update, i will be waiting

pedroSG94 commented 2 months ago

Fixed and uploaded. Try with version 0.0.4

prikshitgupta commented 2 months ago

still has same issue its less but when i speak it cracks the voice

pedroSG94 commented 2 months ago

ok, I will check again

pedroSG94 commented 2 months ago

Hello,

Check again, this should be working with version 0.0.5

prikshitgupta commented 2 months ago

working perfect now, thanks a ton.

fix below issue as well please

private func writeNaluSize(buffer: inout [UInt8], offset: Int, size: Int) { // Check if size is within the range of a 32-bit unsigned integer guard size <= UInt32.max else { fatalError("Size exceeds maximum value of a 32-bit unsigned integer") }

buffer[offset] = UInt8(size >> 24 & 0xFF) buffer[offset + 1] = UInt8(size >> 16 & 0xFF) buffer[offset + 2] = UInt8(size >> 8 & 0xFF) buffer[offset + 3] = UInt8(size & 0xFF) }

prikshitgupta commented 2 months ago

fixed, thank you so much 😊