Search code examples
linuxbashopencvffmpeghttp-live-streaming

Setting HLS segment times


I am passing a processed video from openCV to ffmpeg via a pipe here is the code

./OpenCV & \
 tail -n +0 -f out.avi  | ffmpeg -i pipe:0  -hls_time 1 -hls_list_size 0 -hls_wrap 10 -hls_segment_filename '%03d.ts' stream.m3u8 

My issue is the output .ts files are not in a uniformed duration they change from file to file.

These are mostly long say 60 seconds. This means the connecting client has to wait for the first stream to finish before the playlist file (.m3u8) file is created. Therefor in this example they are 60 seconds or so behind live video and if the next .ts file is larger the streaming stops until this is finished. If the client tries to play before the next .ts file is created they are played the first .ts file.

The frame rate from openCV is 1 frame per second.

tail changes the output file of openCV called (out.avi) to a stdout.

Any help would be great.


Solution

  • I know I am answering my own question but I have changed the code below

    ./OpenCV & \
     tail -n +0 -f out.avi  | ffmpeg -i pipe:0  -hls_time 1 -hls_list_size 0 -hls_wrap 10 -hls_segment_filename '%03d.ts' stream.m3u8 `
    

    to

    ./OpenCV & \
    tail -n +0 -f out.avi  | ffmpeg -i pipe:0 -f hls -g 2 -hls_time 2 -hls_list_size 0 -hls_wrap 10 -hls_segment_filename '%03d.ts' stream.m3u8 `
    

    Seems to have done the trick.