创建文件 basic-tutorial-3.c
编译 gcc basic-tutorial-3.c -o basic-tutorial-3 pkg-config --cflags --libs gstreamer-1.0
执行 ./basic-tutorial-3

参考:
详细的GStreamer开发教程

#include <gst/gst.h>/* Structure to contain all our information, so we can pass it to callbacks */
typedef struct _CustomData {GstElement *pipeline;GstElement *source;GstElement *convert;GstElement *sink;
} CustomData;/* Handler for the pad-added signal */
static void pad_added_handler (GstElement *src, GstPad *pad, CustomData *data);int main(int argc, char *argv[]) {CustomData data;GstBus *bus;GstMessage *msg;GstStateChangeReturn ret;gboolean terminate = FALSE;/* Initialize GStreamer */gst_init (&argc, &argv);/* Create the elements */data.source = gst_element_factory_make ("uridecodebin", "source_fan");    //名字在这个文件中不重要data.convert = gst_element_factory_make ("audioconvert", "convert_fan");data.sink = gst_element_factory_make ("autoaudiosink", "sink_fan"); /* Create the empty pipeline */data.pipeline = gst_pipeline_new ("test-pipeline");   //名字在这个文件中不重要if (!data.pipeline || !data.source || !data.convert || !data.sink) {g_printerr ("Not all elements could be created.\n");return -1;}/* Build the pipeline. Note that we are NOT linking the source at this* point. We will do it later. */gst_bin_add_many (GST_BIN (data.pipeline), data.source, data.convert , data.sink, NULL);  //根据流程排序if (!gst_element_link (data.convert, data.sink)) {g_printerr ("Elements could not be linked.\n");gst_object_unref (data.pipeline);return -1;}/* Set the URI to play */g_object_set (data.source, "uri", "https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm", NULL);  //设定资源怎么走么?/* Connect to the pad-added signal */g_signal_connect (data.source, "pad-added", G_CALLBACK (pad_added_handler), &data);  //参数2  (名字不重要)在这个/*
说明:
此函数的的作用将一个事件(发出信号)的请求及处理这件事件的方法连接起来。函数中的几个参数意思是:instance : 要作用到的实例,如想要操作的窗口,按钮等。detailed_signal : 具体的信号类型,如关闭,缩小,放大等。c_handler :  这里是一个回调函数,在回调函数里会具体定义操作的内容。data : 传递到第 3 个参数,也就是回调函数的一个参数。
*//* Start playing */ret = gst_element_set_state (data.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 (data.pipeline);return -1;}/* Listen to the bus */bus = gst_element_get_bus (data.pipeline);do {msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS);/* 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);terminate = TRUE;break;case GST_MESSAGE_EOS:g_print ("End-Of-Stream reached.\n");terminate = TRUE;break;case GST_MESSAGE_STATE_CHANGED:/* We are only interested in state-changed messages from the pipeline */if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data.pipeline)) {GstState old_state, new_state, pending_state;gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);g_print ("Pipeline state changed from %s to %s:\n",gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));}break;default:/* We should not reach here */g_printerr ("Unexpected message received.\n");break;}gst_message_unref (msg);}} while (!terminate);/* Free resources */gst_object_unref (bus);gst_element_set_state (data.pipeline, GST_STATE_NULL);gst_object_unref (data.pipeline);return 0;
}/* This function will be called by the pad-added signal */
static void pad_added_handler (GstElement *src, GstPad *new_pad, CustomData *data) {GstPad *sink_pad = gst_element_get_static_pad (data->convert, "sink");GstPadLinkReturn ret;GstCaps *new_pad_caps = NULL;GstStructure *new_pad_struct = NULL;const gchar *new_pad_type = NULL;g_print ("Received new pad '%s' from '%s':\n", GST_PAD_NAME (new_pad), GST_ELEMENT_NAME (src));/* If our converter is already linked, we have nothing to do here */if (gst_pad_is_linked (sink_pad)) {g_print ("We are already linked. Ignoring.\n");goto exit;}/* Check the new pad's type */new_pad_caps = gst_pad_get_current_caps (new_pad);new_pad_struct = gst_caps_get_structure (new_pad_caps, 0);new_pad_type = gst_structure_get_name (new_pad_struct);if (!g_str_has_prefix (new_pad_type, "audio/x-raw")) {g_print ("It has type '%s' which is not raw audio. Ignoring.\n", new_pad_type);goto exit;}/* Attempt the link */ret = gst_pad_link (new_pad, sink_pad);if (GST_PAD_LINK_FAILED (ret)) {g_print ("Type is '%s' but link failed.\n", new_pad_type);} else {g_print ("Link succeeded (type '%s').\n", new_pad_type);}exit:/* Unreference the new pad's caps, if we got them */if (new_pad_caps != NULL)gst_caps_unref (new_pad_caps);/* Unreference the sink pad */gst_object_unref (sink_pad);
}

