gstreamer基础教程1-Hello world

gStreamer 官方教程资源大全 1. 入门教程:Basic tutorials 这里列一个GStreamer入门课程清单,大家按需选择吧。 基础教程1:Hello world!—— 惯例性的 “Hello world” 程序 基本教程2:GStreamer概念 基础教程3:动态管道 基础教程4:时间管理 基础教程5: GUI工具包集成 基础教程6:媒体格式和Pad功能 基本教程7:多线程和Pad可用性 基础教程8:管道短路操作 基础教程9:媒体信息收集 基本教程10:GStreamer工具 基本教程11:调试工具 基础教程12:流媒体 基 阅读详情

索引:https://blog.youkuaiyun.com/knowledgebao/article/details/84621238

Goal

编写一个类似于hello world的视频播放程序,核心代码只有4句。初始化、设置参数、开始播放、监听消息,当然最后要释放资源。

Nothing better to get a first impression about a software library than to print “Hello World” on the screen!

But since we are dealing with multimedia frameworks, we are going to play a video instead.

Do not be scared by the amount of code below: there are only 4 lines which do real work. The rest is cleanup code, and, in C, this is always a bit verbose.

Without further ado, get ready for your first GStreamer application...

Hello world

下边代码运行正常的话,会弹出一个播放窗口,播放互联网上的视频和声音,当然你的网速。

Copy this code into a text file named basic-tutorial-1.c (or find it in your GStreamer installation).

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

If everything built fine, fire up the executable! You should see a window pop up, containing a video being played straight from the Internet, along with audio. Congratulations!

Walkthrough结构解析

Let's review these lines of code and see what they do:

初始化,所有gstream必须调用的接口。

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

This must always be your first GStreamer command. Among other things, gst_init():

  • Initializes all internal structures初始化内部结构

  • Checks what plug-ins are available检查可用的插件

  • Executes any command-line option intended for GStreamer命令行参数执行

If you always pass your command-line parameters argc and argv to gst_init() your application will automatically benefit from the GStreamer standard command-line options (more on this in Basic tutorial 10: GStreamer tools)

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

导入网络上的URI地址,这里涉及两部分gst_parse_launch和playbin。

This line is the heart of this tutorial, and exemplifies(例证) two key points: gst_parse_launch() and playbin.

gst_parse_launch

自动构建管道,适用于简单的,不包含高级功能的管道构建。有一个工具 gst-launch-1.0可以协助此函数的构建,具体详见Basic tutorial10

GStreamer is a framework designed to handle multimedia flows. Media travels from the “source” elements (the producers), down to the “sink” elements (the consumers), passing through a series of intermediate elements performing all kinds of tasks. The set of all the interconnected elements is called a “pipeline”.

In GStreamer you usually build the pipeline by manually assembling the individual elements, but, when the pipeline is easy enough, and you do not need any advanced features, you can take the shortcut: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 (see Basic tutorial 10: GStreamer tools to learn about gst-launch-1.0 and the gst-launch-1.0 syntax).

playbin

这是一个工具,会被gst_parse_launch调用,会根据用户传入参数,自动寻找合适的element进行组装,包括source和sink组件(element)。

So, what kind of pipeline are we asking gst_parse_launch()to build for us? Here enters the second key point: We are building a pipeline composed of a single element called playbin.

playbin is a special element which acts as a source and as a sink, and is a whole pipeline. Internally, it creates and connects all the necessary elements to play your media, so you do not have to worry about it.

It does not allow the control granularity that a manual pipeline does, but, still, it permits enough customization to suffice for a wide range of applications. Including this tutorial.

In this example, we are only passing one parameter to playbin, which is the URI of the media we want to play. Try changing it to something else! Whether it is an http:// or file:// URI, playbin will instantiate the appropriate GStreamer source transparently!

If you mistype the URI, or the file does not exist, or you are missing a plug-in, GStreamer provides several notification mechanisms, but the only thing we are doing in this example is exiting on error, so do not expect much feedback.

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

设置管道(pipeline)的状态,pipeline有4中状态,分别是:  GST_STATE_NULL ,GST_STATE_READY ,GST_STATE_PAUSED , GST_STATE_PLAYING

