opencv ffmpeg debian linux下开启硬件编解码加速处理
1.编译opencv支持ffmpeg
2.调用opencv代码配置环境变量
#ifdef _MSC_VER
//Windows下指定UDP参数
std::string strOpts = "OPENCV_FFMPEG_CAPTURE_OPTIONS=rtsp_transport;udp|stimeout;20000000|max_delay;1000000|buffer_size;4096000|";
(void)putenv((char*)strOpts.c_str());
std::cout << __func__ << ":" << __LINE__ << " OPENCV_FFMPEG_CAPTURE_OPTIONS=" << getenv("OPENCV_FFMPEG_CAPTURE_OPTIONS") << std::endl;
#else
//Linux下指定UDP参数
std::string strOpts = "OPENCV_FFMPEG_CAPTURE_OPTIONS=rtsp_transport;udp|stimeout;20000000|max_delay;1000000|buffer_size;4096000|pkt_size;4096000|bitrate;25|";
//std::string strOpts = "OPENCV_FFMPEG_CAPTURE_OPTIONS=rtsp_transport;udp|stimeout;20000000|max_delay;1000000|buffer_size;4096000|pkt_size;4096000|video_codec;h264_mmal|";//指定硬解码
(void)putenv((char*)strOpts.c_str());
std::cout << __func__ << ":" << __LINE__ << " OPENCV_FFMPEG_CAPTURE_OPTIONS=" << getenv("OPENCV_FFMPEG_CAPTURE_OPTIONS") << std::endl;
#endif // _MSC_VER
备注说明:
解码器,可以通过ffmpeg -decoder命令查看获取。实际应用中要查看板子及配套OS支持的硬件解码器。这里使用的是树莓派4B,buster版本系统,硬解码器名称为h264_mmal。
Debian Linux下调整接收缓冲区大小限制:(如有需要才设置)
$sudo vi /etc/sysctl.conf
尾部添加:
net.core.rmem_max = 67108864
$sudo sysctl -p