打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
How to use LibVLC with Qt 5

I'm trying to use LibVLC in a Qt 5 program to open a VLC instance and play a video. The following code comes from https://wiki.videolan.org/LibVLC_Tutorial/I'm using Linux.

.pro :

TEMPLATE = appTARGET = projectLoicINCLUDEPATH += . vlcQT += widgets# InputHEADERS += SOURCES += main.cppLIBS +=-lvlc

main :

#include <vlc/vlc.h>#include <QApplication>int main(int argc, char* argv[]){    QApplication app(argc, argv);    libvlc_instance_t * inst;    libvlc_media_player_t *mp;    libvlc_media_t *m;         // Load the VLC engine         inst = libvlc_new(0, NULL);         // Create a new item         m = libvlc_media_new_path (inst, "/home/........mp3");         // Create a media player playing environement         mp = libvlc_media_player_new_from_media (m);         // play the media_player         libvlc_media_player_play (mp);     return app.exec();}

The compilation is fine. But the program immediatly crashes when I build it (with Qt Creator). Any idea?

Many thanks



Many things could cause this crash. The best is to get VLC source code to trace back the issue. Passing the option '--verbose=2' when initializing libVLC can help as well.

In my case the cause of the crash was due to this bug in the ubuntu package of vlc:https://bugs.launchpad.net/ubuntu/+source/vlc/+bug/1328466

When calling libvlc_new() vlc modules and their dependent libraries are loaded into memory. The qt module of LibVLC was searching for Qt4 shared objects instead of Qt5 (manually installed).

The solution was to rebuild the module cache which was outdated an pointing to Qt4 binaries. You can reset it on the command line:

sudo /usr/lib/vlc/vlc-cache-gen -f /usr/lib/vlc/plugins/

Or pass to vlc the option:

--reset-plugins-cache
shareimprove this answer

    
that didn't helped me. I still have usr/lib/libvlc-qt-widgets.so.0.9 depending on QT4, not on QT5 –  Temak Mar 5 at 11:15
    
sometimes sudo ldconfig -v helps. If you reinstalled some libs it will make correct linkk to them –  Temak Mar 5 at 12:57

I have never used this library, but Are you using exactly this code?

 m = libvlc_media_new_path (inst, "/home/........mp3");

This path may be the problem.

shareimprove this answer

    
i'm not using exactly this code, my path is fine ;) –  damien Jul 31 '14 at 20:42
    
Ok, I get to compile the code and run it without problem. This is what I used to install the library: sudo apt-get install libvlc5 libvlc-dev libvlccore-dev I don't have enough information to say what can be wrong. But, it works for me. –  Jose Monsalve Diaz Jul 31 '14 at 20:48
    
ok I have installed the library you suggested, but there is no improvment. This is what I get : Starting /home/domi/build-projectLoic-Desktop-Debug/projectLoic... The program has unexpectedly finished. /home/domi/build-projectLoic-Desktop-Debug/projectLoic crashed –  damien Aug 1 '14 at 19:30
    
I need to know in which line the code crash. QtCreator in debug mode should give you the last line the program executed and the stack with the function calls. Sometimes, previous versions of the libraries are installed and generate this kind of conflicts. I suggest trying to uninstall both libraries (Qt and libVLC). Make sure that you don′t have them in the libraries folders. I think is /usr/lib. Then, re-install both from scratch. (I had the same problem with libosg once, and I solved it this way). –  Jose Monsalve Diaz Aug 3 '14 at 0:45
    
Thanks a lot for helping me. In debug mode I get : The inferior stopped because it received a signal from the Operating System. Signal name : SIGSEGV Signal meaning : Segmentation fault –  damien Aug 6 '14 at 20:34

What distribution of Linux are you using?

I ran into this same problem with Qt5 and LibVLC, and the primary cause (Ubuntu 12.04 LTS and 14.04 LTS), was that LibVLC was loading the qt4 interface plugin, which conflicted with Qt5. If you check your call stack, you'll most likely see that at a Qt4 library was being loaded, causing the crash.

If this is the problem, there are only 3 options (tested with LibVLC 2.2 and Qt5 on Ubuntu 12.04 and 14.04 LTS 64 bit).

The first (worst) is to delete the qt4 user interface plugin. You can test this is the problem by moving and running and then setting it back. Deleting will break your regular VLC player most likely.

Second option is to create a copy of the plugins directory and set that in your runtime path using VLC_PLUGIN_PATH, environment variable. but I've had trouble getting that to work without changing the original plugin path folder also (which will break your VLC player unless you modify your shortcuts, etc. to also set VLC_PLUGIN_PATH.

The third option, and what I ended up doing, was to custom build my own static LibVLC binary with a few edits to the source code so that it will not load the qt4 interface plugin installed with VLC. You can follow these steps to do this.

1)  Download VLC Source Code for your platforms distribution.    http://download.videolan.org/pub/videolan/vlc/    Make sure you download the version matching your distribution. For    example, match the VLC version to what is installed with Ubuntu.2)  Extract source code to folder3)  Install dependencies for the OS distribution    sudo apt-get build-dep vlc4)  Modify src/modules/bank.c    Edit the module_InitDynamic function    Add the following code at the top of the function:    // HACK TO DISABLE QT4 PLUGIN    if(strstr(path, "qt4") != NULL)        return NULL;    // END HACK3)  From terminal    ./bootstrap    ./configure --disable-qt --disable-skins2 --enable-xcb --prefix=/home/$USER/vlc-custom_build_output_folder_name    ./make    ./make install4)  Copy/Save the resulting files in the install folder.

Then just link against this library instead.

shareimprove this answer
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Compiling cufflinks 0.9.x [Archive]
Building Qt with OpenGL ES accelerated by SGX
mupdf
LibVLC SampleCode Qt
基于QT视频软件的开发和学习
VLC动态库介绍(续一)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服