tea*_*mon 5 video streaming overlay raspberry-pi
我正在为树莓派相机使用各种视频流选项。目前具有最低延迟的最佳解决方案是将数据从raspividto管道传输nc到mplayer
在覆盆子上:
/opt/vc/bin/raspivid -t 0 -hf -vf -w 640 -h 480 --nopreview -o - | nc -l 5000
Run Code Online (Sandbox Code Playgroud)
在客户端机器上(-fps 60跳过缓冲的技巧)
nc $RASP_IP 5000 | mplayer -nosound -framedrop -x 640 -y 480 -fps 60 -demuxer +h264es -cache 1024 -
Run Code Online (Sandbox Code Playgroud)
这项工作非常好,几乎为零延迟。
现在我想将一些动态数据叠加到视频上。实现这一目标的最佳方法是什么?
我见过raspivid直接编辑和添加 opencv 之类的解决方案,但这在我的情况下不起作用,因为显示器必须位于与连接到相机的机器不同的机器上。
技术(语言/库)并不重要,除非它可以在 *nix 上运行(.NET 不是一个选项)
以下是我使用多播通过网络流式传输 Pi 摄像头的几个命令,并在图像底部写入时间和摄像头名称。我在每一行之间添加了注释来解释它的作用,但命令本身必须全部位于同一行,没有任何注释才能实际工作(一行以 开头v4l2-ctl,另一行以 开头ffmpeg)。
# Set up the camera device for dynamic framerate (to get better images in
# low light) and for uncompressed video output.
v4l2-ctl
-d /dev/video0
--set-ctrl=exposure_dynamic_framerate=1
--set-ctrl=scene_mode=8
-v width=1296,height=960,pixelformat=YU12
# Run ffmpeg.
ffmpeg
# Select the frame size. This is for the Pi camera v1 and must match the
# size set above in v4l2-ctl.
-f rawvideo -pix_fmt yuv420p -video_size 1296x960
# Use the system clock because the camera stream doesn't have timestamps.
-use_wallclock_as_timestamps 1
# Select the first camera. This could change if you have multiple
# cameras connected (e.g. via USB)
-i /dev/video0
# Set the framerate in the output H264 stream. This value is double
# the actual framerate, so 30 means 15 fps.
-bsf h264_metadata=tick_rate=30
# Use a video filter
-vf '
# Make the video higher by 37 pixels (32 for the words and 5 for padding)
pad=h=(in_h+5+32),
# Write the time at the bottom right.
drawtext=x=(w-tw-8):y=(h-28):fontcolor=white:fontsize=28:text=%{localtime},
# Write the hostname on the bottom left, which we put in the file
# /tmp/cam_hostname before running this command.
drawtext=x=8:y=(h-28):fontcolor=white:fontsize=28:textfile=/tmp/cam_hostname,
# Write another message from /tmp/cam_msg after the hostname. This
# file is read each frame, so it can contain live data such as the
# temperature or motion sensor status. The file contents must be
# written by another program.
drawtext=x=32:y=(h-28):fontcolor=white:fontsize=28:textfile=/tmp/cam_msg:reload=1
# End of -vf parameter
'
# Duplicate or drop frames as needed to ensure a constant output framerate.
# This is because the Pi camera is set to a dynamic framerate, so at night
# the framerate will drop to give a brighter image. This option ensures
# that whatever the camera framerate, the output H264 framerate will be
# constant.
-vsync 1
# Specify the output framerate. We use 15 fps because that's the camera's
# maximum in high resolution mode.
-r 15
# Use the hardware H264 encoder via the V4L2 M2M interface.
-c:v h264_v4l2m2m
# Set the bitrate of the output video.
-b:v 5M
# No audio.
-an
# Adjust the output H264 bitstream so the timestamps run at the correct
# rate. This is required so if the stream is recorded, media players will
# seek accurately (e.g. seeking 10 seconds forward will go forward 10
# seconds). Without this, seeking forward by 10 seconds could jump forward
# by a minute or more, making it difficult to seek around in the
# recorded footage.
-bsf 'setts=ts=N*(1/15)*100000,h264_metadata=tick_rate=30'
# Output the final stream via RTP to a multicast IP address.
-f rtp_mpegts udp://239.0.0.3:5004
Run Code Online (Sandbox Code Playgroud)