Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RtmpClient H265 stream error: Broken pipe #1311

Closed
sheng930920 opened this issue Oct 25, 2023 · 14 comments
Closed

RtmpClient H265 stream error: Broken pipe #1311

sheng930920 opened this issue Oct 25, 2023 · 14 comments

Comments

@sheng930920
Copy link

When using RtmpClient to push DJI drone H265 video stream data, RtmpSender error java.net.SocketException: Broken pipe, actually my network is available normally

The version information is as follows

implementation 'com.github.pedroSG94.RootEncoder:library:2.3.1'

SRS Server
image

Below is the code I tested

class RtmpPublisher private constructor() : ConnectCheckerRtmp, StreamDataListener {

    private val rtmpUrl = "rtmp://192.168.160.106:1935/live/3455"
    private val mVideoInfo = MediaCodec.BufferInfo()
    private val mRtmpClient by lazy {
        RtmpClient(this).apply {
            setOnlyVideo(true)
            setReTries(Integer.MAX_VALUE)
            setFps(30)
            resizeCache(10 * 1024)
            setProfileIop(ProfileIop.BASELINE)
            setLogs(true)
        }
    }

    fun startLiveStream() {
        MediaDataCenter.getInstance().videoStreamManager.getAvailableVideoChannel(VideoChannelType.PRIMARY_STREAM_CHANNEL)?.let { primaryChannel ->
            primaryChannel.addStreamDataListener(this)
        }
    }

    override fun onReceive(videoFrame: IVideoFrame) {
        mVideoInfo.size = videoFrame.data.size
        mVideoInfo.offset = 0
        mVideoInfo.presentationTimeUs = System.nanoTime() / 1000
        mVideoInfo.flags = MediaCodec.BUFFER_FLAG_PARTIAL_FRAME

        if (videoFrame.isIFrame && !mRtmpClient.isStreaming) {
            mVideoInfo.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME
            val result = decodeSpsPpsFromByteArray(videoFrame.data)
            mRtmpClient.setVideoInfo( ByteBuffer.wrap(result.first),  ByteBuffer.wrap(result.second),  ByteBuffer.wrap(result.third))
            mRtmpClient.connect(rtmpUrl, true)
        }
        if (mRtmpClient.isStreaming) {
            mRtmpClient.sendVideo(ByteBuffer.wrap(videoFrame.data), mVideoInfo)
        }
    }

    override fun onAuthErrorRtmp() {

    }

    override fun onAuthSuccessRtmp() {
    }

    override fun onConnectionFailedRtmp(reason: String) {
        LogUtils.e(TAG, reason)
        mRtmpClient.reConnect(200L)
    }

    override fun onConnectionStartedRtmp(rtmpUrl: String) {
    }

    override fun onConnectionSuccessRtmp() {
    }

    override fun onDisconnectRtmp() {
    }

    override fun onNewBitrateRtmp(bitrate: Long) {
    }

    private fun decodeSpsPpsFromByteArray(videoByteArray: ByteArray): Triple<ByteArray, ByteArray, ByteArray> {
        var spsIndex = -1
        var ppsIndex = -1
        var vpsIndex = -1
        var ppsEndIndex = -1

        var index = 0
        while (index + 3 < videoByteArray.size) {
            if (videoByteArray[index].toInt() == 0x00 &&
                videoByteArray[index + 1].toInt() == 0x00 &&
                videoByteArray[index + 2].toInt() == 0x00 &&
                videoByteArray[index + 3].toInt() == 0x01
            ) {
                val nalType = (videoByteArray[index + 4].toInt() and 0x7E) ushr 1
                println("nalType: $nalType")
                when(nalType) {
                    // VPS
                    32 -> vpsIndex = index
                    // SPS
                    33 -> spsIndex = index
                    // PPS
                    34 -> ppsIndex = index
                    // PPS
                    20 -> {
                        ppsEndIndex = index
                        break
                    }
                }
            }
            index++
        }
        println("vpsIndex: $vpsIndex  spsIndex:$spsIndex   ppsIndex:$ppsIndex")

        val vpsLength = spsIndex - vpsIndex
        val spsLength = ppsIndex - spsIndex
        val ppsLength = ppsEndIndex - ppsIndex

        val vps = ByteArray(vpsLength).apply {
            System.arraycopy(videoByteArray, vpsIndex, this, 0, vpsLength)
        }
        val sps = ByteArray(spsLength).apply {
            System.arraycopy(videoByteArray, spsIndex, this, 0, spsLength)
        }
        val pps = ByteArray(ppsLength).apply {
            System.arraycopy(videoByteArray, ppsIndex, this, 0, ppsLength)
        }
        return Triple(vps, sps, pps)
    }


