Skip to main content

SDK 简介

简介

AidStream 是用来构建流媒体应用的视频框架,其目标是要简化视频+AI应用程序的开发中需要插入算法的程序构建。 AidStream 基于pipeline的概念,aidstream中的pipeline元素也非常简单,只分为输入端和输出端,使用函数调用即可,且在pipeline开始后时,sdk可以在输入端和输出端之间通过回调函数获取RGB数据,在回调函数中可以将此RGB数据经算法处理后再返回给pipeline,经处理后的RGB数据会继续pipeline的后续输出过程。 V3版本是对之前AidStream初始版本的一次重大升级。

处理流程:

alt text

快速上手

C++示例代码

tip

使用AidStream SDK V3 C++ API编译,需要引入AidStream SDK 头文件:

#include "aidstream.h"

链接时需要指定AidStream SDK so库,例如:

$g++ example.cpp -o demo -L/usr/local/lib/ -laidstream-gst -L/usr/local/lib/aidlux_opencv/lib/ -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -I/usr/local/include/aidlux/aidstream-gst/ -I/usr/local/lib/aidlux_opencv/include/opencv4/

AidStream SDK 头文件地址: /usr/local/include/aidlux/aidstream-gst/aidstream.h

AidStream SDK 库文件地址: /usr/local/lib/libaidstream-gst.so

由于对OpenCV有依赖,建议执行前设置OpenCV路径:
export LD_LIBRARY_PATH=/usr/local/lib/aidlux_opencv/lib/:/usr/local/lib:$LD_LIBRARY_PATH

安装程序自带example示例及相应的CMakeLists.txt,可到安装目录/usr/local/share/aidstream-gst/example/cxx/下查看。

根据配置文件参数来选择输入输出流。关于配置文件,请参考Reference

#include <cstdlib>
#include <string>
#include <iostream>
#include "aidstream.h"

using namespace std;
using namespace Aidlux::AidStream;

int8_t my_img_cb(const Image &img)
{
printf("width: %d, height: %d, fps: %f\n", img.width, img.height, img.fps);
return 0;
}

int main(int argc, char* argv[])
{
string _idx;
if (argc > 1)
{
_idx = argv[1];
}
else
{
_idx = "1";
}

Aidlux::AidStream::GetImageCB callback = my_img_cb;
start_stream(_idx, callback);

return 0;
}

读取rtsp流显示,不做任何处理,输出RTSP流到rtsp://192.168.111.115:8554/aidstream-gst-rtsp-test

#include <cstdlib>
#include <string>
#include <iostream>
#include "aidstream.h"

using namespace std;
using namespace Aidlux::AidStream;

int8_t my_img_cb(const Image &img)
{
printf("width: %d, height: %d, fps: %f\n", img.width, img.height, img.fps);
return 0;
}

int main()
{
string rtsp_path = "rtsp://admin:aidlux123@192.168.110.234:554/h264/ch1/main/av_stream";
int res = start_stream_input_rtsp(rtsp_path, my_img_cb, StreamType::RTSPSINK, "rtsp://192.168.111.115:8554/aidstream-gst-rtsp-test");
if(res != 0)
{
return -1;
}
return 0;
}

根据参数同时开启多路流显示,不做任何处理

#include <cstdlib>
#include <thread>
#include <string>
#include <iostream>
#include "aidstream.h"

using namespace std;
using namespace Aidlux::AidStream;

int8_t my_img_cb(const Image &img)
{
printf("width: %d, height: %d, fps: %f\n", img.width, img.height, img.fps);
return 0;
}

int main(int argc, char* argv[])
{
clogger("./aidclog_aidstream_c");
set_log_level(GSTLogLevel::SINFO);
Aidlux::AidStream::GetImageCB callback = my_img_cb;

std::thread t1(start_stream, "1", ref(callback));
std::thread t2(start_stream, "7", ref(callback));

t1.join();
t2.join();

return 0;
}