If you are developing computer vision models, building a Video Management System (VMS), or writing OpenCV scripts, you often need a reliable RTSP stream to test your code. Instead of buying physical IP cameras, the easiest method is to stream a pre-recorded MP4 file over the network as an RTSP feed.
In this guide, we will cover three ways to achieve this: using FFmpeg, using VLC, and using a modern cloud-based approach that requires zero configuration.
Method 1: The Hard Way (FFmpeg)
FFmpeg is the swiss-army knife of video processing. To use it for RTSP streaming, you first need to run an RTSP server locally (like MediaMTX), and then use FFmpeg to push your MP4 file to that server.
Assuming you have your server running on localhost:8554, open your terminal and run this command:
ffmpeg -re -stream_loop -1 -i sample.mp4 -c copy -f rtsp rtsp://localhost:8554/mystream
What this does:
-re: Reads the input at its native frame rate (crucial for streaming, otherwise it processes it as fast as possible).-stream_loop -1: Loops the video infinitely so your stream doesn't end abruptly.-c copy: Copies the video codec without re-encoding, saving CPU.
The downside? Setting up the RTSP server locally, managing firewalls, and dealing with FFmpeg's tendency to crash during infinite loops can be frustrating.
Method 2: The UI Way (VLC Media Player)
If you don't like terminal commands, VLC has a built-in RTSP server capability.
- Open VLC and go to Media > Stream... (Ctrl+S).
- Click Add and select your MP4 file. Click Stream.
- Click Next, and in the "New destination" dropdown, select RTSP and click Add.
- Set the port (e.g., 8554) and the path (e.g.,
/test). - Uncheck "Activate Transcoding" (to save CPU) and click Stream.
Your stream is now available locally at rtsp://127.0.0.1:8554/test.
The downside? VLC's streaming server is notoriously unstable for long periods. If the video reaches the end, looping it gracefully over RTSP often causes client disconnections or frozen frames.
Method 3: The Easy Way (illucam)
If you just want a reliable RTSP URL instantly so you can get back to writing your actual code, the best option is illucam.
illucam is a cloud-based platform designed specifically to turn MP4 files into robust RTSP streams.
- Go to illucam.com and log in.
- Drag and drop your MP4 file into the dashboard.
- Copy your secure
rtsp://URL.
That's it. The stream is hosted in the cloud, loops infinitely without crashing, and can be accessed from any computer or server without messing with NAT forwarding or firewalls.
Stop Fighting with FFmpeg Scripts
Get a stable, looping RTSP stream from your MP4 file in under 30 seconds.
Stream Your MP4 Now