Skip to content

Instantly share code, notes, and snippets.

@r3n33
Last active June 30, 2019 20:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save r3n33/acaa8110c9c11b2a7d865e62ef29a320 to your computer and use it in GitHub Desktop.
Save r3n33/acaa8110c9c11b2a7d865e62ef29a320 to your computer and use it in GitHub Desktop.
LetsRobot.tv Video Overlay

Letsrobot.tv / Run My Robot Overlay Guide

  • Both of these methods expect a PNG image with transparency to be the same size as your video feed ( 640x480 by default ). It is possible to blend images at different resolutions with alternate commands but beyond the scope of this document.

Static video overlay

  • Requires no modification to FFMPEG
  • Add overlayCommand and change the videoCommandLine in send_video.py:

staticOverlayCommand = '-f image2 -i /home/pi/runmyrobot/images/hud.png -filter_complex "[0:v]format=argb,geq=r=\'r(X,Y)\':g=\'g(X,Y)\':b=\'b(X,Y)\':a=\'0.7*alpha(X,Y)\'[overlay]; [1:v][overlay]overlay"'

videoCommandLine = '/usr/local/bin/ffmpeg {overlay} -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video{video_device_number} {rotation_option} -f mpegts -codec:v mpeg1video -s {xres}x{yres} -b:v {kbps}k -bf 0 -muxdelay 0.001 http://{server}:{video_port}/hello/{xres}/{yres}/'.format(overlay=staticOverlayCommand,video_device_number=commandArgs.video_device_number, rotation_option=rotationOption(), kbps=commandArgs.kbps, server=server, video_port=videoPort, xres=commandArgs.xres, yres=commandArgs.yres)

Dynamic video overlay ( polls filesystem for modified file at specified interval, default 2Hz )

  • Requires additional code to be compiled with FFMPEG ( see below )
  • Add overlayCommand and change the videoCommandLine in send_video.py:

overlayCommand = '-vf dynoverlay=overlayfile=/home/pi/runmyrobot/images/hud.png:check_interval=500'

videoCommandLine = '/usr/local/bin/ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video%s %s -f mpegts -codec:v mpeg1video -s 640x480 -b:v %dk -bf 0 -muxdelay 0.001 %s http://%s:%s/hello/640/480/' % ( deviceAnswer, rotationOption, args.kbps, overlayCommand, server, videoPort)

To compile FFMPEG with Dynoverlay filter use these modified instructions from step 6 in the README

sudo apt install gnutls-dev

cd /usr/local/src

git clone https://github.com/r3n33/FFmpeg.git -b dynoverlay

cd FFmpeg

./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree --enable-gnutls --extra-libs=-ldl --enable-zlib

make -j4

sudo make install

UPDATE: Dynoverlay now supports multiple overlays and X,Y offsets. (Images can be small and placed in various locations.)

For example:

overlayCommand = '-vf dynoverlay=overlayfile=/dev/shm/battery.png:check_interval=1000:x=520:y=383,dynoverlay=overlayfile=/dev/shm/nametag.png:check_interval=5000:x=0:y=395'

UPDATE 2: Best location for dynoverlay parameters

In the python send_video.py you can add the video filter parameters to the empty return string if you are not flipping your video 180 degrees. If you are rotating your video append the dynoverlay information after the last transpose=2. For example:

def rotationOption():

    if commandArgs.rotate180:
        return "-vf transpose=2,transpose=2"
    else:
        return ""

to this:

def rotationOption():

    if commandArgs.rotate180:
        return "-vf transpose=2,transpose=2,dynoverlay=overlayfile=/dev/shm/battery.png:check_interval=1000:x=520:y=383,dynoverlay=overlayfile=/dev/shm/nametag.png:check_interval=5000:x=0:y=395'"
    else:
        return "-vf dynoverlay=overlayfile=/dev/shm/battery.png:check_interval=1000:x=520:y=383,dynoverlay=overlayfile=/dev/shm/nametag.png:check_interval=5000:x=0:y=395'"
@Nocturnal42
Copy link

Important note : Not compatible with the --rotate180 option of send_video.py. The second -vf option overwrites the overlay command.

@r3n33
Copy link
Author

r3n33 commented Jul 25, 2017

Thanks @Nocturnal42 I just noticed this the other day. Appended a new update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment