Search code examples
ffmpeghttp-live-streamingm3u8

How to restream m3u8 with ffmpeg


I use nginx rtmp and followig command:

ffmpeg -fflags +igndts -hide_banner -i https://ch.iptvmate.net/ec6e5689ffd6f9690102640bddd2f9e7.m3u8 -c copy -f hls -hls_time 4 -hls_flags append_list+delete_segments -hls_list_size 6 -hls_segment_filename 'hls/ch2/file%03d.ts' hls/ch2/playlist.m3u8

It streams but not live, it has recorded one period of the channel and this link streams this period again and again. Is the command correct? I just created the folder called ch2 and it is.


Solution

  • If you are trying to push stream as rtmp, HLS parameters are not required.

    Simple way to re-stream via rtmp into nginx:

    ffmpeg -fflags +igndts -hide_banner -i https://ch.iptvmate.net/ec6e5689ffd6f9690102640bddd2f9e7.m3u8 -c copy -f flv rtmp://127.0.0.1/live/stream
    

    Afterwards, you can configure your live block in Nginx to have HLS.

            application live {
            live on;
            hls on;
            hls_path /tmp/hls;
        }
    

    Eventually, you would like to have chunks over HTTP:

            location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /tmp;
            add_header Cache-Control no-cache;
        }
    

    Try http://127.0.0.1/hls/stream.m3u8 when configuration is successful and ffmpeg is running.