基于QT视频软件的开发和学习_第1页
基于QT视频软件的开发和学习_第2页
基于QT视频软件的开发和学习_第3页
基于QT视频软件的开发和学习_第4页
基于QT视频软件的开发和学习_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、基于QT视频软件的开发和学习 马上工作需要做视频软件了,所以准备学习QT来开发,为什么选择QT呢,因为他优点多多(不说了自己网上g一下) 随着高清的不断普及,所有视频软件都向高清这个方向而前进,其中有一款开源跨平台的播放器vlc的特性和功能都是非常的好,所以想准备学习vlc的源码来看看,在看他源码的时候,发现他还有一个可供开发人员调用的libvlc 媒体库可用(GPL),而vlc本身使用的GUI就是QT。 好了不多说了 先装好QT SDK,然后把环境变量设置一下(不会去G!) 然后把vlc库加入到mingw里面 先复制vlc-include.rar解压出来的头文件到Qt2009.04mingw

2、include里面 在把vlc-lib.rar解压出来的文件放到C:vlc-lib 我们在 Qt Creator 里面建立一个空的QT项目 新建一个Player类 ,会多出player.cpp,player.h 修改成如下player.cppCpp代码 /* * Flie Name player.cpp */ #include player.h #include <QVBoxLayout> #include <QPushButton> #include <QSlider> #include <QTimer> #include <QFrame

3、> Player:Player() : QWidget() /preparation of the vlc command const char * const vlc_args = -I, dummy, /* Dont use any interface */ -ignore-config, /* Dont use VLCs config */ -extraintf=logger, /log anything -verbose=2, /be much more verbose then normal for debugging purpose -plugin-path=C:vlc-0.

4、9.9-win32plugins ; _videoWidget=new QFrame(this); _volumeSlider=new QSlider(Qt:Horizontal,this); _volumeSlider->setMaximum(100); /the volume is between 0 and 100 _volumeSlider->setToolTip(Audio slider); / Note: if you use streaming, there is no ability to use the position slider _positionSlide

5、r=new QSlider(Qt:Horizontal,this); _positionSlider->setMaximum(POSITION_RESOLUTION); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(_videoWidget); layout->addWidget(_positionSlider); layout->addWidget(_volumeSlider); setLayout(layout); _isPlaying=false; poller=new QTimer(this);

6、 /Initialize an instance of vlc /a structure for the exception is neede for this initalization libvlc_exception_init(&_vlcexcep); /create a new libvlc instance _vlcinstance=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args0), vlc_args,&_vlcexcep); /tricky calculation of the char space used raise

7、 (&_vlcexcep); / Create a media player playing environement _mp = libvlc_media_player_new (_vlcinstance, &_vlcexcep); raise (&_vlcexcep); /connect the two sliders to the corresponding slots (uses Qts signal / slots technology) connect(poller, SIGNAL(timeout(), this, SLOT(updateInterface(

8、); connect(_positionSlider, SIGNAL(sliderMoved(int), this, SLOT(changePosition(int); connect(_volumeSlider, SIGNAL(sliderMoved(int), this, SLOT(changeVolume(int); poller->start(100); /start timer to trigger every 100 ms the updateInterface slot /desctructor Player:Player() /* Stop playing */ libv

9、lc_media_player_stop (_mp, &_vlcexcep); /* Free the media_player */ libvlc_media_player_release (_mp); libvlc_release (_vlcinstance); raise (&_vlcexcep); void Player:playFile(QString file) /the file has to be in one of the following formats /perhaps a little bit outdated) /* file:/filename P

10、lain media file http:/ip:port/file HTTP URL ftp:/ip:port/file FTP URL mms:/ip:port/file MMS URL screen:/ Screen capture dvd:/deviceraw_device DVD device vcd:/device VCD device cdda:/device Audio CD device udp:<source address><bind address>:<bind port> */ /* Create a new LibVLC medi

11、a descriptor */ _m = libvlc_media_new (_vlcinstance, file.toAscii(), &_vlcexcep); raise(&_vlcexcep); libvlc_media_player_set_media (_mp, _m, &_vlcexcep); raise(&_vlcexcep); / /! Please note /! / / passing the widget to the lib shows vlc at which position it should show up / vlc autom

12、atically resizes the video to the given size of the widget / and it even resizes it, if the size changes at the playing /* Get our media instance to use our window */ #if defined(Q_OS_WIN) libvlc_media_player_set_drawable(_mp, reinterpret_cast<unsigned int>(_videoWidget->winId(), &_vlce

13、xcep ); /libvlc_media_player_set_hwnd(_mp, _videoWidget->winId(), &_vlcexcep ); / for vlc 1.0 #elif defined(Q_OS_MAC) libvlc_media_player_set_drawable(_mp, _videoWidget->winId(), &_vlcexcep ); /libvlc_media_player_set_agl (_mp, _videoWidget->winId(), &_vlcexcep); / for vlc 1.0 #

14、else /Linux libvlc_media_player_set_drawable(_mp, _videoWidget->winId(), &_vlcexcep ); /libvlc_media_player_set_xwindow(_mp, _videoWidget->winId(), &_vlcexcep ); / for vlc 1.0 #endif raise(&_vlcexcep); /* Play */ libvlc_media_player_play (_mp, &_vlcexcep ); raise(&_vlcexcep

15、); _isPlaying=true; void Player:changeVolume(int newVolume) libvlc_exception_clear(&_vlcexcep); libvlc_audio_set_volume (_vlcinstance,newVolume , &_vlcexcep); raise(&_vlcexcep); void Player:changePosition(int newPosition) libvlc_exception_clear(&_vlcexcep); / Its possible that the vl

16、c doesnt play anything / so check before libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp, &_vlcexcep); libvlc_exception_clear(&_vlcexcep); if (curMedia = NULL) return; float pos=(float)(newPosition)/(float)POSITION_RESOLUTION; libvlc_media_player_set_position (_mp, pos, &_v

17、lcexcep); raise(&_vlcexcep); void Player:updateInterface() if(!_isPlaying) return; / Its possible that the vlc doesnt play anything / so check before libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp, &_vlcexcep); libvlc_exception_clear(&_vlcexcep); if (curMedia = NULL) retur

18、n; float pos=libvlc_media_player_get_position (_mp, &_vlcexcep); int siderPos=(int)(pos*(float)(POSITION_RESOLUTION); _positionSlider->setValue(siderPos); int volume=libvlc_audio_get_volume (_vlcinstance,&_vlcexcep); _volumeSlider->setValue(volume); void Player:raise(libvlc_exception_t

19、 * ex) if (libvlc_exception_raised (ex) fprintf (stderr, error: %sn, libvlc_exception_get_message(ex); exit (-1); player.hCpp代码 /* libVLC and Qt sample code * Copyright ? 2009 Alexander Maringer <maringermaringer-it.de> */ #ifndef VLC_ON_QT_H #define VLC_ON_QT_H #include <vlc/vlc.h> #inc

20、lude <QWidget> class QVBoxLayout; class QPushButton; class QTimer; class QFrame; class QSlider; #define POSITION_RESOLUTION 10000 class Player : public QWidget Q_OBJECT QSlider *_positionSlider; QSlider *_volumeSlider; QFrame *_videoWidget; QTimer *poller; bool _isPlaying; libvlc_exception_t _vlcexcep; libvlc_instance_t *_vlcinstance; libvlc_media_player_t *_mp; libvlc_media_t *_m; public: Player(); Player(); void raise(libvlc_exception_t * ex); publi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论