gstreamer的安装和简单的mp3编写
为了使贪吃蛇在吃到食物时,能够发出声音。网上到gstreamer可以在windows下使用,相
当于windows下的directshow。
Gstreamer简单介绍:
GStreamer 作为 GNOME
桌面环境推荐的流媒体应用框架,采用了基于插件(plugin)和管道(pipeline)的体系结
构,框架中的所有的功能模块都被实现成可以插拔的组件(component),
并且在需要的时候能够很方便地安装到任意一个管道上,由于所有插件都通过管道机制进行
统一的数据,因此很容易利用已有的各种插件“组装”出一个功能完善的多媒体应用程序。
这篇文章“用 GStreamer 简化 Linux 多媒体开发”对GStreamer的概念介绍的挺好的.
www.ibm/developerworks/cn/linux/l-gstreamer/
在linux安装gstreamer:
1.去/下载源码包
一般要安装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,去launchpad/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正确。
“f 文件与PKG_CONFIG_PATH变量”
hi.baidu/litaosmile/blog/item/751be4f45bbb4ee67609d7be.html
”安装gstreamer到ARMv6平台“的可以参考:
hi.baidu/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学习笔记(一)”
wwwblogs/phinecos/archive/2009/06/07/1498166.html中的代码,无
法播放mp3.
作了些修改,加了个convert就可以了:
view plaincopy to clipboardprint?
#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 ();
wordpress安装首页}
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);
}
#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);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论