- 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.
- 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)
- 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)
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'
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'"