Gstreamer在Ubuntu上的安装和MP3的播放
2014年09月20日 14:29:43 Linux ⁄ 共 6751字 暂无评论 ⁄ 被围观 2,785次

Gstreamer简单介绍:

GStreamer 作为流媒体应用框架,采用了基于插件(plugin)和管道(pipeline)的体系结构,框架中的所有的功能模块都被实现成可以插拔的组件(component),并且在需要的时候能够很方便地安装到任意一个管道上,由于所有插件都通过管道机制进行统一的数据,因此很容易利用已有的各种插件“组装”出一个功能完善的多媒体应用程序。

在Ubuntu上安装gstreamer:

在安装之前首先要设置代理

有三个地方:

1 network proxy

2  Synaptic Package Manager里的settings

3 在命令行里输入 gedit  etc/apt/apt.conf

然后在文件里加入

Acquire::http::proxy "http://student102:student@10.1.243.240:8080/";这里面的账号和密码老自动删除了,如代理有问题在进来看看这

一、去http://gstreamer.freedesktop.org/下载源码包,一般要安装gstreamer以下最基本的包,分别下载:

Gstreamer-0.10.35.tar.bz2

gst-plugins-base-0.10.35.tar.bz2

gst-plugins-good-0.10.30.tar.bz2

二、安装gstreamer:

解压后,进入目录直接执行./configure,此时出现如下错误:

configure: error: Could not find bison

出现这个错误,说明找不到bison,那么解决方案也很简单,安装bison。

解决办法:

administrator@ubuntu:~/gstreamer-0.10.35$ sudo apt-get install bison

make

make install

cd ..

再次运行./configure,出现如下错误:

administrator@ubuntu:~/gstreamer-0.10.35$ ./configure

....

checking for bison... /usr/bin/bison

checking bison version 2.4.1 >= 1.875... Yes

checking for flex... No

configure: error: Could not find flex

解决办法,同上面安装bison的过程:

administrator@ubuntu:~/下载/gstreamer-0.10.35$ sudo apt-get install flex

make

make install

cd ..

再次运行./configure,出现如下错误:

checking for GLIB... No

configure: No package 'glib-2.0' found

No package 'gobject-2.0' found

No package 'gthread-2.0' found

No package 'gmodule-no-export-2.0' found

configure: error: This package requires GLib >= 2.22 to compile.

解决办法:

administrator@ubuntu:~/gstreamer-0.10.35$ sudo apt-get install glib-2.0

make

make install

cd ..

再次运行./configure,出现如下错误:

configure: error: *** Working zlib library and headers not found ***

解决办法:

 

administrator@ubuntu:~/下载/glib-2.29.4$ sudo apt-get install zlib1g

 

 

administrator@ubuntu:~/下载/glib-2.29.4$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
...
configure: error: Package requirements (libffi >= 3.0.0) were not met:

No package 'libffi' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBFFI_CFLAGS
and LIBFFI_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

 

安装libffi

 

错误解决

 

 