This line highlights another interesting concept: the state. Every GStreamer element has an associated state, which you can more or less think of as the Play/Pause button in your regular DVD player. For now, suffice to say that playback will not start unless you set the pipeline to the PLAYING state.

In this line, gst_element_set_state() is setting pipeline (our only element, remember) to the PLAYING state, thus initiating playback.

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

监听消息总线,直到文件播放完成或者出现致命错误。

These lines will wait until an error occurs or the end of the stream is found. gst_element_get_bus() retrieves the pipeline's bus, and gst_bus_timed_pop_filtered() will block until you receive either an ERROR or an EOS (End-Of-Stream) through that bus. Do not worry much about this line, the GStreamer bus is explained in Basic tutorial 2: GStreamer concepts.

And that's it! From this point onwards, GStreamer takes care of everything. Execution will end when the media reaches its end (EOS) or an error is encountered (try closing the video window, or unplugging the network cable). The application can always be stopped by pressing control-C in the console.

Cleanup

清空变量。

Before terminating the application, though, there is a couple of things we need to do to tidy up correctly after ourselves.

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

Always read the documentation of the functions you use, to know if you should free the objects they return after using them.

In this case, gst_bus_timed_pop_filtered() returned a message which needs to be freed with gst_message_unref()(more about messages in Basic tutorial 2: GStreamer concepts).

gst_element_get_bus() added a reference to the bus that must be freed with gst_object_unref(). Setting the pipeline to the NULL state will make sure it frees any resources it has allocated (More about states in Basic tutorial 3: Dynamic pipelines). Finally, unreferencing the pipeline will destroy it, and all its contents.


Conclusion结论

And so ends your first tutorial with GStreamer. We hope its brevity serves as an example of how powerful this framework is!

Let's recap a bit. Today we have learned:

  • How to initialize GStreamer using gst_init().

  • How to quickly build a pipeline from a textual description using gst_parse_launch().

  • How to create an automatic playback pipeline using playbin.

  • How to signal GStreamer to start playback using gst_element_set_state().

  • How to sit back and relax, while GStreamer takes care of everything,  using  gst_element_get_bus()  and   gst_bus_timed_pop_filtered().  

The next tutorial will keep introducing more basic GStreamer elements, and show you how to build a pipeline manually.

It has been a pleasure having you here, and see you soon!

GStreamer详解1 hello world void gst_init (int *argc, char **argv[]) 初始化所有内部数据结构. 检查所有可用的插件. 运行所有的命令行选项. GstElement * gst_element_factory_make (const gchar * factoryname, const gchar * name) 创建element对象 gst-inspect可以 阅读详情

相关推荐

Gstreamer基础教程1: Hello world

Gstreamer基础教程1:Hello world1. Goal2. Code3. 解析3.1. 使用的函数3.1.1. gst_init2.gst_parse_launch3.2. 整体分析 1. Goal 播放一段视频。 2. Code 编译运行 gcc basic-tutorial-1.c -o basic-tutorial-1 `pkg-config --cflags --libs gstreamer-1.0` ./basic-tutorial-1 basic-tutorial-1.c #inc

R_X 625

GStreamer使用详解

使用系统自带的源,安装过程中会报错,因此先切换源,这里优先选择清华的源,阿里的源部分不维护,会安装报错。 1.备份原来的源,将以前的源备份一下,以防以后可以用的。 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 2.打开/etc/apt/sources.list文件,在前面添加如下条目,并保存。 sudo vim /etc/apt/sources.list 3.摁i进入插入模式 4.然后摁 键盘的delete删除原有的源 ...

程序猿老樊的博客 6133

1、gstreamer基础教程-播放视频

基本思想:只是单纯记录一下官方的例子,具体信息看官方手册,本菜也是参考官方手册学习。

sxj731533730 1137

FFmpeg4.3系列之20:GStreamer小白入门

