测试VPU
编译mpp
bash
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版本
bash
mpp_info_test
tail /var/log/syslog
测试硬解码
bash
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(每秒帧数),这是一个非常高的帧率,显示了解码过程的高效性。
测试硬编码
bash
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 ! 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
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 ! 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