windows下gstreamer软件开发环境的搭建过程
在windows下使用Visual C++进行gstreamer软件框架的应用程序的编程
以播放msmpeg4编码的avi视频为例,过程如下:
1,安装GStreamerWinBuild-0.10.5.1.exe和GStreamerWinBuild-0.10.5-dev.exe,
按照默认安装设置进行安装,即安装在C:/gstreamer目录下。
软件下载地址:
http://www.gstreamer-winbuild.ylatuya.es/doku.php?id=start
2,打开Visual C++,创建工程。
文件->新建->Win32 Console Application->工程名称(填avi_player)->位置(填E:/SHARE/SVN/VC/gstreamer/avi_player)->确定->一个
支持MFC的程序->完成->确定
3,添加头文件目录和库文件目录
工具->选项->目录->Include files 添加路径
C:/GSTREAMER/INCLUDE/GSTREAMER-0.10
C:/GSTREAMER/INCLUDE/GLIB-2.0
C:/GSTREAMER/INCLUDE/LIBXML2
C:/GSTREAMER/INCLUDE
工具->选项->目录->Library files 添加路径
C:/GSTREAMER/LIB
4,添加具体连接的库名称
工程->设置->连接->工程选项 添加
gobject-2.0.lib
glib-2.0.lib
gstreamer-0.10.lib
确定
5,编写程序代码
avi_player.cpp
---------------------
#include "stdafx.h"
#include "avi_player.h"
#include <gst/gst.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int gargc;
char **gargv;
static GMainLoop *loop;
static void new_pad(GstElement *element,GstPad *pad,gpointer data){
GstElement *decoder=(GstElement *)data;
GstPad *sinkpad=gst_element_get_pad(decoder,"sink");
gst_pad_link(pad,sinkpad);
gst_object_unref(sinkpad);
}
GstElement * create_player(){
GstElement *player,*source,*demuxer,*decoder,*convert,*sink;
player=gst_pipeline_new("video-player");
source=gst_element_factory_make("filesrc","file-source");
demuxer=gst_element_factory_make("avidemux","avi-demuxer");
decoder=gst_element_factory_make("ffdec_msmpeg4","mpeg4-decoder");
convert=gst_element_factory_make("ffmpegcolorspace","color-convert");
sink=gst_element_factory_make("dshowvideosink","vid-sink");
if(!player||!source||!demuxer||!decoder||!convert ||!sink){
return NULL;
}
g_object_set(G_OBJECT(source),"location","sun.avi",NULL);
gst_bin_add_many(GST_BIN(player),source,demuxer,decoder,convert,sink,NULL);
gst_element_link(source,demuxer);
gst_element_link_many(decoder,convert,sink,NULL);
g_signal_connect(demuxer,"pad-added",G_CALLBACK(new_pad),decoder);
return player;
}
void play(GstElement *player){
gst_element_set_state(player,GST_STATE_PLAYING);
}
void delete_player(GstElement *player){
gst_element_set_state(player,GST_STATE_NULL);
gst_object_unref(GST_OBJECT(player));
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
GstElement *player;
gargc=argc;
gargv=argv;
gst_init(&argc,&argv);
if(argc!=1){
g_print("play_pipe_avi usage:/n"
"/t%s/n",
argv[0]);
return -1;
}
if((player=create_player())==NULL){
g_print("Cann't create player/n");
return -1;
}
play(player);
loop=g_main_loop_new(NULL,FALSE);
g_main_loop_run(loop);
delete_player(player);
g_main_loop_unref(loop);
return nRetCode;
}
---------------------
6,创建应用程序
Build(F7),在Debug目录下生成可执行程序avi_player.exe
7,使用应用程序avi_player.exe
将avi_player.exe拷贝到sun.avi视频所在目录,点击avi_player.exe,就可以正常播放了。