敬告:该系列的课程在抓紧录制更新中,敬请大家关注。敬告: 该系列的课程涉及:FFmpeg,WebRTC,SRS,Nginx,Darwin,Live555,等。包括:音视频、流媒体、直播、Android、视频监控28181、等。我将带领大家一起来学习:GStreamer开发框架的原理与实战、搭建开发环境、源码编译;GStreamer入门案例实战与原理详解具体内容包括:1.GStreamer入门简介与环境搭建。2.GStreamer源码编译。3.GStreamer入门案例实战与原理详解。 音视频与流媒体是一门很复杂的技术,涉及的概念、原理、理论非常多,很多初学者不学 基础理论,而是直接做项目,往往会看到c/c++的代码时一头雾水,不知道代码到底是什么意思,这是为什么呢? 因为没有学习音视频和流媒体的基础理论,就比如学习英语,不学习基本单词,而是天天听英语新闻,总也听不懂。所以呢,一定要认真学习基础理论,然后再学习播放器、转码器、非编、流媒体直播、视频监控、等等。 梅老师从事音视频与流媒体行业18年;曾亲手主导广电直播全套项目,精通h.264/h.265/aac,曾亲自参与百度app上的网页播放器等实战产品。目前全身心自主创业,主要聚焦音视频+流媒体行业,精通音视频加密、流媒体在线转码快编等热门产品。

GStreamer基础教程1:Hello World

目标 没有比在屏幕上打印“ Hello World”更好的关于软件库的第一印象了! 但是由于我们正在处理多媒体框架,所以我们将改为播放视频。 不要被下面的代码量吓到了:只有4行可以完成实际工作。剩下的就是清理代码,在C语言中,这总是有些冗长。 事不宜迟,为您的第一个GStreamer应用程序做准备... Hello World 将此代码复制到一个名为basic-tutorial-1.c...

ZONGXP的博客 2682

数据中心机房建设标准及依据

深刻理解、尊重并恪守这些依据,是我们以科学、经济、可靠的方式,为蓬勃发展的数字经济筑牢基石的唯一路径。让我们共同努力,以标准为依据,以匠心为精神,建造更多世界一流的高效能、高可用、高智能的绿色数据中心,共同赋能数字中国的宏伟事业,支撑中华民族在数字时代的伟大复兴征程中稳步前行!今天我将力图以宏大的视角和深入的剖析,系统性地阐述数据中心机房建设所应遵循的多层次、多维度的标准依据,揭示这些依据背后的深层逻辑与时代使命,并探讨其如何共同作用于一座世界级数据中心的诞生。,以支持万兆乃至更高速率的传输。

qq_39980997的博客 1139

详细的GStreamer开发教程

详细的GStreamer开发教程 文章目录详细的GStreamer开发教程1. 什么是GStreamer?2. GStreamer架构2.1 Media Applications2.2 Core Framework2.3 Plugins3. GStreamer组件3.1 Element创建一个 GstElement3.2 箱柜(bin)元件的状态3.3 衬垫(Pad)元件链接(Pad link)...

HanBlogs 4万+

HC32F460的GPIO重映射实战:如何用3步搞定SPI引脚冲突问题

本文详细介绍了HC32F460的GPIO重映射功能,通过三步操作解决SPI引脚冲突问题。文章解析了HC32F460的FuncGroup功能分组机制,提供了具体的寄存器配置步骤和验证技巧,并对比了与传统方案的性能优势,帮助工程师灵活配置引脚,优化硬件设计。

t4y5u6i7o的博客 918

GStreamer——教程——基础教程1:Hello World

