Reputation: 13
I am running a robot that uses fmpeg to send straming video to letsrobot.tv You can see my bot on the website called patton II. I want to overlay a video HUD on the stream.
I have found a link explaining how to do this, however I do not know how to do it with a streaming video as input instead of a single image file.
This is the command that is currently being used to stream the video:
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)
audioCommandLine = '/usr/local/bin/ffmpeg -f alsa -ar 44100 -i hw:1 -ac 2 -f mpegts -codec:a mp2 -b:a 32k -muxdelay 0.001 http://%s:%s/hello/640/480/' % (server, audioPort)
Upvotes: 0
Views: 2276
Reputation: 38672
You already have one input, which is the webcam video:
-f v4l2 -framerate 25 -video_size 640x480 -i /dev/video%s
You want to overlay another video, so you have to add a second input, which is your HUD stream. I'm assuming that you already have a stream that's being generated on the fly:
-i /path/to/hud/stream
Then, add a complex filter that overlays one over the other:
-filter_complex "[0:v][1:v]overlay[out]"
After the filter, add a -map "[out]"
option to tell ffmpeg to use the generated video as output, and add your remaining options as usual. So, in sum:
/usr/local/bin/ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video%s \
-i /path/to/hud/stream \
-filter_complex "[0:v][1:v]overlay[out]" -map "[out]" \
-f mpegts -codec:v mpeg1video -s 640x480 -b:v %dk -bf 0 \
-muxdelay 0.001 %s http://%s:%s/hello/640/480/
Obviously, without knowing more, this is the most generic advice I can give you.
Some general tips:
overlay
filter's x
and y
options to move the HUD.-codec:v mpeg1video
, which is MPEG-1 video. It's quite resource-efficient but otherwise low in quality. You may want to choose a better codec, but it depends on your device capabilities (e.g., at least MPEG-2 with mpeg2
, or MPEG-4 Part 10 with mpeg4
, or H.264 with libx264
).Upvotes: 2