Gstreamer基础教程+Qt

系列文章目录

第一章  环境配置

第一章  基础概念


前言

      本文主要是按照Gstreamer官方文档框架进行讲解,建议入门之后多观看Gstreamer官方文档,官方文档地址:基础教程 2:GStreamer 概念


 

一、例程

例程中管道创建可以通过命令实现 :gst-launch-1.0 videotestsrc !autovideosink 

gst-launch-1.0是运行管道命令

#include "widget.h"
#include <QApplication>

#include <gst/gst.h>

int main(int argc, char *argv[])
{
     QApplication a(argc, argv);

     GstElement *pipeline, *source, *sink;
     GstBus *bus;
     GstMessage *msg;
     GstStateChangeReturn ret;

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

     /* Create the elements */
     source = gst_element_factory_make ("videotestsrc", "source");
     sink = gst_element_factory_make ("autovideosink", "sink");

     /* Create the empty pipeline */
     pipeline = gst_pipeline_new ("test-pipeline");

     if (!pipeline || !source || !sink) {
       g_printerr ("Not all elements could be created.\n");
       return -1;
     }

     /* Build the pipeline */
     gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
     if (gst_element_link (source, sink) != TRUE) {
       g_printerr ("Elements could not be linked.\n");
       gst_object_unref (pipeline);
       return -1;
     }

     /* Modify the source's properties */
     g_object_set (source, "pattern", 0, NULL);

     /* Start playing */
     ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
     if (ret == GST_STATE_CHANGE_FAILURE) {
       g_printerr ("Unable to set the pipeline to the playing state.\n");
       gst_object_unref (pipeline);
       return -1;
     }

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

     /* Parse message */
     if (msg != NULL) {
       GError *err;
       gchar *debug_info;

       switch (GST_MESSAGE_TYPE (msg)) {
         case GST_MESSAGE_ERROR:
           gst_message_parse_error (msg, &err, &debug_info);
           g_printerr ("Error received from element %s: %s\n",
               GST_OBJECT_NAME (msg->src), err->message);
           g_printerr ("Debugging information: %s\n",
               debug_info ? debug_info : "none");
           g_clear_error (&err);
           g_free (debug_info);
           break;
         case GST_MESSAGE_EOS:
           g_print ("End-Of-Stream reached.\n");
           break;
         default:
           /* We should not reach here because we only asked for ERRORs and EOS */
           g_printerr ("Unexpected message received.\n");
           break;
       }
       gst_message_unref (msg);
     }

     /* Free resources */
     gst_object_unref (bus);
     gst_element_set_state (pipeline, GST_STATE_NULL);
     gst_object_unref (pipeline);
     return a.exec();
}

二、Gstreamr基本结构

      Gstreamer处理音视频就是创建一个处理管道,而管道是由N个元素组成;管道类似于流水线,材料从管道口(source)流入,经过管道处理,从管道另一侧(sink)流出,制成产品。

三、主要函数说明

gst_init (&argc, &argv);   //gst初始化函数
gst_element_factory_make ("videotestsrc", "source"); //创建元素:名称为source的视频采集器
gst_pipeline_new ("test-pipeline");   //创建空管道
gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);//向管道中增加元素
g_object_set (source, "pattern", 0, NULL); //给元素设置参数 
gst_element_set_state (pipeline, GST_STATE_PLAYING);//设置管道的状态

gst_object_unref (pipeline); //释放管道资源


总结

   本片主要介绍gst的一些基础函数的使用以及相关概念,后面会做一些基础demo。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值