这个函数将解析一条文本形式表示的pipeline并将其转化成一条真实的pipeline,使用起来十分便利。事实上,这个功能是非常方便,有一个完全围绕它构建的工具,您将获得非常熟悉(请参阅。是一个特殊的 element,它具备一个pipeline的所有特点,既有source,又有sink。如果您输入了错误的URI,或者文件不存在,或者您缺少一个插件,GStreamer提供了几种通知机制,但我们在本例中唯一要做的就是在出错时退出,所以不要期望太多反馈。,它是我们要播放的媒体的URI。尝试将其更改为某些内容。

FREEDOM_X的专栏 1222

YOLOv8模型压缩终极方案:LAMP剪枝实战,速度提升不掉点

一个庞大的模型虽然强大,但在实际部署,尤其是资源受限的边缘设备(如无人机、移动电话、嵌入式系统)上,却面临着严峻的挑战:高昂的内存占用、巨大的计算量以及随之而来的高延迟和高能耗。本教程从LAMP剪枝的深刻理论出发,详细解释了它如何通过最小化最坏情况下的L2失真,并借助巧妙的数学简化,最终推导出一种高效、无超参数、层自适应的剪枝策略。它如同为臃肿的模型进行一次精准的“瘦身手术”,通过移除网络中冗余或不重要的权重、神经元甚至整个结构,来显著降低模型的参数量和计算量(FLOPs),从而实现推理加速和资源节约。

LXY_LOVE36的博客 175

Ubuntu-22.04安装VMware虚拟机并安装Windows10

最近在研究虚拟机,主要集中在KVM、Virtualbox和VMware这三种虚拟机上。前面我已经研究了前两种虚拟机的安装和使用方式,这篇文章介绍3兄弟中最后一个虚拟机安装和使用方式。Virtualbox虚拟机安装和使用KVM虚拟机安装和使用相比于前两种,VMware的安装方式最麻烦,但是综合体验下来我感觉流畅度最好。如果你确实有在Linux上使用VMware虚拟机的需求,那不妨跟着我看下去吧。1、gcc版本和内核版本一定要匹配上,否则会出各种错误。

jiexijihe945的博客 4116

Gstreamer教程 1 Hello world

pipeline.set_state(Gst.State.PLAYING),设置状态,开始播放。这个没有缓冲,所以网速慢的时候可能会在几秒后停止,pipeline.set_state(Gst.State.NULL),释放资源。然后运行python3 basic-tutorial-1.py。bus = pipeline.get_bus(),获取总线。Gst.init(sys.argv[1:]),初始化。),设置阻塞,直到遇到错误,或者播放结束。xxxx巴啦啦,占个位置,之后细说。

wzy_777的博客 227

37、基于铁电场效应晶体管(FeFET)的片上深度神经网络(DNN)直接反馈对齐训练

本文提出了一种基于铁电场效应晶体管(FeFET)的深度神经网络(DNN)训练加速器架构,结合直接反馈对齐(DFA)算法和FeFET的独特物理特性,以解决当前DNN训练中反向传播(BP)算法带来的高计算开销、复杂数据依赖和高能耗问题。通过设计基于FeFET的MVM引擎、低功耗ADC和随机数生成器(RNG),该架构在速度和功率效率方面相比现有基于ReRAM的加速器分别提升了1.3倍和2.5倍。研究为未来高效能AI训练硬件的发展提供了新的思路和实现路径。

wine的专栏 163

GStreamer 基础教程学习 1 - Hello World(GStreamer Basic tutorial 1 - Hello World)

https://gstreamer.freedesktop.org/documentation/tutorials/basic/hello-world.html?gi-language=c 重要的知识点: 1. gst_init() /* Initialize GStreamer */ gst_init (&argc, &argv); This must always ...

gsymichael的专栏 902

【WorkBuddy从入门到精通实战教程】使用手册 第 2 章 WorkBuddy的下载、安装、登录与更新

摘要:WorkBuddy官方下载地址为https://www.codebuddy.cn/work/,支持Mac和Windows系统,需根据设备自动匹配版本。安装时需核对发布者信息,Mac用户需拖入应用程序文件夹。登录支持微信扫码或手机号,公司电脑安装需IT授权。更新通过个人中心检查,遇到安装包损坏、登录失败或文件读写问题时,建议重新下载、检查网络/权限或联系官方支持。重要文件建议定期备份,避免直接操作原文件。(149字)

企鹅码农的专属播客,分享10多年的实战案例和经验解读,包含YOLO、RT-DETR、AI等各个工作领域。 1862

华为od 面试八股文_测试/测试开发_05_含答案

华为od 面试八股文_测试/测试开发_05_含答案

MISAYAONE的博客 2558

GStreamer基础教程1 - Hello World