gstreamer 代码实现相关推荐

  1. GStreamer(一)

    http://antkillerfarm.github.io/ 概况 当前GStreamer主要有两个大的版本分支: 1)0.10.x系列.这个版本系列的历史较久,相关资源比较丰富.但目前官方已经不再 ...

  2. gstreamer读取USB摄像头H264帧并用rtmp推流

    文章目录 gstreamer命令行实现rtmp推流 gstreamer代码实现rtmp推流 因为要在嵌入式端使用rtmp推流,目前我知道的有三种办法,ffmpeg.gstreamer.librtmp, ...

  3. Python Gstreamer播放rtsp视频流(海康IPCAM)

    Python Gstreamer播放rtsp视频流(海康IPCAM) 播放思路: 图解: 1.首先通过IPCAM的ip与用户等信息获得rtsp码:   海康新版IPCAM的rtsp地址规则为:rtsp ...

  4. Python Gstreamer播放rtsp视频(含音频)(海康IPCAM)

    Python Gstreamer播放rtsp视频(海康IPCAM) 播放思路详见博客:Python Gstreamer播放rtsp视频流(海康IPCAM) 元件连接图解:   这里开始想使用tee分流 ...

  5. python Gstreamer 播放不同编码格式的视频文件

    python Gstreamer 播放不同编码格式的视频文件   在之前的博客中写过了如何查找一个视频中的video以及audio编码格式,并根据编码的格式挑选元件对视频进行播放.但在相同的封装格式的 ...

  6. gstreamer简介

    常用 gchar * caps_string = gst_caps_to_string (new_selected_caps); g_free (caps_string); 需要弄懂的问题 tunne ...

  7. 从零开始成为GStreamer专家——基于Windows的GStreamer从源码下载、编译到开发

    基于Windows的GStreamer从源码下载.编译到开发 本文介绍了在GStreamer下载方法, 使用过程中的部分依赖,以及在Windows上编译配置GStreamer 过程,为学习GStrea ...

  8. 开发之准备:为目标设备创建映像

    (作者:徐诚 http://blog.csdn.net/shizhebsys 保留版权) 开发之准备:为目标设备创建映像 简介 Moblin Image Creator是用来创建目标环境映像的工具.可 ...

  9. 隐私合规:收集SDK部分介绍

    com.meizu.cloud.pushsdk.SystemReceiver 魅族推送服务是由魅族公司为开发者提供的消息推送服务,开发者可以向集成了魅族 push SDK 的客户端实时地推送通知或者消 ...

最新文章

  1. vrrp preempt mode configed in keepalived conf
  2. ARP病毒查找与防范
  3. 丢失控制文件,有旧的备份控制文件,之后有drop表空间和create表空间的操作恢复。...
  4. 美团2015校招哈尔滨站笔试题--第二题
  5. python报错输出到日志_Python日志记录和子进程输出和错误流
  6. catch的执行与try的匹配
  7. c++ array赋值问题
  8. 记录第一次部署servlet实例
  9. jzoj4050-寻宝游戏【二分,树状数组,LCA】
  10. “BindingNavigator”如何在删除前弹出确认框?
  11. php ios 判断字符串长度,iOStextfield 限制输入字符长度和过滤表情符号
  12. Extreme以5500万美元收购Brocade数据中心网络资产
  13. 虚拟机软件、虚拟机、操作系统它们之间的关系
  14. piwik阅读(整体结构)
  15. 基于8086的16位键盘操作系统仿真设计-基于8086LCD1602显示仿真设计-基于8086的LED中文显示屏显示设计-基于8086方波锯齿波三角波发生器-基于8086的LED点阵汉字流水显示设计
  16. 用人话说说文明和文化
  17. codeforce 755 B
  18. ORA-01652: 无法通过 128 (在表空间 LTE_PM_TEMP 中) 扩展 temp 段
  19. i7 10750h是标压吗 属于什么档次 i7 10750h天梯图
  20. 【国产之光】:龙芯1B(嵌入式方向)

热门文章

  1. 探索2018年春节互联网流量峰值再创新高背后
  2. 做好博客平台,互通知识有无
  3. 魔兽争霸 / 星际争霸 无法使用 CTRL + 1 进行编队
  4. Visual Studio安装,更新,报错,密钥
  5. Python每日一练(12)-掷骰子
  6. python对比excel两列数据_python 对比excel表格数据表-python实现两个excel表列数据对比若源表与目标表存......
  7. python矩阵的螺旋排列_飘逸的python – 打印螺旋矩阵 | 学步园
  8. Jsp页面中双引号问题
  9. 消息人士透露JDI今年开始为苹果Apple Watch供应OLED屏幕
  10. iCheck插件 全选和获取value值的解决方法