pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.57k stars 778 forks source link

Invalid NAL unit size with ZLMediaKit #1648

Open Lyman92 opened 5 days ago

Lyman92 commented 5 days ago

Hello,

I use RtspStream to push android screen and microphone to rtsp server (we use ZLMediaKit as server site) my android code:

rtspStream = new RtspStream(getBaseContext(), this, new NoVideoSource(), new MicrophoneSource());
rtspStream.getStreamClient().setReTries(10);
rtspStream.getStreamClient().setLogs(true);
rtspStream.getGlInterface().setForceRender(true, FPS);
rtspStream.setAudioCodec(AudioCodec.AAC);
rtspStream.setTimestampMode(TimestampMode.BUFFER, TimestampMode.BUFFER);
prepared = rtspStream.prepareVideo(capSize.getWidth(), capSize.getHeight(), vBitrate, FPS, IFRAME_INTERVAL, rotation) &&
                    rtspStream.prepareAudio(sampleRate, isStereo, aBitrate, true, true);
rtspStream.getGlInterface().setCameraOrientation(0);
rtspStream.changeVideoSource(screenSource);
rtspStream.changeAudioSource(new MicrophoneSource());
rtspStream.startStream(endpoint);

our admin site will play and record the video and audio via ZLMediaKit , video and audio will be transformed to ws protocol as below ws://192.168.110.220:6060/rtp/41280175262397976495_41280175262397976495.live.flv we cannot see the video but can hear the sound from the stream.

The browser console loged as below Jessibuca: [worker]: [h264 @ 0x6bda30] Invalid NAL unit size (0 > 117492). Jessibuca: [worker]: [h264 @ 0x6bda30] Error splitting the input into NAL units.

the stream can be played well with vlc player by the rtsp protocol.

We cannot find other solussions. Any idea or suggestions for us? Thank you so much.

pedroSG94 commented 5 days ago

If VLC can reproduce it using RTSP the problem should be in the transformation to ws or the player. Can you see the video using VLC and ws? Did you try using H265?

Lyman92 commented 1 day ago

If I use H265, The app throws an exception

FATAL EXCEPTION: VideoEncoder
Process: com.openfire.app, PID: 7738
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.nio.ByteBuffer.remaining()' on a null object reference
    at com.pedro.encoder.video.VideoEncoder.extractVpsSpsPpsFromH265(VideoEncoder.java:427)
    at com.pedro.encoder.video.VideoEncoder.sendSPSandPPS(VideoEncoder.java:332)
    at com.pedro.encoder.video.VideoEncoder.formatChanged(VideoEncoder.java:512)
    at com.pedro.encoder.BaseEncoder$1.onOutputFormatChanged(BaseEncoder.java:315)
    at android.media.MediaCodec$EventHandler.handleCallback(MediaCodec.java:1810)
    at android.media.MediaCodec$EventHandler.handleMessage(MediaCodec.java:1705)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:223)
    at android.os.HandlerThread.run(HandlerThread.java:67)
pedroSG94 commented 15 hours ago

Hello,

I fixed that error here: https://github.com/pedroSG94/RootEncoder/commit/e7d23da2aaf8ff8b9bcda96c303b25a1a51acbdf

Did you try to reproduce the stream using ws with VLC to discard that the problem is in the player?

Lyman92 commented 8 hours ago

VLC can't play the stream using ws. I tried H265 and works on my phone and some Android TV. But some of my Android TV do not support H265 encoding ( prepareVideo return false )