如何使用LibVLC与Qt 5 [英] How to use LibVLC with Qt 5
问题描述
我试图在Qt 5程序中使用LibVLC打开一个VLC实例和播放视频。
以下代码来自 https://wiki.videolan.org/LibVLC_Tutorial/
我在使用Linux。
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 = app
TARGET = projectLoic
INCLUDEPATH += . vlc
QT += widgets
# Input
HEADERS +=
SOURCES += main.cpp
LIBS +=-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();
}
编译正常。但是程序立即崩溃,当我构建它(与Qt Creator)。任何想法?
The compilation is fine. But the program immediatly crashes when I build it (with Qt Creator). Any idea?
非常感谢
推荐答案
崩溃。最好是获得VLC源代码来追溯这个问题。在初始化libVLC时传递选项'--verbose = 2'也可以帮助。
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.
在我的情况下,崩溃的原因是由于这个bug的ubuntu包of vlc:
https://bugs.launchpad.net/ ubuntu / + source / vlc / + bug / 1328466
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
当调用libvlc_new()vlc模块及其依赖库加载到内存时。 LibVLC的qt模块正在搜索Qt4共享对象,而不是Qt5(手动安装)。
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).
解决方案是重建模块缓存,过时指向Qt4二进制。您可以在命令行中重置它:
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/
或传递给vlc选项:
--reset-plugins-cache
这篇关于如何使用LibVLC与Qt 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!