【GStreamer 】5-1 USB相机转RTSP网络视频流 初次接触

29 篇文章 8 订阅
19 篇文章 29 订阅

        前面铺垫了很多,从显示,到压缩,经过一段时间的学习,终于大致清楚了gstreamer如何扩展应用,终于到现在,可以开始一开始就定好的目标,把USB相机转成RTSP流的网络相机。这在很多机器人本体应用还是很有必要,USB相机小巧,便宜,可以安装很多个,为了降低视频远传后显示对带宽的需求,我们肯定是需要将其压缩,并且装成RTSP流。

前面我们讲了很多基础的,非基础的,这里我们罗列一下:

        通过这些铺垫,会对后续工作开展有很多帮助。后续我们的测试和学习过程还是延续了一样的硬件环境,及TX1核心模块,USB 720P的相机,就不在重复交代,有需要前面随便翻一篇就有说明。

0. 安装gstreamer-rtsp-server

git clone  -b 1.8 https://github.com/GStreamer/gst-rtsp-server.git  //下载源码
cd gst-rtsp-server      
./autogen.sh
sudo make
sudo make install

 

问题1 解决:configure: error: You need to have gtk-doc >= 1.12 installed to build [GStreamer]

 

sudo apt install gtk-doc-tools

进入示例查看代码:

cd /home/nvidia/Downloads/gst-rtsp-server/examples

我们主要使用test-launch 这个测试文件。

 

1、测试组件test-launch源码说明

#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
​
 /* 注释:端口宏定义 */
#define DEFAULT_RTSP_PORT "8554"
​
static char *port = (char *) DEFAULT_RTSP_PORT;
​
static GOptionEntry entries[] = {
  {"port", 'p', 0, G_OPTION_ARG_STRING, &port,
      "Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"},
  {NULL}
};
​
int main (int argc, char *argv[])
{
  GMainLoop *loop;
  GstRTSPServer *server;
  GstRTSPMountPoints *mounts;
  GstRTSPMediaFactory *factory;
  GOptionContext *optctx;
  GError *error = NULL;
​
  optctx = g_option_context_new ("<launch line> - Test RTSP Server, Launch\n\n"
      "Example: \"( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )\"");
  g_option_context_add_main_entries (optctx, entries, NULL);
  g_option_context_add_group (optctx, gst_init_get_option_group ());
  if (!g_option_context_parse (optctx, &argc, &argv, &error)) {
    g_printerr ("Error parsing options: %s\n", error->message);
    g_option_context_free (optctx);
    g_clear_error (&error);
    return -1;
  }
  g_option_context_free (optctx);
​
  loop = g_main_loop_new (NULL, FALSE);
​
  /* create a server instance */
  server = gst_rtsp_server_new ();
  g_object_set (server, "service", port, NULL);
​
  /* get the mount points for this server, every server has a default object
   * that be used to map uri mount points to media factories */
  mounts = gst_rtsp_server_get_mount_points (server);
​
  /* make a media factory for a test stream. The default media factory can use
   * gst-launch syntax to create pipelines.
   * any launch line works as long as it contains elements named pay%d. Each
   * element with pay%d names will be a stream */
  factory = gst_rtsp_media_factory_new ();
  gst_rtsp_media_factory_set_launch (factory, argv[1]);
​
  /* attach the test factory to the /test url */
  gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
​
  /* don't need the ref to the mapper anymore */
  g_object_unref (mounts);
​
  /* attach the server to the default maincontext */
  gst_rtsp_server_attach (server, NULL);
​
  /* start serving */
  g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port);
  g_main_loop_run (loop);
​
  return 0;
}

编译:

gcc test-launch.c -o test-launch $(pkg-config --cflags --libs gstreamer-rtsp-server-1.0 gstreamer-1.0)

测试:

./test-launch "( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )"

 

播放rtsp流:需要显示器支持

gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8554/test

也可以使用VLC在WIN电脑上播放,只要在同一个局域网就可以:

rtsp://192.168.55.1:8554/test

 

2、使用USB相机做为服务器视频源

./test-launch --gst-debug-level=3 "( v4l2src device=/dev/video0 ! videoconvert! videoscale ! video/x-raw, width=640, height=480, framerate=25/1 ! queue ! x264enc bitrate=2048 !  rtph264pay name=pay0 pt=96 )"

播放rtsp流:

rtsp://192.168.55.1:8554/test

 

这个目前的延时有个10秒左右,有很大的优化空间。

服务器还会打印很多信息警告:

同时,CPU占用也比较高

 

后续我们的主要工作就是分两点:

(1)详细了解gstreamer-rtsp-server 中使用的一些控件细节

(2)优化CPU占用,进行硬件加速辅助

  • 6
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机器人虎哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值