linux - Passing processed Video from OpenCV to FFmpeg for HLS streaming (Raspberry PI) -


hi have question have opencv , ffmpeg on raspberry pi , trying stream live video raspberry pi. @ moment have output output of opencv saving .avi file , have command ffmpeg ffmpeg -i out.avi -hls_segment_filename '%03d.ts' stream.m3u8 command take output creates playlist(.m3u8) , segments(.ts).

at present have opencv programmed in c++ (this can not change) have executable programmed , have both executable c++ , above ffmpeg in bash script.

#!/bin/bash  while true; ./opencv ffmpeg -i out.avi -hls_segment_filename '%03d.ts' stream.m3u8 done 

this allow me stream processed opencv video issue bash script in while loop keeps resetting playlist , .ts files, have press play on client connection.

is there anyway around this?

i tried including variable increment every loop if replace '%03d' error.

if insist on using program (opencv) , ffmpeg in loop can specify initial hls sequence number stream.m3u8 using start_number. this:

... before ... ffmpeg -i out.avi -hls_segment_filename '%03d.ts' --start_number $i stream.m3u8 

where i variable have increment each time loop runs. approach fragile , result in incorrect stream because assumes ffmpeg produce single segment in reality produce multiple segments.

a better approach run opencv , ffmpeg in parallel , make them talk each other. doing there no need write temporary file out.avi , run opencv , ffmpeg in sequences , keep media sequences synchronized.

i think can hack this. note may need change opencv writes out.avi , not return after while:

./opencv & tail -n +0 -f out.avi  | ffmpeg -i pipe:0 -hls_segment_filename '%03d.ts' stream.m3u8 

a better approach change program write stdout or named pipe , run so:

./opencv | ffmpeg -i pipe:0 -hls_segment_filename '%03d.ts' stream.m3u8 

Comments