    companion object {

        const val TAG: String = "RtmpPublisher"

        @Volatile
        private var instance: RtmpPublisher? = null

        fun getInstance(): RtmpPublisher {
            return instance ?: synchronized(this) {
                instance ?: RtmpPublisher().also { instance = it }
            }
        }
    }
}
```java


Below is the error log
```java
2023-10-25 18:17:32.083 26928-27547/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:32.083 26928-27547/com.shd.nest I/RtmpSender: wrote Video packet, size 50132
2023-10-25 18:17:32.652 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:32.653 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 46181
2023-10-25 18:17:32.685 26928-27168/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:33.182 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:33.183 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 36584
2023-10-25 18:17:33.220 26928-27168/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:33.752 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:33.753 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 37162
2023-10-25 18:17:33.786 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 37076
2023-10-25 18:17:33.820 26928-27272/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:34.320 26928-27168/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:34.321 26928-27168/com.shd.nest I/RtmpSender: wrote Video packet, size 36861
2023-10-25 18:17:34.352 26928-27272/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:34.819 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:34.820 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 38020
2023-10-25 18:17:34.853 26928-27272/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:35.355 26928-27169/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:35.356 26928-27169/com.shd.nest I/RtmpSender: wrote Video packet, size 37778
2023-10-25 18:17:35.387 26928-27273/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:36.021 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:36.021 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 37857
2023-10-25 18:17:36.054 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 37549
2023-10-25 18:17:36.092 26928-27169/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:36.553 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:36.553 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 37667
2023-10-25 18:17:36.587 26928-27547/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:37.156 26928-27547/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:37.157 26928-27547/com.shd.nest I/RtmpSender: wrote Video packet, size 39427
2023-10-25 18:17:37.194 26928-27274/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:37.724 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:37.725 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 40607
2023-10-25 18:17:38.429 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:38.430 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 38405
2023-10-25 18:17:38.457 26928-27274/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:38.991 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:38.992 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 38205
2023-10-25 18:17:39.026 26928-27169/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:39.493 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:39.494 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 42563
2023-10-25 18:17:39.527 26928-27273/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:39.995 26928-27547/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:39.996 26928-27547/com.shd.nest I/RtmpSender: wrote Video packet, size 44643
2023-10-25 18:17:40.028 26928-27273/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:40.528 26928-27169/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:40.528 26928-27169/com.shd.nest I/RtmpSender: wrote Video packet, size 50187
2023-10-25 18:17:41.095 26928-27547/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:41.095 26928-27547/com.shd.nest I/RtmpSender: wrote Video packet, size 50173
2023-10-25 18:17:41.128 26928-27273/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:41.662 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:41.663 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 44816
2023-10-25 18:17:41.696 26928-27547/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:42.195 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:42.196 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 37312
2023-10-25 18:17:42.228 26928-27274/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:42.796 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:42.796 26928-27274/com.shd.nest I/RtmpSender: wrote Video packet, size 37032
2023-10-25 18:17:42.831 26928-27168/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:43.296 26928-27168/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:43.298 26928-27168/com.shd.nest I/RtmpSender: wrote Video packet, size 38953
2023-10-25 18:17:43.330 26928-27273/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:43.830 26928-27272/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:43.831 26928-27272/com.shd.nest I/RtmpSender: wrote Video packet, size 35245
2023-10-25 18:17:43.862 26928-27272/com.shd.nest I/RtmpSender: wrote Video packet, size 36409
2023-10-25 18:17:43.896 26928-27272/com.shd.nest I/RtmpSender: wrote Video packet, size 37541
2023-10-25 18:17:43.930 26928-27547/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:44.395 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:44.395 26928-27273/com.shd.nest I/RtmpSender: wrote Video packet, size 38678
2023-10-25 18:17:44.431 26928-27547/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2023-10-25 18:17:44.896 26928-27168/com.shd.nest I/RtmpSender: wrote Video packet, size 104
2023-10-25 18:17:44.896 26928-27168/com.shd.nest I/RtmpSender: wrote Video packet, size 41196
2023-10-25 18:17:44.931 26928-27547/com.shd.nest E/RtmpSender: send error: 
    java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        at com.pedro.rtmp.rtmp.message.RtmpMessage.writeBody(RtmpMessage.kt:130)
        at com.pedro.rtmp.rtmp.CommandsManager.sendVideoPacket(CommandsManager.kt:208)
        at com.pedro.rtmp.rtmp.RtmpSender$start$1.invokeSuspend(RtmpSender.kt:156)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
        at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)

