初识gstreamer——安装与hello

gstreamer

一、安装

参考:https://www.cnblogs.com/walker-lin/p/11520064.html)
基于16.04 Ubuntu系统安装gstreamer。
1.下载:https://gstreamer.freedesktop.org/src/
在这里插入图片描述
2.解压:

tar -vxf gst....tar.xz

3.安装
配置环境:

sudo apt-get install bison
sudo apt-get install flex

编译安装:

sudo apt-get install build-essential dpkg-dev flex bison autotools-dev automake liborc-dev autopoint libtool gtk-doc-tools libgstreamer1.0-dev

cd gstreamer-1.16.0
./configure
sudo make
sudo make install
sudo vim ~/.bashrc
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
source ~/.bashrc
cd ..

同样按顺序处理:

sudo apt-get install libxv-dev libasound2-dev libtheora-dev libogg-dev libvorbis-dev

gst-plugins-base-1.16.0

sudo apt-get install libbz2-dev libv4l-dev libvpx-dev libjack-jackd2-dev libsoup2.4-dev libpulse-dev

gst-plugins-good-1.16.0

sudo apt-get install faad libfaad-dev libfaac-dev

gst-plugins-bad-1.16.0

sudo apt-get install libx264-dev libmad0-dev

gst-plugins-ugly-1.16.0

sudo apt-get install yasm

gst-libav-1.16.0

sudo vim ~/.bashrc

LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH

source ~/.bashrc

验证:dpkg -l | grep gstreamer

二、运行hello:

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

新建 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=file:///home/gstreamer/sintel_trailer-480p.webm", NULL);
  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;
}

在这里插入图片描述

三、代码解析

https://www.cnblogs.com/xleng/p/11008239.html
初始化:

 gst_init (&argc, &argv);

gst_init负责以下资源初始化:

  • 初始化gstreamer库
  • 注册内部element
  • 加载插件列表,扫描列表中及相应路径下的插件
  • 解析并执行命令行参数

创建Pipeline:
当pipeline比较简单且不需要对pipeline中的element进行过多的控制时,采用gst_parse_launch来简化pipeline的创建。

设置播放状态
只有当状态处于PLAYING时,pipeline才会播放/处理数据

等待播放结束
gstreamer框架通过bus,将所发生的事件通知到应用程序,这里首先取得pipeline的bus对象,通过gst_bus_timed_pop_filtered以同步的方式等待bus上的ERROR或EOS消息。

释放资源
将不再使用的msg,bus对象销毁,将pipeline状态设置为NULL,最后销毁pipeline对象。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值