ffmpegrtmpoverlays

Use FFMPEG to blend streaming overlay onto second stream


I'm trying to build a form of monitoring that can be superimposed onto a live stream.

Monitor Overlay

ffmpeg -i rtmp://localhost/pool/livestream -filter_complex \
  "nullsrc=1024x576[1:v]; \
  [0:a]showvolume=v=0:o=1:t=0:f=0.1,drawbox=x=ih-40:y=0:w=40:h=ih[volume]; \
  [1:v]drawtext=x=(main_w/2)-(text_w/2):y=text_h:fontsize=30:fontcolor=white:borderw=1:text='Stream Label',scale=-1:-1[label]; \
  [label][volume]overlay=x=main_w-40:y=0[output]" \
  -map "[output]" -f flv rtmp://localhost/pool/livestream_overlay

What I would like to accomplish is that this stream be superimposed onto the original stream and pushed to a third RTMP endpoint, like this:

ffmpeg -i rtmp://localhost/pool/livestream -i rtmp://localhost/pool/livestream_overlay \
  -filter_complex "[0:v][1:v]overlay=shortest=1[output]" \
  -f flv rtmp://localhost/pool/livestream_monitor

While the workflow seems to be working, the overlay is not blending (subtracted?) onto the original video:

Actual output

Actual output

Expected output

Expected output

Note: codec options have been removed for brevity's sake.


Solution

  • Use

    ffmpeg -i rtmp://localhost/pool/livestream -filter_complex \
    "[0:a]showvolume=v=0:o=1:t=0:f=0.1,drawbox=x=iw-40:y=0:w=40:h=ih[volume]; \
     [0:v]drawtext=x=(W-tw)/2:y=th:fontsize=30:fontcolor=white:borderw=1:text='Stream Label'[label]; \
     [label][volume]overlay=x=W-40:y=0[output]" \
    -map "[output]" -map 0:a -f flv rtmp://localhost/pool/livestream_monitor
    

    None of the usual FLV codecs support alpha, so in the 2nd command, you would have to perform chroma keying, which is usually subpar in ffmpeg. So, you can do it in the same command.