其他分享
首页 > 其他分享> > GStreamer入门-1

GStreamer入门-1

作者:互联网

Ubuntu18.04-GStreamer入门-1

Gstream安装

参见官网:Installing on Linux

第一步 —— 在Ubuntu上安装GStreamer

sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio

第二步 —— 使用GStreamer构建应用程序

pkg-config --cflags --libs gstreamer-1.0

第三步 —— 获取教程的源代码

git clone https://gitlab.freedesktop.org/gstreamer/gst-docs

第四步 ——Building 教程

gcc basic-tutorial-1.c -o basic-tutorial-1 `pkg-config --cflags --libs gstreamer-1.0`

提示:需要进入存放教程文件的文件夹内才能building
参考我的路径是:~/gst-docs/examples/tutorials

第五步 ——Running 教程

./basic-tutorial-1

源码 basic-tutorial-1.c

#include <gst/gst.h>

int main(int argc, char *argv[])
{
  GstElement *pipeline;
  GstBus *bus;
  GstMessage *msg;

  /* Initialize GStreamer */
  gst_init(&argc, &argv);

  /* Build the pipeline */
  pipeline =
      gst_parse_launch("playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm",
                       NULL);

  /* Start playing */
  gst_element_set_state(pipeline, GST_STATE_PLAYING);

  /* Wait until error or EOS */
  bus = gst_element_get_bus(pipeline);
  msg =
      gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
                                 GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

  /* Free resources */
  if (msg != NULL)
    gst_message_unref(msg);
  gst_object_unref(bus);
  gst_element_set_state(pipeline, GST_STATE_NULL);
  gst_object_unref(pipeline);
  return 0;
}

Conclusion

  1. 在GStream中source这个elements可以看作生产者,sink这个elemen可以看作消费者,媒体数据从source出发,经过一系列的中间处理元素,最后到达sink。在这个过程中相互连接的元素的集合称之为“pipeline

  2. gst_init()
    这必须始终是第一个GStreamer命令
    gst_init():
    初始化所有内部结构
    检查可用的插件
    执行任何用于GStreamer的命令行选项

  3. gst_parse_launch()
    This function takes a textual representation of a pipeline and turns it into an actual pipeline, which is very handy. In fact, this function is so handy there is a tool built completely around it which you will get very acquainted with

  4. gst_element_set_state()
    设置pipeline(这里的pipeline是由GstElement定义的变量)的状态,当这个函数的第二个变量为GST_STATE_PLAYING,即是将媒体流的状态设置为playing状态;当第二个变量为GST_STATE_NULL,即释空

  5. gst_element_get_bus()

  6. gst_bus_timed_pop_filtered()

标签:pipeline,入门,bus,GStreamer,GST,gstreamer1.0,gst
来源: https://blog.csdn.net/jerry18863/article/details/120844670