RTSP not working
Hello, I'm trying to play an RTSP link in exoPlayer. But I'm getting an error. The same link plays correctly in VLC.
Here's how I try to play in exoPlayer:
RtspMediaSource videoSource = new RtspMediaSource.Factory() .setDebugLoggingEnabled(true) .createMediaSource(MediaItem.fromUri(url)); exoPlayer.setMediaSource(videoSource); exoPlayer.prepare(); exoPlayer.setPlayWhenReady(true);
I get an error in the logs: androidx.media3.exoplayer.ExoPlaybackException: Source error Caused by: java.io.IOException: java.lang.IllegalArgumentException: bad base-64 Caused by: androidx.media3.exoplayer.rtsp.RtspMediaSource$RtspPlaybackException: java.lang.IllegalArgumentException: bad base-64 at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspResponse(RtspClient.java:701) at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspMessage(RtspClient.java:531) at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.lambda$onRtspMessageReceived$0$androidx-media3-exoplayer-rtsp-RtspClient$MessageListener(RtspClient.java:524)
Stream parameters: "rtsp://171.25.235.253/9ba7c5c359614d9394bace7c7947cea1" ffprobe version 7.0.1 Copyright (c) 2007-2024 the FFmpeg developers built with Apple clang version 15.0.0 (clang-1500.3.9.4) configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/7.0.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon libavutil 59. 8.100 / 59. 8.100 libavcodec 61. 3.100 / 61. 3.100 libavformat 61. 1.100 / 61. 1.100 libavdevice 61. 1.100 / 61. 1.100 libavfilter 10. 1.100 / 10. 1.100 libswscale 8. 1.100 / 8. 1.100 libswresample 5. 1.100 / 5. 1.100 libpostproc 58. 1.100 / 58. 1.100 [tcp @ 0x600003f0da70] No default whitelist set [tcp @ 0x600003f0da70] Original list of addresses: [tcp @ 0x600003f0da70] Address 171.25.235.253 port 554 [tcp @ 0x600003f0da70] Interleaved list of addresses: [tcp @ 0x600003f0da70] Address 171.25.235.253 port 554 [tcp @ 0x600003f0da70] Starting connection attempt to 171.25.235.253 port 554 [tcp @ 0x600003f0da70] Successfully connected to 171.25.235.253 port 554 [rtsp @ 0x13f605a70] SDP: v=0 o=- 1760166502488591 1 IN IP4 127.0.0.1 s=mpeg4 i=mpeg4 t=0 0 a=tool:Hankvision Server Media v2017.03.21 a=type:broadcast a=control:* a=range:npt=0- a=x-qt-text-nam:mpeg4 a=x-qt-text-inf:mpeg4 m=video 0 RTP/AVP 96 c=IN IP4 0.0.0.0 b=AS:2097 a=rtpmap:96 H264/90000 a=fmtp:96 packetization-mode=1;profile-level-id=4d002a;sprop-parameter-sets=Z00AKpY1QPAET8s3BQEFQAAAAwBAAAAMoQ==,aO4xsg==config=0000000167640028ad84054562b8ac5474202a2b15c562a3a1015158ae2b151d080a8ac57158a8e84054562b8ac5474202a2b15c562a3a10248521393c9f27e4fe4fc9f279b9b34d081242909c9e4f93f27f27e4f93cdcd9a6b403c0113f2ca9000003007800001c206040001312d000055d4bbdef85e1108d400000000168ee0000 a=x-dimensions: 1920, 1080 a=x-framerate: 25 a=control:track0
Failed to parse interval end specification '' [rtsp @ 0x13f605a70] video codec set to: h264 [rtsp @ 0x13f605a70] RTP Packetization Mode: 1 [rtsp @ 0x13f605a70] RTP Profile IDC: 4d Profile IOP: 0 Level: 2a [rtsp @ 0x13f605a70] Extradata set to 0x6000026040e0 (size: 37) [rtsp @ 0x13f605a70] setting jitter buffer size to 0 [rtsp @ 0x13f605a70] hello state=0 [h264 @ 0x1408046e0] nal_unit_type: 7(SPS), nal_ref_idc: 3 [h264 @ 0x1408046e0] nal_unit_type: 8(PPS), nal_ref_idc: 3 [h264 @ 0x1408046e0] Decoding VUI [h264 @ 0x1408046e0] nal_unit_type: 7(SPS), nal_ref_idc: 3 [h264 @ 0x1408046e0] nal_unit_type: 8(PPS), nal_ref_idc: 3 [h264 @ 0x1408046e0] Decoding VUI [h264 @ 0x1408046e0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 3 [h264 @ 0x1408046e0] Format yuvj420p chosen by get_format(). [h264 @ 0x1408046e0] Reinit context to 1920x1088, pix_fmt: yuvj420p [h264 @ 0x1408046e0] Frame num gap 22 20 [h264 @ 0x1408046e0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 3 Last message repeated 1 times [h264 @ 0x1408046e0] Decoding VUI [h264 @ 0x1408046e0] unknown SEI type 229 [h264 @ 0x1408046e0] nal_unit_type: 7(SPS), nal_ref_idc: 3 [h264 @ 0x1408046e0] nal_unit_type: 8(PPS), nal_ref_idc: 3 [h264 @ 0x1408046e0] nal_unit_type: 6(SEI), nal_ref_idc: 0 [h264 @ 0x1408046e0] nal_unit_type: 5(IDR), nal_ref_idc: 3 [h264 @ 0x1408046e0] Decoding VUI [h264 @ 0x1408046e0] unknown SEI type 229 [h264 @ 0x1408046e0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 3 Last message repeated 5 times [rtsp @ 0x13f605a70] first_dts 36000 not matching first dts NOPTS (pts NOPTS, duration 3600) in the queue [h264 @ 0x1408046e0] Decoding VUI [h264 @ 0x1408046e0] unknown SEI type 229 [rtsp @ 0x13f605a70] All info found Input #0, rtsp, from 'rtsp://171.25.235.253/9ba7c5c359614d9394bace7c7947cea1': Metadata: title : mpeg4 comment : mpeg4 Duration: N/A, start: 0.040000, bitrate: N/A Stream #0:0, 31, 1/90000: Video: h264 (Main), 1 reference frame, yuvj420p(pc, bt470bg/bt470bg/bt709, progressive, left), 1920x1080, 0/1, 25 fps, 25 tbr, 90k tbn [h264 @ 0x1408046e0] nal_unit_type: 7(SPS), nal_ref_idc: 3 [h264 @ 0x1408046e0] nal_unit_type: 8(PPS), nal_ref_idc: 3 [h264 @ 0x1408046e0] Decoding VUI
What could be the problem? Thank you.
@Anatolf
Hi, it would be helpful if you could share a full bug report! This way I can take a look at the full stack trace rather than your little snippet. If you cannot send it publicly, please send them to [email protected] with the subject Issue #2841. Please also update this issue to indicate you've done this.
My guess is that there is something wrong with the contents that are Base-64 encoded in the RTSP Response of your server. It may be that VLC is more lenient.
If you could provide a publicly available URI for your RTSP Server then that would make it a lot easier for us to assist as well. If you cannot send it publicly then you can send the url to [email protected] with the subject Issue #2841 as well.
This is an open link, you can check it yourself: 'rtsp://171.25.235.253/9ba7c5c359614d9394bace7c7947cea1'
Here is the error in full stack trace:
Playback error androidx.media3.exoplayer.ExoPlaybackException: Source error at androidx.media3.exoplayer.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:927) at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:903) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:85) Caused by: java.io.IOException: java.lang.IllegalArgumentException: bad base-64 at androidx.media3.exoplayer.rtsp.RtspMediaPeriod$InternalListener.onSessionTimelineRequestFailed(RtspMediaPeriod.java:697) at androidx.media3.exoplayer.rtsp.RtspClient.dispatchRtspError(RtspClient.java:334) at androidx.media3.exoplayer.rtsp.RtspClient.access$700(RtspClient.java:76) at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspResponse(RtspClient.java:701) at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspMessage(RtspClient.java:531) at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.lambda$onRtspMessageReceived$0$androidx-media3-exoplayer-rtsp-RtspClient$MessageListener(RtspClient.java:524) at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) at android.os.Handler.handleCallback(Handler.java:959) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:85) Caused by: androidx.media3.exoplayer.rtsp.RtspMediaSource$RtspPlaybackException: java.lang.IllegalArgumentException: bad base-64 at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspResponse(RtspClient.java:701) at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspMessage(RtspClient.java:531) at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.lambda$onRtspMessageReceived$0$androidx-media3-exoplayer-rtsp-RtspClient$MessageListener(RtspClient.java:524) at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) at android.os.Handler.handleCallback(Handler.java:959) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:85)
@Anatolf
Thank you. When I attempted to connect myself I saw additional pieces in the stack trace as follows:
Caused by: java.io.IOException: java.lang.IllegalArgumentException: bad base-64
at androidx.media3.exoplayer.rtsp.RtspMediaPeriod$InternalListener.onSessionTimelineRequestFailed(RtspMediaPeriod.java:696)
at androidx.media3.exoplayer.rtsp.RtspClient.dispatchRtspError(RtspClient.java:333)
at androidx.media3.exoplayer.rtsp.RtspClient.access$700(RtspClient.java:75)
at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspResponse(RtspClient.java:700)
at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspMessage(RtspClient.java:530)
at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.lambda$onRtspMessageReceived$0$androidx-media3-exoplayer-rtsp-RtspClient$MessageListener(RtspClient.java:523)
at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
at android.os.Handler.handleCallback(Handler.java:1070)
at android.os.Handler.dispatchMessage(Handler.java:125)
... 4 more
Caused by: androidx.media3.exoplayer.rtsp.RtspMediaSource$RtspPlaybackException: java.lang.IllegalArgumentException: bad base-64
... 10 more
Caused by: java.lang.IllegalArgumentException: bad base-64
at android.util.Base64.decode(Base64.java:164)
at android.util.Base64.decode(Base64.java:139)
at android.util.Base64.decode(Base64.java:121)
at androidx.media3.exoplayer.rtsp.RtspMediaTrack.getInitializationDataFromParameterSet(RtspMediaTrack.java:384)
at androidx.media3.exoplayer.rtsp.RtspMediaTrack.processH264FmtpAttribute(RtspMediaTrack.java:411)
at androidx.media3.exoplayer.rtsp.RtspMediaTrack.generatePayloadFormat(RtspMediaTrack.java:277)
at androidx.media3.exoplayer.rtsp.RtspMediaTrack.<init>(RtspMediaTrack.java:174)
at androidx.media3.exoplayer.rtsp.RtspClient.buildTrackList(RtspClient.java:365)
at androidx.media3.exoplayer.rtsp.RtspClient.access$1700(RtspClient.java:75)
at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.onDescribeResponseReceived(RtspClient.java:734)
at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspResponse(RtspClient.java:640)
... 9 more
Your RTSP stream is failing because it is providing malformed values necessary for H264 decoding. I believe that the reason why it works for VLC is because they can get the decoder initialization values from within the stream. Perhaps those values are correctly encoded compared to the values we are seeing in the transport layer.
We have not implemented in-stream sprop processing for RTSP H264 or H265 streaming yet. I can update this ticket when that occurs.
For now I'd suggest filing an issue with the RTSP server/camera company. They should fix the sprop values they are sending in the transport layer of the stream. My last suggestion would be to try adjusting the RTSP server/camera to stream in a different encoding, like H265.
Thank you. Yes, please update this ticket when in-stream sprop processing appears in the ExoPlayer.
Hey @Anatolf. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!