本篇教程会学到: 如何使用gst_init()初始化GStreamer 如何使用gst_parse_launch()从文本描述来快速构建一个pipeline 如何使用playbin创建一个自动播放的pipeline 如何使用gst_element_set_state()通知GStreamer开始播放 如何使用gst_element_get_bus()和gst_bus_timed_pop_filtered()处理事件通知 学习一门编程语言,打印一个hello world是最好的实践。学习gstreamer

白纸的专栏 872

【matlab】基于 Simulink 的空调恒温控制系统仿真建模

本文介绍了基于Simulink的空调恒温控制系统仿真建模方法。系统采用PID控制算法,通过传感器测量温度、控制器计算信号、执行器调节功率来实现恒温控制。文章详细阐述了Simulink模型搭建步骤,包括PID控制器、房间热力学特性模拟等模块的实现,并提供了测试流程和多种实际部署场景。该方法可有效验证控制算法性能,优化系统设计,适用于家用、商用、工业及汽车空调系统。未来可结合智能算法和节能优化技术进一步提升系统性能。

走向CTO的路上... 920

GStreamer Tutorial 中文翻译:Basic tutorial 1: Hello world

GStreamer Tutorial 9中文翻译 文章目录GStreamer Tutorial 9中文翻译前言[Basic tutorial 1: Hello world!](https://gstreamer.freedesktop.org/documentation/tutorials/basic/hello-world.html?gi-language=c)目的Hello world代码走读`gst_parse_launch``playbin`清理工作结论 前言 由于工作原因,用的GStreame

wuchangwen0216的博客 339

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Gstreamer基础教程1:hello world! python

文章目录前言一、本节目标二、Hello World三、程序通读gst_parse_launchplaybinCleanup四、总结 前言 本文根据GStreamer官方文档书写,用于学习和备忘。 提示:以下是本篇文章正文内容,下面案例可供参考 一、本节目标 对一个软件库而言,没有什么比能在屏幕上打印出“Hello World”更好的第一印象了! 但由于我们使用的是多媒体框架,我们将播放视频。 准备好您的第一个GStreamer应用程序…… 二、Hello World basic-tutorial-1.p.

SYGgogogo的博客 4833

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

GStreamer官方入门课程1:Hello World!

没有什么比在屏幕上打印“Hello World”更能给人留下软件库的第一印象了! 但既然我们要处理多媒体框架,我们就要播放视频了。 不要被下面的代码量吓倒:只有4行代码可以完成真正的工作。剩下的是清理代码,在C语言中,这总是有点冗长。 不用再费吹灰之力,准备好您的第一个GStreamer应用程序...

程序猿视角 1237

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Gstreamer Basic tutorial 1: Hello world!

1,Ubuntu已经安装了gstreamer库,因此只需要再安装几个开发库即可,是 libstreamer0.10-0 libstreamer0.10-dev libstreamer0.10-0-dbg 在新立得里选中应用即可 2,测试gstreamer开发库 #include gst/gst.h> int main (int   argc,char *arg

young honker 1422

GStreamer笔记 -- 1.Hello world

GStreamer笔记 -- 1.Hello world 因为项目需要,要用到deepstream,然后deepstream又是基于GStreamer库写的,因此学习一下GSreamer,尝试了一下,认为如果是只关注应用层,重点不在于编解码的话,GStreamer是最好的选择,如果要做视频编解码的话ffmpeg是个不错的选择 ...

xf1234的博客 363

【GStreamer 】Basic tutorials-Basic tutorial 1: Hello world!

这些教程描述了理解其余教程所需的一般主题。

qq_43298381的博客 516

gstreamer开发实例1: Hello world!

本教程展示了一下内容:如何使用CMake构建GStreamer程序。如何使用gst_init()初始化GStreamer。如何使用快速构建一条pipeline。如何使用playbin创建一条自动的播放pipeline。如何使用向GStreamer发送开始播放信号。如何使用和监听pipeline并进行相关处理。

浩瀚之水的专栏 304
上一篇: gobject相关概念GNU,GNOME,GLIB,GTK,GTYPE
下一篇: gstreamer基础教程2-GStreamer concepts
knowledgebao
博客等级 码龄15年 401粉丝 198原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值