linux搭建gst-rtsp-server

1.安装gstreamer基础库

sudo apt-get install gtk-doc-tools
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install libgl1-mesa-dev
sudo apt-get install gstreamer1.0-libav
sudo apt-get install gstreamer1.0-plugins-bad
sudo apt-get install gstreamer1.0-plugins-base
sudo apt-get install gstreamer1.0-plugins-ugly
sudo apt-get install gstreamer1.0-plugins-good
sudo apt-get install libgstrtspserver-1.0-dev

2.下载安装编译gstreamer-rtsp-server

# download src
git clone git://anongit.freedesktop.org/gstreamer/gst-rtsp-server

cd gst-rtsp-server

git branch -av
git checkout -B test
git reset --hard 8799fb5

# compile
./autogen.sh
make -j12

3.配置环境变量

sudo gedit ~/.bashrc   //打开bashrc文件

#在.bashrc末尾加上以下两行保存退出
export LD_LIBRARY_PATH=/usr/local/lib
export GST_PLUGIN_PATH=/usr/local/lib:/usr/lib/x86_64-linux-gnu/gstreamer-1.0

source ~/.bashrc

#查看gstreamer版本信息
gst-inspect-1.0 --version

4.推流

#编译gst-rtsp-server/examples/下的test_launch.c生成可执行文件test
cd gst-rtsp-server/examples/
gcc test-launch.c -o test $(pkg-config --cflags --libs gstreamer-rtsp-server-1.0 gstreamer-1.0)

#推流
./test --gst-debug-level=3 "( videotestsrc ! video/x-raw,format=I420,width=640,height=480 ! x264enc tune="zerolatency" threads=4 ! rtph264pay name=pay0 pt=96 )"

#元心设备端执行
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
GST_DEBUG=2

#拉流
gst-launch-1.0 rtspsrc latency=20 location="rtsp://127.0.0.1:8554/test" ! rtph264depay ! h264parse ! avdec_h264 ! autovideosink

5.test_launch.c源码,增加设置ip地址(46行)

#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;
    const gchar *newAddress = "192.168.100.101";
    gchar *address;

    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);

    /* 设置ip地址 */
    gst_rtsp_server_set_address(server, newAddress);

    /* 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, "/1", 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://%s:%s/test\n", gst_rtsp_server_get_address(server), port);
    g_main_loop_run (loop);

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值