androidreact-nativewebrtcvideo-streamingrtsp

How to Convert WebRTC MediaStream to RTSP in Real-Time for React Native VLC Player?


I am working on a React Native 0.78 app and using WebRTC for peer-to-peer (P2P) video streaming. I successfully set up a WebRTC connection and received a WebRTC stream as a MediaStream (MediaTrack format).

The problem is that I want to play this WebRTC stream using the React Native VLC media player (react-native-vlc-media-player), but the player only accepts URL-based streams (like RTSP or HTTP). My WebRTC stream does not have a URL, so I can't play it directly.

Why I Need RTSP?

What I Need Help With:

  1. How can I create a React Native native module in Java to convert a WebRTC MediaStream into an RTSP stream in real time?

  2. How can I manage multiple WebRTC streams and generate unique RTSP URLs for each?

I appreciate any help, sample code, or guidance on how to achieve this. Thanks!


Solution

  • No conversion is needed now.

    Google's official Chromium documentation mentions that H.265 support in WebRTC is currently in development. It has been released under 'Implemented behind flags' status: Chromium Feature.

    This feature can be enabled using the following command:

    For macOS:

    open -a "Google Chrome" --args --enable-features=WebRtcAllowH265Send,WebRtcAllowH265Receive --force-fieldtrials=WebRTC-Video-H26xPacketBuffer/Enabled/
    

    For Windows:

    start chrome --enable-features=WebRtcAllowH265Send,WebRtcAllowH265Receive --force-fieldtrials=WebRTC-Video-H26xPacketBuffer/Enabled/
    

    For Android: I used the WebView implementation to switch from Android System WebView (M134) to Android System WebView Dev (M136). It works perfectly, but the switch has to be done manually.

    Chromium M136 stable release: Tue, Apr 29, 2025 Chromium.