测试VPU
编译mpp
sudo apt update
sudo apt install gcc g++ cmake make
cd ~
git clone https://github.com/rockchip-linux/mpp.git
cd mpp/build/linux/aarch64/
sed -i 's/aarch64-linux-gnu-gcc/gcc/g' ./arm.linux.cross.cmake
sed -i 's/aarch64-linux-gnu-g++/g++/g' ./arm.linux.cross.cmake
./make-Makefiles.bash
make -j$(nproc)
sudo make install
cd test
sudo cp mpp_info_test /usr/local/bin/mpp_info_test
sudo cp mpi_dec_test /usr/local/bin/mpi_dec_test
sudo cp mpi_enc_test /usr/local/bin/mpi_enc_test
查看mpp版本
mpp_info_test
tail /var/log/syslog
测试硬解码
wget http://112.124.9.243/test/200frames_count.h264 -O 200frames_count.h264
mpi_dec_test -t 7 -i 200frames_count.h264
tail /var/log/syslog
mpi_dec_test: decode 200 frames time 213 ms delay 3 ms fps 934.71
- 这条日志详细记录了解码性能的关键指标:
- 解码了200帧
- 总耗时213毫秒
- 平均每帧延迟3毫秒
- 帧率为934.71 FPS(每秒帧数),这是一个非常高的帧率,显示了解码过程的高效性。
测试硬编码
wget http://112.124.9.243/test/4k_nv12.yuv.gz -O 4k_nv12.yuv.gz
gzip -d 4k_nv12.yuv.gz
mpi_enc_test -w 3840 -h 2160 -t 7 -i 4k_nv12.yuv -f 0 -o 4k_nv12.h264
tail /var/log/syslog
mpi_enc_test: chn 0 encode 241 frames time 31623 ms delay 107 ms fps 7.62 bps 32174975
- 这条信息提供了编码任务的性能汇总:
encode 241 frames
表示共编码了241帧。time 31623 ms
表示总耗时约31秒。delay 107 ms
表示平均每帧延迟107 毫秒。fps 7.62
表示平均每秒编码约7.62 帧,显示编码速度。bps 32174975
表示平均每秒传输的比特数,即编码的视频流的比特率。
推流实验
ffmpeg下载
服务器配置(NGINX)
sudo apt update
sudo apt install build-essential libpcre3 libpcre3-dev libssl-dev zlib1g-dev
wget http://nginx.org/download/nginx-1.21.6.tar.gz
tar -zxvf nginx-1.21.6.tar.gz
git clone https://github.com/arut/nginx-rtmp-module.git
cd nginx-1.21.6
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
make
sudo make install
sudo vim /usr/local/nginx/conf/nginx.conf
添加RTMP配置
rtmp {server {listen 1935; # 监听端口chunk_size 4096;application live {live on; # 允许实时视频流record off; # 不记录视频流}}
}server {listen 8080;...
}
重启nginx服务器
sudo /usr/local/nginx/sbin/nginx #启动nginx
sudo /usr/local/nginx/sbin/nginx -s reload #重启nginx
ffmpeg -f v4l2 -input_format mjpeg -framerate 30 -video_size 1920x1080 -i /dev/video10 -c:v h264_v4l2m2m -b:v 2M -f flv rtmp://192.168.137.82/live/stream
ffmpeg -f v4l2 -input_format yuyv422 -framerate 10 -video_size 1024x768 -i /dev/video10 -c:v h264_v4l2m2m -b:v 2M -f flv rtmp://192.168.137.82/live/stream
Gstreamer下载
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-rtsp
添加RTMP配置
rtmp {server {listen 1935;chunk_size 4096;application live {live on;record off;}}
}http {server {listen 8080;location / {root html;index index.html index.htm;}location /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {root /usr/local/nginx/html;}}
}
硬件加速推流指令
gst-launch-1.0 -v v4l2src device=/dev/video10 ! image/jpeg,width=640,height=480,framerate=30/1 ! jpegdec ! videoconvert ! video/x-raw,format=NV12 ! mpph264enc ! h264parse ! flvmux ! rtmpsink location=rtmp://192.168.137.82/live/streamgst-launch-1.0 -v v4l2src device=/dev/video10 ! image/jpeg,width=640,height=480,framerate=30/1 ! mppjpegdec ! videoconvert ! video/x-raw,format=NV12 ! queue max-size-time=0 max-size-buffers=1 leaky=downstream ! mpph264enc ! h264parse ! flvmux streamable=true ! rtmpsink location=rtmp://192.168.137.82/live/stream
#系统日志:
pi@SOM-RK3399v2:~/gst-rtsp-server$ tail /var/log/syslog
Jun 2 13:35:38 SOM-RK3399v2 mpp[282345]: mpp: unable to create enc h265 for soc rk3399 unsupported
Jun 2 13:35:38 SOM-RK3399v2 mpp[282345]: mpp: Only rk3588 h264 encoder can use frame parallel
Jun 2 13:36:00 SOM-RK3399v2 mpp[282508]: mpp_info: mpp version: 8d93a45f author: jensen 2023-06-28 [vpu_api_test] fix library name of dlopen
Jun 2 13:36:00 SOM-RK3399v2 mpp[282508]: mpp: unable to create enc h265 for soc rk3399 unsupported
Jun 2 13:38:49 SOM-RK3399v2 mpp[283301]: mpp_info: mpp version: 8d93a45f author: jensen 2023-06-28 [vpu_api_test] fix library name of dlopen
Jun 2 13:38:49 SOM-RK3399v2 mpp[283301]: mpp: unable to create enc h265 for soc rk3399 unsupported
Jun 2 13:38:49 SOM-RK3399v2 mpp[283301]: mpp: Only rk3588 h264 encoder can use frame parallel
Jun 2 13:38:49 SOM-RK3399v2 mpp[283301]: mpp_enc: MPP_ENC_SET_RC_CFG bps 1152000 [1080000 : 1224000] fps [30:30] gop 30
Jun 2 13:38:49 SOM-RK3399v2 mpp[283301]: h264e_api_v2: MPP_ENC_SET_PREP_CFG w:h [640:480] stride [640:480]
Jun 2 13:38:49 SOM-RK3399v2 mpp[283301]: mpp_enc: mode cbr bps [1080000:1152000:1224000] fps fix [30/1] -> fix [30/1] gop i [30] v [0]
PC端vlc播放器有大概2s延时,暂时不清楚具体原因。可能是PC解码问题,也可能是格式转换的问题(摄像头不支持NV12格式捕获,需要转换)。