Local RTSP to HLS Stream Conversion

Muhammad Azhar  Iqbal

Muhammad Azhar Iqbal

Expose Local RTSP to HLS Stream via Cloudflare Tunnel

This project converts an RTSP camera stream to HLS (HTTP Live Streaming) and exposes it online using a Cloudflare Tunnel.

Prerequisites

Node.js and npm/yarn installed
FFmpeg installed globally on your system
Cloudflare account with access to Zero Trust Tunnels
cloudflared CLI tool installed

Setup & Usage

1. Install Dependencies

yarn install
# or
npm install
Verify that FFmpeg is installed:
ffmpeg -version

2. Configure Your RTSP URL

Open package.json
Find the convert script
Replace the placeholder rtsp://<YOUR_RTSP_URL_HERE> with your actual RTSP camera URL

3. Convert RTSP to HLS

Run the conversion script to generate HLS files:
yarn convert
This will generate HLS files in the videos/ipcam/ directory.

4. Start the Local HTTP Server

Serve the HLS files locally with CORS support:
yarn read-server
The server will run on http://localhost:8080 by default.

5. Expose via Cloudflare Tunnel

Go to Cloudflare DashboardZero TrustTunnels
Select your tunnel or create a new one
Click Run Tunnel and copy the token
Run the tunnel locally:
cloudflared tunnel run --token <YOUR_TOKEN>

6. Access Your Stream

Once everything is running, access your HLS stream via the Cloudflare tunnel URL:
https://<your-tunnel-hostname>/index.m3u8

Project Structure

.
├── videos/
│ └── ipcam/ # HLS output files (.m3u8, .ts segments)
├── package.json # Project scripts and dependencies
└── README.md # This file

Notes

HLS files are stored in videos/ipcam/
Using --token is suitable for temporary sessions
For persistent tunnels, configure config.yml with credentials JSON
Ensure the Cloudflare tunnel points to the correct local HTTP server port (default: 8080)
Keep the yarn convert and yarn read-server processes running simultaneously

Troubleshooting

FFmpeg not found: Install FFmpeg and ensure it's in your system PATH
Port already in use: Change the port in your server configuration
Stream not accessible: Verify both the conversion script and HTTP server are running
Cloudflare tunnel issues: Check your tunnel configuration and token validity

License

This project is open source and available under the MIT License.
Like this project

Posted Dec 10, 2025

Converted and exposed an RTSP stream to HLS using Cloudflare Tunnel.