1. 源由
为了利用手头的树莓派硬件,同时,搭建一个Rover FPV验证平台。
前期,在《msposd 开源代码之树莓派3B+ Bookworm部署》中已经基本完成。
但是,无法显示fps/bitrate数据,初步讨论结果:
2. 分析
经过简单的初步分析,我们了解到libcamera-vid
打印日志中,含有或者间接含有相关数据。
例如:
- 帧 #34
- FPS 29.99 Hz
- 数据量 21008 Bytes
计算公式:
B
i
t
r
a
t
e
(
b
p
s
)
=
(
Sum of buffer sizes (bytes)
×
8
)
×
fps
Bitrate (bps) = ( \text{Sum of buffer sizes (bytes)} \times 8 ) \times \text{fps}
Bitrate(bps)=(Sum of buffer sizes (bytes)×8)×fps
B
i
t
r
a
t
e
(
b
p
s
)
=
(
21008 (bytes)
×
8
)
×
29.99
=
5
,
040
,
239.36
b
p
s
=
5.04
M
b
p
s
Bitrate (bps) = ( \text{21008 (bytes)} \times 8 ) \times \text{29.99} = 5,040,239.36 bps = 5.04Mbps
Bitrate(bps)=(21008 (bytes)×8)×29.99=5,040,239.36bps=5.04Mbps
Viewfinder frame 34
#34 (29.99 fps) exp 33216.00 ag 8.00 dg 1.00
FileOutput: output buffer 0x7f9d73a000 size 21008
- 1
- 2
- 3
3. 部署
3.1 下载
$ git clone https://github.com/SnapDragonfly/libcamera_mon.git
- 1
3.2 编译
$ cd libcamera_mon
$ make
$ tree ./build/
./build/
├── libcamera_mon
├── libcamera_proc.ko
├── libcamera_proc.mod
├── libcamera_proc.mod.c
├── libcamera_proc.mod.o
├── libcamera_proc.o
├── modules.order
└── Module.symvers
1 directory, 8 files
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
3.3 安装
$ sudo cp ./build/libcamera_mon /usr/local/bin/fpvdrone/
$ sudo cp ./build/libcamera_proc.ko /usr/local/bin/fpvdrone/
$ tree /usr/local/bin/fpvdrone/
/usr/local/bin/fpvdrone/
├── font_ardu_hd.png
├── font_ardu.png
├── font_btfl_hd.png
├── font_btfl.png
├── font_inav_hd.png
├── font_inav.png
├── fpv-drone.sh
├── fpv-update.sh
├── libcamera_mon
├── libcamera_proc.ko
└── msposd
1 directory, 11 files
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
3.4 配置
$ sudo nano /usr/local/bin/fpvdrone/fpv-drone.sh
$ cat /usr/local/bin/fpvdrone/fpv-drone.sh
#!/bin/bash
# Set up environment variables
export PATH=$PATH:/usr/local/bin:/usr/bin
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib
# Start the wfb_tx process
/usr/bin/wfb_tx \
-p 17 \
-u 14560 \
-K /etc/drone.key \
-B 20 \
-M 1 \
-S 1 \
-L 1 \
-G long \
-k 1 \
-n 2 \
-T 0 \
-i 7669206 \
-f data \
wfb-rf0 &
insmod /usr/local/bin/fpvdrone/libcamera_proc.ko
# Check if /tmp/libcamera/logs FIFO file exists, create it if not
if [ ! -p /tmp/libcamera/logs ]; then
mkfifo /tmp/libcamera/logs
fi
/usr/local/bin/fpvdrone/libcamera_mon &
# Start libcamera-vid and pipe its output to GStreamer while logging to /tmp/libcamera/logs
/usr/bin/libcamera-vid \
--verbose \
--inline \
--width 1920 \
--height 1080 \
--bitrate 4000000 \
--framerate 30 \
--hflip \
--vflip \
--timeout 0 \
-o - 2> /tmp/libcamera/logs | \
/usr/bin/gst-launch-1.0 \
-v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=35 ! udpsink sync=false host=127.0.0.1 port=5602 &
# Change to the FPVDrone directory and start the msposd process
cd /usr/local/bin/fpvdrone/
/usr/local/bin/fpvdrone/msposd \
--master /dev/ttyUSB0 \
--baudrate 115200 \
--out 127.0.0.1:14560 \
--matrix 11 \
--ahi 1 \
-r 30 \
-c 7 \
-c 9 &
# (Optional) Run the FPVDrone update script
# /usr/local/bin/fpvdrone/fpv-update.sh &
# Wait for all background processes to finish
wait
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
注:要先加载libcamera_proc.ko
,启动libcamera_mon
进程,最后打开视频libcamera-vid
,上述顺序不能错。
3.5 运行
启动fpv服务以后,使用测试脚本update.sh
定时每秒获取当前的fps
和bitrate
。
$ sudo systemctl start fpvdrone
$ cat update.sh
#!/bin/bash
while true; do
cat /proc/libcamera_proc
sleep 1
done
$ ./update.sh
frame=-2, fps=30.00, size=16045, filtered=3.17 Mbps, bitrate=3.85 Mbps
frame=-2, fps=30.01, size=22336, filtered=3.86 Mbps, bitrate=5.36 Mbps
frame=-2, fps=30.01, size=22328, filtered=4.74 Mbps, bitrate=5.36 Mbps
frame=-2, fps=30.01, size=15911, filtered=3.61 Mbps, bitrate=3.82 Mbps
frame=-2, fps=30.00, size=16023, filtered=3.58 Mbps, bitrate=3.85 Mbps
frame=-2, fps=30.01, size=15981, filtered=3.79 Mbps, bitrate=3.84 Mbps
frame=-2, fps=30.01, size=15976, filtered=3.61 Mbps, bitrate=3.83 Mbps
frame=-2, fps=30.01, size=21637, filtered=4.04 Mbps, bitrate=5.19 Mbps
frame=-2, fps=30.01, size=15977, filtered=3.29 Mbps, bitrate=3.84 Mbps
frame=-2, fps=30.01, size=15972, filtered=3.86 Mbps, bitrate=3.83 Mbps
frame=-2, fps=30.01, size=16005, filtered=3.49 Mbps, bitrate=3.84 Mbps
frame=-2, fps=30.01, size=20713, filtered=3.96 Mbps, bitrate=4.97 Mbps
frame=-2, fps=30.01, size=12510, filtered=3.31 Mbps, bitrate=3.00 Mbps
frame=-2, fps=30.01, size=16658, filtered=3.64 Mbps, bitrate=4.00 Mbps
frame=-2, fps=30.00, size=11612, filtered=4.08 Mbps, bitrate=2.79 Mbps
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
4. 总结
本文侧重部署libcamera_mon
相关的部署,关于服务以及传输层方面的内容,详见:
从数据的角度,可能也可以看出传输速率根据帧数据量的变化,bitrate会不断发生变化,当出现干扰,带宽受限,就会导致丢包率增加,此时很有丢帧情况发生。
在Adpative Link考虑中,更多要从丢包率、信号强度等等参数入手分析,这个,后续会跟进。前期已经简单介绍了一些资料,详见:
【1】OpenIPC开源FPV之Adaptive-Link工程解析
【2】OpenIPC开源FPV之Adaptive-Link天空端代码解析
【3】OpenIPC开源FPV之Adaptive-Link地面站代码解析
接下去,就是在msposd
的代码中,类似·sigmastar· 和hisilicon
获取fps
和bitrate
即可。
5. 后续 - OSD显示FPS/bitrate
目前OpenIPC官网并没有将树莓派作为支持选项,因此提供以下代码和脚本,供需要的朋友使用。
$ git clone https://github.com/SnapDragonfly/msposd.git
$ cd msposd
$ git checkout pr_pi3b_libcamera_vid_mon
$ ./build.sh raspberry
$ sudo cp msposd /usr/local/bin/fpvdrone/msposd
- 1
- 2
- 3
- 4
- 5
$ git clone https://github.com/SnapDragonfly/libcamera_mon.git
$ cd libcamera_mon
$ make
$ sudo cp build/libcamera_mon /usr/local/bin/fpvdrone/libcamera_mon
- 1
- 2
- 3
- 4
- 打开Option命令行,自定义OSD显示
daniel@raspberrypi:~/msposd $ sudo nano /usr/local/bin/fpvdrone/fpv-drone.sh
daniel@raspberrypi:~/msposd $ cat /usr/local/bin/fpvdrone/fpv-drone.sh
#!/bin/bash
# Set up environment variables
export PATH=$PATH:/usr/local/bin:/usr/bin
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib
# Start the wfb_tx process
/usr/bin/wfb_tx \
-p 17 \
-u 14560 \
-K /etc/drone.key \
-B 20 \
-M 1 \
-S 1 \
-L 1 \
-G long \
-k 1 \
-n 2 \
-T 0 \
-i 7669206 \
-f data \
wfb-rf0 &
insmod /usr/local/bin/fpvdrone/libcamera_proc.ko
# Check if /tmp/libcamera/logs FIFO file exists, create it if not
if [ ! -p /tmp/libcamera/logs ]; then
mkfifo /tmp/libcamera/logs
fi
/usr/local/bin/fpvdrone/libcamera_mon &
# Start libcamera-vid and pipe its output to GStreamer while logging to /tmp/libcamera/logs
/usr/bin/libcamera-vid \
--verbose \
--inline \
--width 1920 \
--height 1080 \
--bitrate 4000000 \
--framerate 30 \
--hflip \
--vflip \
--timeout 0 \
-o - 2> /tmp/libcamera/logs | \
/usr/bin/gst-launch-1.0 \
-v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=35 ! udpsink sync=false host=127.0.0.1 port=5602 &
# Change to the FPVDrone directory and start the msposd process
cd /usr/local/bin/fpvdrone/
/usr/local/bin/fpvdrone/msposd \
--master /dev/ttyUSB0 \
--baudrate 115200 \
--out 127.0.0.1:14560 \
--matrix 11 \
--ahi 1 \
-r 30 \
-c 7 \
-c 9 &
# (Optional) Run the FPVDrone update script
/usr/local/bin/fpvdrone/fpv-update.sh &
# Wait for all background processes to finish
wait
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
$ cat /usr/local/bin/fpvdrone/fpv-update.sh
#!/bin/bash
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
while true; do
echo "Monitor... &L24 &F28 &t CPU:&C &B Temp:&T" > /usr/local/bin/fpvdrone/MSPOSD.msg
sleep 3
done
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
评论记录:
回复评论: