Make sprop-parameter-sets optional for RTSP H.264 streams
Hello Media3/ExoPlayer team,
I have an RTSP stream from a device that does not include the sprop-parameter-sets attribute in the SDP response. However, the stream works perfectly in VLC, as VLC extracts the SPS/PPS from the first IDR frame.
Currently, ExoPlayer fails to parse such streams because processH264FmtpAttribute(formatBuilder, fmtpParameters) in RtspMediaTrack.java enforces sprop-parameter-sets as mandatory and throws an exception if it is missing:
case MimeTypes.VIDEO_H264:
checkArgument(!fmtpParameters.isEmpty(), "missing attribute fmtp");
processH264FmtpAttribute(formatBuilder, fmtpParameters);
break;
However, if I manually set a dummy resolution in RtspMediaTrack.java (instead of calling processH264FmtpAttribute), the stream works fine, and ExoPlayer later detects the correct video resolution through onVideoSizeChanged:
case MimeTypes.VIDEO_H264:
checkArgument(!fmtpParameters.isEmpty(), "missing attribute fmtp");
// processH264FmtpAttribute(formatBuilder, fmtpParameters); // Removed
formatBuilder
.setWidth(192)
.setHeight(108);
break;
With this modification, ExoPlayer successfully plays the stream, and onVideoSizeChanged provides the correct resolution. Here’s the code I used to verify it:
player.addListener(new Player.Listener() {
@Override
public void onVideoSizeChanged(VideoSize videoSize) {
int width = videoSize.width;
int height = videoSize.height;
Log.d("RTSP", "Current resolution: " + width + "x" + height);
}
});
This prints:
D/RTSP: Current resolution: 1280x720
This means that ExoPlayer is capable of determining the resolution dynamically, just like VLC, but it currently fails due to the strict sprop-parameter-sets check.
Expected Behavior
ExoPlayer should allow RTSP streams even if sprop-parameter-sets is missing, by:
- Parsing SPS/PPS from the actual stream (like VLC does).
- Providing an option to bypass the strict check, allowing ExoPlayer to extract SPS/PPS from IDR frames.
Proposed Solutions
-
Make
sprop-parameter-setsoptional and allow ExoPlayer to extract SPS/PPS dynamically from incoming NAL units. -
Introduce a setting or flag (e.g.,
RtspConfig.allowDynamicSPSPPS) that enables support for streams withoutsprop-parameter-sets.
Steps to Reproduce
- Stream an H.264 RTSP feed without
sprop-parameter-setsin SDP. - Try to play it using ExoPlayer with
RtspMediaSource. - Observe that ExoPlayer fails due to
missing sprop parameter. - Apply the workaround (
setWidth(192).setHeight(108)) and see that ExoPlayer plays the stream correctly and later reports the correct resolution viaonVideoSizeChanged.
Environment
-
ExoPlayer Version: Media3
1.5.1 - Device: [Confidential due to NDA]
-
Android Version:
14 - Stream URL: [Confidential due to NDA]
Additional Notes
- VLC works fine with the same RTSP stream.
- Other RTSP libraries have not been tested.
Could you please consider making sprop-parameter-sets optional or adding an option to disable this strict check? This would improve compatibility with real-world RTSP cameras and streams.
Thank you!
I’m facing the same issue on several Chinese RTSP cameras (including Hikvision-based models)