administrator@ubuntu:~/下载/glib-2.29.4$ ./configure
...
checking for msgfmt... no
configure: error:
*** You must have either have gettext support in your C library, or use the
*** GNU gettext library. (http://www.gnu.org/software/gettext/gettext.html

安装gettex

administrator@ubuntu:~/下载/glib-2.29.4$ sudo apt-get install gettex

 

 

administrator@ubuntu:~/下载/glib-2.29.4$  ./configure
无错误。
administrator@ubuntu:~/下载/glib-2.29.4$  make & sudo make install

administrator@ubuntu:~/下载/gstreamer-0.10.35$ ./configure
。。。。
checking for XML... no
no
configure: error:
       Need libxml2 and development headers/files to build GStreamer.

       You can do without libxml2 if you pass --disable-loadsave to
       configure, but that breaks ABI, so don't do that unless you
       are building for an embedded setup and know what you are doing.

 

安装libxml2

 

administrator@ubuntu:~/下载/gstreamer-0.10.35$ sudo apt-get install libxml2

 

 

解压libxml2-2.7.7.tar.gz
administrator@ubuntu:~/下载/libxml2-2.7.7$ ./configure
出错:
config.status: executing libtool commands
/bin/rm: cannot remove `libtoolT': No such file or directory
Done configuring
administrator@ubuntu:~/下载/libxml2-2.7.7$ make & sudo make install

administrator@ubuntu:~/下载/gstreamer-0.10.35$ ./configure

 

安装完成

Configuration
   Version                    : 0.10.35
   Source code location       : .
   Prefix                     : /usr/local
   Compiler                   : gcc -std=gnu99
   Package name               : GStreamer source release
   Package origin             : Unknown package origin

   Documentation (manuals)    : no
   Documentation (API)        : no

   Debug Logging              : yes
   Pipeline XML load/save     : yes
   Command-line parser        : yes
   Option parsing in gst_init : yes
   Tracing subsystem          : yes
   Allocation tracing         : yes
   Plugin registry            : yes
   Plugin support               : yes
   Network support            : yes
   Unit testing support       : yes

   Debug                      : yes
   Profiling                  : no

   Building examples          : yes
   Building test apps         : yes
   Building tests that fail   : no

 

 

在安装完gstreamer后,安装其他plugins之前要设置PKG_CONFIG_PATH正确。

 

3.安装gst-plugins-base:
安装前要设置环境变量,由于gstreamer是默认安装,没有设置--prefix,所以将export
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH就行了
./configure,提示缺少liboil,去https://launchpad.net/ubuntu/+source/liboil/0.3.14

也可以在 gedit /etc/profile 末尾 加上下面的语句

export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

export

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

-3下载安装即可
make
make install

 

4.安装gst-plugins-good:
./configure
make
make install

这里有可能 在 Synaptic Package Manager里下载G++

到此可以用gst-launch -vm audiotestsrc ! audioconvert ! audioresample ! osssink
测试能在杨声器里听到蜂鸣音

 

注意:总之,在安装过程中,缺什么就apt-get install,找不到就去网上下载安装。

5.编写代码测试,最简单的mp3播放:
a.需要使用mad解码插件,因此首先要安装libid3tag0-dev和libmad0-dev
apt-get install liblid3tag0-dev
apt-get install libmad0-dev

b.接着安装gstreamer0.10-plugins-ugly才会安装上mad

 

这上面三个包得按顺序安装,要不可能出问题

 

编写.c

#include <gst/gst.h>   

#include <gtk/gtk.h>   

  

#define GTK_WINDOW 0   

  

static GtkWidget *window;  

  

static gboolean  

delete_event(GtkWidget *widget,  

              GdkEvent *event,  

              gpointer data)  

 

    return FALSE;  

 

  

static void  

destroy(GtkWidget *widget,  

         gpointer data)  

 

    gtk_main_quit ();  

 

  

static void  

window_create(void)  

 

    window gtk_window_new (GTK_WINDOW_TOPLEVEL);  

    g_signal_connect (G_OBJECT (window), "delete_event",  

                      G_CALLBACK (delete_event), NULL);  

    g_signal_connect (G_OBJECT (window), "destroy",  

                      G_CALLBACK (destroy), NULL);    

  

    gtk_widget_show (window);  

 

  

int   

main(int argc, char *argv[])  

     

    GstElement *pipeline, *filesrc, *decoder, *convert, *audiosink;  

  

#if GTK_WINDOW   

    gtk_init(&argc, &argv);  

    window_create();      

#endif   

    gst_init(&argc, &argv);      

   

    if (argc != 2)  

        g_print("usage: %s <mp3 filename>/n", argv[0]);  

        exit (-1);  

     

    

    pipeline gst_pipeline_new("pipeline");     

      

    filesrc gst_element_factory_make("filesrc", "disk_source");     

    decoder gst_element_factory_make("mad", "decoder");  

    convert gst_element_factory_make("audioconvert", "a-convert");  

    audiosink gst_element_factory_make("osssink", "play_audio");  

  

    g_object_set(G_OBJECT(filesrc), "location", argv[1], NULL);  

     

    gst_bin_add_many(GST_BIN(pipeline), filesrc, decoder, convert, audiosink, NULL);      

    gst_element_link_many(filesrc, decoder, convert, audiosink, NULL);  

      

    gst_element_set_state(pipeline, GST_STATE_PLAYING);  

      

#if GTK_WINDOW   

    gtk_main ();  

#else   

    while (gst_bin_iterate_recurse(GST_BIN(pipeline)));  

#endif   

      

    gst_element_set_state(pipeline, GST_STATE_NULL);      

    gst_object_unref(GST_OBJECT (pipeline));  

    exit (0);  

     

 

编译运行:

gcc -Wall $(pkg-config --cflags --libs gstreamer-0.10) hello.c -o hello
../hello 路径/yourfilename.mp3

【上篇】
【下篇】

给我留言

留言无头像?