top of page

RTSP to HLS repacking service

RTSP to HLS

RTSP (Real-Time Streaming Protocol) is widely used for live video streaming, especially in IP cameras and surveillance systems. However, RTSP isn't natively supported by most web browsers, making it less versatile for modern applications. On the other hand, HLS (HTTP Live Streaming) is a browser-friendly protocol supported across devices and platforms. By leveraging FFmpeg and Nginx, you can efficiently repack RTSP streams into HLS for seamless streaming. Here's how this powerful duo works.


What is FFmpeg?

FFmpeg is a robust multimedia framework capable of processing, converting, and streaming audio and video in various formats. It plays a crucial role in transforming RTSP streams into HLS playlists ( .m3u8 ).


What is Nginx?

Nginx is a high-performance web server and reverse proxy that serves as the delivery mechanism for the HLS files generated by FFmpeg. It ensures efficient file hosting, supports cross-origin requests, and scales to handle many simultaneous viewers.



How FFmpeg Helps Repack RTSP to HLS


FFmpeg repackages the RTSP stream into the HLS format without re-encoding, which saves computational resources and reduces latency.


Use FFmpeg to process the RTSP input and generate HLS segments.


Example Command: 

ffmpeg -i rtsp://admin:Multimedia@10.14.25.151:8554/ch01 \
       -c:v copy -c:a copy -f hls -hls_time 1 -hls_list_size 6 \
       -hls_time 1 -hls_list_size 6 -hls_flags delete_segments \
       /var/www/streams/AV05SD082a.m3u8

Key Parameters:


  • -c:v copy: Copies the video codec without re-encoding.

  • -c:a copy:  Copies the audio codec without re-encoding.

  • -hls_time: Sets the duration (in seconds) of each HLS segment.

  • -hls_list_size: Defines the number of segments in the playlist.


FFmpeg continuously processes the RTSP stream and generates a live .m3u8 playlist media segments.



How Nginx Serves HLS Streams


Nginx acts as the web server that delivers the HLS files to clients. Configure Nginx to serve HLS files with CORS support.


Configuration File Location: /etc/nginx/sites-enabled/strapi.conf


Sample Configuration:

server {
    listen 80;
    server_name 10.14.25.18;

    location /streams/ {
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
        root /var/www;
        add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;
    }
}
  • The types  block specifies MIME types for .m3u8  and .ts  files.

  • The Access-Control-Allow-Origin *  header supports cross-origin requests.


Restart Nginx after configuration:

sudo systemctl restart nginx

Clients can now access the HLS stream through a URL like http://10.14.25.18/streams/stream.m3u8 .



Conclusion


Repacking RTSP streams into HLS using FFmpeg and Nginx is an effective solution for delivering high-quality video streams to a wide range of devices. This setup ensures compatibility, scalability, and efficiency, making it ideal for applications like IP camera streaming, live broadcasting, or multimedia projects. With HLS support, AV Studio allows developers to create projects without the need for third-party plug-ins. Just integrate into your project AV Studio a video element that supports HLS playback.

39 views0 comments

Comments


bottom of page