media icon indicating copy to clipboard operation
media copied to clipboard

Make sprop-parameter-sets optional for RTSP H.264 streams

Open bartwell opened this issue 10 months ago • 1 comments

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:

  1. Parsing SPS/PPS from the actual stream (like VLC does).
  2. Providing an option to bypass the strict check, allowing ExoPlayer to extract SPS/PPS from IDR frames.

Proposed Solutions

  1. Make sprop-parameter-sets optional and allow ExoPlayer to extract SPS/PPS dynamically from incoming NAL units.
  2. Introduce a setting or flag (e.g., RtspConfig.allowDynamicSPSPPS) that enables support for streams without sprop-parameter-sets.

Steps to Reproduce

  1. Stream an H.264 RTSP feed without sprop-parameter-sets in SDP.
  2. Try to play it using ExoPlayer with RtspMediaSource.
  3. Observe that ExoPlayer fails due to missing sprop parameter.
  4. Apply the workaround (setWidth(192).setHeight(108)) and see that ExoPlayer plays the stream correctly and later reports the correct resolution via onVideoSizeChanged.

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!

bartwell avatar Mar 05 '25 12:03 bartwell

I’m facing the same issue on several Chinese RTSP cameras (including Hikvision-based models)

0xtun4 avatar Nov 24 '25 10:11 0xtun4