gstreamer的安装和简单的mp3编写

来源:互联网 发布:mac怎么看电池循环次数 编辑:程序博客网 时间:2024/05/14 23:57

为了使贪吃蛇在吃到食物时,能够发出声音。网上找到gstreamer可以在windows下使用,相
当于windows下的directshow。


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

这篇文章“用 GStreamer 简化 Linux 多媒体开发”对GStreamer的概念介绍的挺好的.
http://www.ibm.com/developerworks/cn/linux/l-gstreamer/

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

gst-plugins-base

gst-plugins-good

2.安装gstreamer:
解压后,进入目录直接执行./configure,可能会出错,如提示缺少bison,flex等,运行apt
-get install bison安装
make
make install

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
-3下载安装即可
make
make install

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

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

总之,在安装过程中,缺什么就apt-get install,找不到就去网上下载安装。
此外,在安装完gstreamer后,安装其他plugins之前要设置PKG_CONFIG_PATH正确。

“ld.so.conf 文件与PKG_CONFIG_PATH变量”
http://hi.baidu.com/litaosmile/blog/item/751be4f45bbb4ee67609d7be.html

”安装gstreamer到ARMv6平台“的可以参考:
http://hi.baidu.com/9562512/blog/item/ee9af9d39351f73d970a16b8.html

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


b.接着安装gstreamer0.10-plugins-ugly才会安装上mad
参考:“Streamer学习笔记(一)”

http://www.cnblogs.com/phinecos/archive/2009/06/07/1498166.html中的代码,无
法播放mp3.
作了些修改,加了个convert就可以了:

view plaincopy to clipboardprint?
  1. #include <gst/gst.h>  
  2. #include <gtk/gtk.h>  
  3.   
  4. #define GTK_WINDOW 0  
  5.   
  6. static GtkWidget *window;  
  7.   
  8. static gboolean  
  9. delete_event(GtkWidget *widget,  
  10.               GdkEvent *event,  
  11.               gpointer data)  
  12. {  
  13.     return FALSE;  
  14. }  
  15.   
  16. static void  
  17. destroy(GtkWidget *widget,  
  18.          gpointer data)  
  19. {  
  20.     gtk_main_quit ();  
  21. }  
  22.   
  23. static void  
  24. window_create(void)  
  25. {  
  26.     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);  
  27.     g_signal_connect (G_OBJECT (window), "delete_event",  
  28.                       G_CALLBACK (delete_event), NULL);  
  29.     g_signal_connect (G_OBJECT (window), "destroy",  
  30.                       G_CALLBACK (destroy), NULL);    
  31.   
  32.     gtk_widget_show (window);  
  33. }  
  34.   
  35. int   
  36. main(int argc, char *argv[])  
  37. {      
  38.     GstElement *pipeline, *filesrc, *decoder, *convert, *audiosink;  
  39.   
  40. #if GTK_WINDOW  
  41.     gtk_init(&argc, &argv);  
  42.     window_create();      
  43. #endif  
  44.     gst_init(&argc, &argv);      
  45.    
  46.     if (argc != 2) {  
  47.         g_print("usage: %s <mp3 filename>/n", argv[0]);  
  48.         exit (-1);  
  49.     }  
  50.     
  51.     pipeline = gst_pipeline_new("pipeline");     
  52.       
  53.     filesrc = gst_element_factory_make("filesrc""disk_source");     
  54.     decoder = gst_element_factory_make("mad""decoder");  
  55.     convert = gst_element_factory_make("audioconvert""a-convert");  
  56.     audiosink = gst_element_factory_make("osssink""play_audio");  
  57.   
  58.     g_object_set(G_OBJECT(filesrc), "location", argv[1], NULL);  
  59.      
  60.     gst_bin_add_many(GST_BIN(pipeline), filesrc, decoder, convert, audiosink, NULL);      
  61.     gst_element_link_many(filesrc, decoder, convert, audiosink, NULL);  
  62.       
  63.     gst_element_set_state(pipeline, GST_STATE_PLAYING);  
  64.       
  65. #if GTK_WINDOW  
  66.     gtk_main ();  
  67. #else  
  68.     while (gst_bin_iterate_recurse(GST_BIN(pipeline)));  
  69. #endif  
  70.       
  71.     gst_element_set_state(pipeline, GST_STATE_NULL);      
  72.     gst_object_unref(GST_OBJECT (pipeline));  
  73.     exit (0);  
  74.     }  

//////////////////////////
在windows下安装gstreamer:
1. 之前参考“gtk的windows环境”

http://young001.blogbus.com/logs/43176719.html
已经建立了用minGW在windows下的gtk开发环境。

2.参考:
a. ”在Windows平台上建立GStreamer开发环境“
http://hi.baidu.com/tinyfun/blog/item/a7167f12cb060a0a5baf5339.html

b. http://www.qihoo.com/q/misc/6565790.html?f=1
Procssing对于视频的支持一向很烂,起码在PC下搭配QuickTime不是什么特别好的选择(这
点和Mac不一样)。如果平时你用它做一些视频的捕获或者是非常大的视频加载,通常不会
让你满意,而且画面很不流畅。以往的解决方法是通过Opengl的texture来渲染。
现在好了,先是有人写好了Gstreamer java的binding,
http://code.google.com/p/gstreamer-java/
Gstreamer也是一个pipeline的工作流程,具体的请参考
http://www.cin.ufpe.br/~cinlug/wiki/index.php/Introducing_GStreamer
然后pr论坛的dres Colubri又写出来了给processing用的Gstreamer
Library,所有的问题都过去了,现在通过使用Gstreamer,在Pr里面直接调用HD的视频都没
有问题。
安装的过程比较复杂,目前只能在PC下使用
1.先下载安装gtk+2runtime 没有这个是安装不了Gstreamer的
地址
http://sourceforge.net/project/downloading.php?groupname=gimp-win&filename=gtk+-
2.10.13-setup.exe&use_mirror=internap
2.去这里下载所有的文件 http://gstreamer.freedesktop.org/pkg/windows/releases/
注意只需要下载windows下安装程序就可以,否则的话你还需要自己编译
3.先安装gtk
4.在安装Gstreamer
5.按顺序安装所有的插件
gst-plugins-base-0.10.13
gst-plugins-good-0.10.6
gst-plugins-bad-0.10.5
gst-plugins-ugly-0.10.6
gst-ffmpeg-0.10.2
6.把Gstreamer Library copy到你的processing的library里面 地址
http://codeanticode.wordpress.com/category/gstreamer/
7.重新启动机器,因为安装Gstreamer的时候会添加系统环境变量
8.Bingo! 现在可以使用了
我机器上的测试 avi,mpeg,divx,quicktime都没问题,我最大加载的是1GB的影片,dres
Colubri测试加载的影片更大是1920x 1280的HD mov

原创粉丝点击