简体   繁体   中英

nginx HLS streaming; how to have directories of media content?

I have a simple nginx server up and running, in which I can serve HLS prepared media content (H264/AAC encoded mp4 video), below is my nginx.conf file.

worker_processes  1;

events {
    worker_connections  1024;
}

rtmp {                
    server {
        listen 1935;  
        chunk_size 4096;
            
        application vod {
            play /opt/video/vod; # videos are placed here.
        }
    }
}

By visiting rtmp://localhost/vod/video.mp4 I can play video.mp4 stored in /opt/video/vod . However, I would like to organise my media in directories such as movies and series within /opt/video/vod . But when I do this, I can no longer play video. For example, I cannot play rtmp://localhost/vod/series/video.mp4 .

Is there any way for this to work with nginx ?

Solved it, I misunderstood how HLS works. By configuring nginx to serve HLS content through a certain path, any actual HLS content, so H264 / AAC encoded content sliced into *.ts segments with an accompanying *.m3u8 playlist can be played from that path. Below is nginx.conf .

rtmp {
    server {
        listen 1935;

        application app {
            live on;

            # Don't allow RTMP playback
            deny play all;

            # Package streams as HLS
            hls on;
            hls_path /var/www/vod; # place your content here
            hls_nested on;
            hls_fragment_naming system;
        }
    }
}

To prepare your HLS content, use ffmpeg :

ffmpeg -i <input_video> -map 0 -codec:v libx264 -codec:a aac -f ssegment -segment_list playlist.m3u8 -segment_list_flags +live -segment_time 10 out%03d.ts

Then point a media player, eg VLC at http://<ip>/vod/playlist.m3u8 and it will play your video! This way you can divide your vod directory in whatever way you like, eg vod/series/himym/1/1/playlist.m3u8 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM