Toybrick

楼主: hisping

RK3399Pro入门教程(7)RTSP库的使用

 

christian

注册会员

积分
132
发表于 2020-4-10 16:32:56 | 显示全部楼层
lipandeng 发表于 2020-1-15 17:38
硬解码后的图像颜色偏差很大,尤其和软解码对比更明显,不知道啥原因还有就是硬解码下cpu使用率还是有些高 ...

你好,颜色偏差大有解决吗?
回复

使用道具 举报

christian

注册会员

积分
132
发表于 2020-4-10 16:36:28 | 显示全部楼层
局域网下测试,摄像头分辨率为1280*720,可以跑起来,但是发现硬解和软解对比颜色偏差比较大,而且硬解的时候,晃动摄像头会有偶尔会有 一点卡顿。还请版主给指导下这个该怎么排查的?
回复

使用道具 举报

lipandeng

注册会员

积分
134
QQ
发表于 2020-4-29 12:26:32 | 显示全部楼层
christian 发表于 2020-4-10 16:32
你好,颜色偏差大有解决吗?

解决了,系统是debian10 ,解决不了可以发邮寄给我:li.pandeng@163.com你参考下,
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <thread>
  9. #include <memory.h>
  10. #include <sys/time.h>
  11. #include <queue>

  12. using namespace std;

  13. #include "opencv2/core/core.hpp"
  14. #include "opencv2/highgui/highgui.hpp"

  15. #include <rockchip/rockchip_rtsp.h>
  16. #include <rockchip/rockchip_mpp.h>
  17. extern "C" {
  18. #include <rockchip/rockchip_rga.h>
  19. }

  20. #define RTSP_URL        "rtsp://192.168.1.200/h264/ch1/main/av_stream"
  21. #define RTSP_USER        "admin"
  22. #define RTSP_PWD        "123456"

  23. static MppDecoder *mpp_dec = NULL;
  24. static std::queue<DecFrame *> frame_queue;
  25. static int run_flag = 0;

  26. unsigned long get_time(void)
  27. {
  28.         struct timeval ts;
  29.         gettimeofday(&ts, NULL);
  30.         return (ts.tv_sec * 1000 + ts.tv_usec / 1000);
  31. }

  32. void onRtspHandle(unsigned char *buf, size_t len)
  33. {
  34.         std::cout << "frame recived " << len << std::endl;

  35.         mpp_dec->ops->enqueue(mpp_dec, buf, len);
  36. }

  37. void inference_thread(RockchipRga *rga, int width, int height)
  38. {
  39.         int ret;
  40.         int resize_w = 1920, resize_h = 1080;
  41.         static int frame_size = 0;
  42.         unsigned char *frame_rgb = NULL;

  43.         rga->ops->initCtx(rga);
  44.         rga->ops->setRotate(rga, RGA_ROTATE_NONE);
  45.         rga->ops->setSrcFormat(rga, V4L2_PIX_FMT_NV12, width, height);
  46.         rga->ops->setDstFormat(rga, V4L2_PIX_FMT_BGR24, resize_w, resize_h);
  47.        
  48.         frame_size = resize_w * resize_h * 3;
  49.         frame_rgb = (unsigned char *)malloc(frame_size);
  50.         cv::Mat img(resize_h , resize_w , CV_8UC3, frame_rgb);
  51.         if (!frame_rgb)
  52.                 goto exit;
  53.        
  54.         rga->ops->setDstBufferPtr(rga, frame_rgb);

  55.         while (run_flag) {
  56.                 if (frame_queue.empty()) {
  57.                         usleep(1000);
  58.                         continue;
  59.                 }

  60.                 auto frame = frame_queue.front();

  61.                 rga->ops->setSrcBufferPtr(rga, frame->data);

  62.                 ret = rga->ops->go(rga);
  63.                 printf("inference_thread ................\n");
  64.                 if (!ret) {
  65.                         ///do something with frame_rgb

  66.                         cv::imshow("test", img);
  67.                         cv::waitKey(10);
  68.                 }

  69.                 frame_queue.pop();
  70.                 mpp_dec->ops->freeFrame(frame);
  71.         }

  72. exit:
  73.         run_flag = 0;

  74.         while (!frame_queue.empty()) {
  75.                 auto frame = frame_queue.front();
  76.                 mpp_dec->ops->freeFrame(frame);
  77.                 frame_queue.pop();
  78.         }

  79.         if (frame_rgb)
  80.                 free(frame_rgb);
  81. }

  82. void decode_thread(RockchipRga *rga)
  83. {
  84.         int ret;
  85.         int first_frame = 0;
  86.         std::thread t_inference;

  87.         while (run_flag) {
  88.                 DecFrame *frame = mpp_dec->ops->dequeue_timeout(mpp_dec, 300);
  89.                 if (frame != NULL) {
  90.                         std::cout << "decode frame" << frame->width << "x" << frame->height << std::endl;
  91.                
  92.                         if (!first_frame) {
  93.                                 std::cout << "first_frame" << std::endl;
  94.                                 t_inference = std::thread(inference_thread, rga, frame->width, frame->height);
  95.                                 first_frame = 1;
  96.                         }

  97.                         if (frame_queue.size() < 30)
  98.                                 frame_queue.push(frame);
  99.                         else
  100.                                 mpp_dec->ops->freeFrame(frame);
  101.                 }
  102.         }

  103. exit:
  104.         run_flag = 0;

  105.         t_inference.join();

  106.         while (!frame_queue.empty()) {
  107.                 auto frame = frame_queue.front();
  108.                 mpp_dec->ops->freeFrame(frame);
  109.                 frame_queue.pop();
  110.         }

  111. }

  112. int main(int argc, char **argv)
  113. {
  114.         int ret;
  115.         RockchipRga *rga;
  116.         unsigned char ready[5] = {'r', 'e', 'a', 'd', 'y'};
  117.         RtspClient rtsp_client(RTSP_URL, RTSP_USER, RTSP_PWD);

  118.         rtsp_client.setDataCallback(onRtspHandle);

  119.         mpp_dec = MppDecoderCreate(DECODE_TYPE_H264);
  120.         if (!mpp_dec) {
  121.                 std::cout << "MppDecoderCreate error!\n" << std::endl;
  122.                 return -1;
  123.         }

  124.         rga = RgaCreate();
  125.         if (!rga) {
  126.                 MppDecoderDestroy(mpp_dec);
  127.                 std::cout << "rgaCreate error!\n" << std::endl;
  128.                 return -1;
  129.         }

  130.         run_flag = 1;

  131.         rtsp_client.enable();

  132.         std::thread t_decode(decode_thread, rga);

  133.         while (run_flag) {
  134.                 usleep(10000);
  135.         }

  136.         rtsp_client.disable();

  137.         run_flag = 0;

  138.         t_decode.join();

  139.         RgaDestroy(rga);

  140.         MppDecoderDestroy(mpp_dec);

  141.         return 0;
  142. }

复制代码
回复

使用道具 举报

Davie_zju

注册会员

积分
110
发表于 2020-5-20 15:54:29 | 显示全部楼层
zerollzeng 发表于 2019-10-8 10:08
谢谢可以了,用vlc也不能打开,后来发现是路由问题,后来人引以为鉴哈哈

怎么解决的啊,我改网段的时候把路由也改了但还是有错,请问你是怎么解决的?
回复

使用道具 举报

Davie_zju

注册会员

积分
110
发表于 2020-5-20 15:56:08 | 显示全部楼层
cr7jj 发表于 2020-3-10 17:01
[toybrick@toybrick build]$ ./rtsp_ssd
mpi: mpp version: Without VCS info
mpp_rt: NOT found ion allo ...

请问你解决了吗
回复

使用道具 举报

Davie_zju

注册会员

积分
110
发表于 2020-5-20 15:56:30 | 显示全部楼层
cr7jj 发表于 2019-11-13 17:19
我想问问,后来怎么解决

请问你解决了吗
回复

使用道具 举报

hellosong

注册会员

积分
178
发表于 2020-6-11 14:31:28 | 显示全部楼层
Debian10  按照wiki安装了rtsp client 的依赖库, cmake这个demo提示没有curl库?Debian如何安装curl库
回复

使用道具 举报

hellosong

注册会员

积分
178
发表于 2020-6-11 14:34:02 | 显示全部楼层
lipandeng 发表于 2020-4-29 12:26
解决了,系统是debian10 ,解决不了可以发邮寄给我:你参考下,

请问你Debian10的rtsp client的环境怎么配的,我在debian10 下编译找不到curl库
回复

使用道具 举报

hellosong

注册会员

积分
178
发表于 2020-6-11 15:08:28 | 显示全部楼层
Debian10  有依赖库安装教程吗?? 之前编译报错curl找不到,安装之后编译报找不到opencv2/core/core.hpp 这些opencv的头文件,系统中可以找到opencv的库但却没有opencv的头文件?
回复

使用道具 举报

hellosong

注册会员

积分
178
发表于 2020-6-12 11:26:28 | 显示全部楼层
我这边在Debian10 上运行这个取流demo,wiki的以来环境都装了, mpp这边报错了 请帮忙解答一下

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表