```java
@pedroSG94
Copy link
Owner

Hello,

I detected 2 fails that could be the reason because youur server close connection.
If you are using H265 you must set the video codec to the RtmpClient like this:

mRtmpClient.setVideoCodec(VideoCodec.H265)

Also here:

mRtmpClient.connect(rtmpUrl, true)

Replace to:

mRtmpClient.connect(rtmpUrl)

@pedroSG94
Copy link
Owner

pedroSG94 commented Oct 25, 2023

You have other error here:

        if (videoFrame.isIFrame && !mRtmpClient.isStreaming) {
            mVideoInfo.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME

The flag (only the flag) must be changed in each keyframe not only on first keyframe. This is not totally required but I recommend you do it

@sheng930920
Copy link
Author

sheng930920 commented Oct 26, 2023

Thanks for the reply and suggestions. Now I can push the H265 video stream to the SRS streaming server normally. However, I found that it cannot be played. I would like to ask if there is something wrong. Or is the data of sps and pps abnormal?

private fun decodeSpsPpsFromByteArray(videoByteArray: ByteArray): Triple<ByteArray, ByteArray, ByteArray> {
        var spsIndex = -1
        var ppsIndex = -1
        var vpsIndex = -1
        var ppsEndIndex = -1

        var index = 0
        while (index + 3 < videoByteArray.size) {
            if (videoByteArray[index].toInt() == 0x00 &&
                videoByteArray[index + 1].toInt() == 0x00 &&
                videoByteArray[index + 2].toInt() == 0x00 &&
                videoByteArray[index + 3].toInt() == 0x01
            ) {
                val nalType = (videoByteArray[index + 4].toInt() and 0x7E) ushr 1
                println("nalType: $nalType")
                when(nalType) {
                    // VPS
                    32 -> vpsIndex = index
                    // SPS
                    33 -> spsIndex = index
                    // PPS
                    34 -> ppsIndex = index
                    // PPS
                    20 -> {
                        ppsEndIndex = index
                        break
                    }
                }
            }
            index++
        }
        println("vpsIndex: $vpsIndex  spsIndex:$spsIndex   ppsIndex:$ppsIndex")

        val vpsLength = spsIndex - vpsIndex
        val spsLength = ppsIndex - spsIndex
        val ppsLength = ppsEndIndex - ppsIndex

        val vps = ByteArray(vpsLength).apply {
            System.arraycopy(videoByteArray, vpsIndex, this, 0, vpsLength)
        }
        val sps = ByteArray(spsLength).apply {
            System.arraycopy(videoByteArray, spsIndex, this, 0, spsLength)
        }
        val pps = ByteArray(ppsLength).apply {
            System.arraycopy(videoByteArray, ppsIndex, this, 0, ppsLength)
        }

        println("VPS: ${vps.joinToString(", ")}")
        println("SPS: ${sps.joinToString(", ")}")
        println("PPS: ${pps.joinToString(", ")}")

        return Triple(sps, pps, vps)
    }

The following is the sps and pps data I printed on the logcat console

VPS: 0, 0, 0, 1, 64, 1, 12, 1, -1, -1, 1, 64, 0, 0, 3, 0, -128, 0, 0, 3, 0, 0, 3, 0, 120, -84, 12, 0, 0, 15, -96, 0, 1, -44, -62, 0, -6, 40
SPS: 0, 0, 0, 1, 66, 1, 1, 1, 64, 0, 0, 3, 0, -128, 0, 0, 3, 0, 0, 3, 0, 120, -96, 2, -48, -128, 16, -25, -6, 46, -20, -111, 119, -94, 93, 88, 16, 0, 0, 62, -128, 0, 7, 83, 12, 64
PPS: 0, 0, 0, 1, 68, 1, -63, -83, -16, 19, 100

The following text content is the data of I frame. The data of sps, pps and vps are all obtained here.
IFrame.txt

image

@pedroSG94
Copy link
Owner

Hello,

Your vps, sps and pps method look fine. You can try this:

  • Reproduce your stream in other format like HLS using ffmpeg or VLC. It is because this players don't support rtmp with h265 codec (at least it was the case when I added this to the library).
  • If the problem persist try with other server like MediaMTX. This is to discard problems with your SRS server version, if the problem is solved using MediaMTX and a player with HLS we can focus on server compatibility

@sheng930920
Copy link
Author

sheng930920 commented Oct 26, 2023

When I try to push the video stream to the MediaMTX streaming server, the push stream is normal, but it still cannot be played using ffplay and VLC players. I see the console output exception message: the stream doesn't contain any supported codec, which are currently H264, MPEG-4 Audio, MPEG-1/2 Audio
image

@pedroSG94
Copy link
Owner

Please, try to open url using RTSP or HLS instead of RTMP in player side. It is because RTMP H265 is not supported in player side.
Like this:

ffplay rtsp://ip:port/appname/streamname

@sheng930920
Copy link
Author

The player uses RTSP or HLS to play the H265 video stream, but the test results are still not good.

The following is tested using the ffplay command and VLC player
image
image
image

Below is Google Chrome to test hls link playback, but the result is that it cannot be played.
image
image

@sheng930920
Copy link
Author

Using ffplay settings to force the video to use h265 decoding, the result is the same error

image

@pedroSG94
Copy link
Owner

Hello,

Try with ffplay with this command:

ffplay -rtsp_transport tcp rtsp://192.168.0.99:8554/live/3455

Also, make sure that you set video resolution to rtmpClient correctly like this:

rtmpClient.setVideoResolution(width, height);

@sheng930920
Copy link
Author

The H265 video resolution is correctly set in the code. I use the ffplay command to play the rtsp link and I don’t see any error log output, but I still can’t see the real video screen.

ffplay -rtsp_transport tcp rtsp://192.168.0.99:8554/live/3455
override fun onReceive(videoFrame: IVideoFrame) {
        mVideoInfo.apply {
            size = videoFrame.data.size
            offset = 0
            presentationTimeUs = System.nanoTime() / 1000
            flags = if (videoFrame.isIFrame) MediaCodec.BUFFER_FLAG_KEY_FRAME else 0
        }
        mRtmpClient.setVideoResolution(videoFrame.width, videoFrame.height)

        if (videoFrame.isIFrame && !mRtmpClient.isStreaming) {
            decodeSpsPpsFromByteArray(videoFrame.data)?.let { result ->
                mRtmpClient.setVideoInfo(ByteBuffer.wrap(result.first),  ByteBuffer.wrap(result.second),  ByteBuffer.wrap(result.third))
                mRtmpClient.connect(rtmpUrl, true)
            }
        }
        if (mRtmpClient.isStreaming) {
            mRtmpClient.sendVideo(ByteBuffer.wrap(videoFrame.data), mVideoInfo)
        }
    }

image

image

@pedroSG94
Copy link
Owner

This is weird. Now, I can't see any error

Do you have a way to test using H264 instead H265 to discard that we are doing something bad no related with the codec?

According with others posts h264 should work with DJI

@sheng930920
Copy link
Author

When I use an old DJI drone to obtain H264 video stream data for live streaming, everything is normal and the video can be played back. Currently, DJI V5 MSDK and new models of drones can only obtain H265 video data.

@pedroSG94
Copy link
Owner

I see,

Can you check if you get keyframes continuously and get nalu type of that frames?
Maybe the player can't start stream because something is wrong with keyframes (a player normally start to reproduce after receive a keyframe because this contains video info).
You can check how to get nalu type here:
https://github.com/pedroSG94/RootEncoder/blob/master/rtmp/src/main/java/com/pedro/rtmp/flv/video/H265Packet.kt#L110
Basically apply this line to the first byte after the byte prefix "00 00 00 01" and show the result (do it with all buffers)

Also, I have a last bullet but this means that we need write a code that could be difficult:
Do you have a method to decode frames rendering a surface?
We can try decode frames and reencode it to get buffers using VideoEncoder class.

@pedroSG94
Copy link
Owner

Closing as inactive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants