Page 1 of 1
[solved] libVLC QT Framework, sometimes video has only sound
Posted: 02 Dec 2009 15:18
by chris_g
Hi,
we have built a QT-Framework which plays videos with libvlc and our own custom controlls.
Sometimes instead of the video a white or yellow rectangle is shown. The sound is always there.
The Backgroundcolor of the QWidget is black.
Setup: Windows Vista, VLC 1.0.3 built from source, QT 4.5.3 built from source.
It seems to work fine on a XP System.
Regards
Chris
Re: libVLC, QT Framework, sometimes video has only sound
Posted: 03 Dec 2009 12:01
by Jean-Baptiste Kempf
How do you set the video to play on the QWidget?
Re: libVLC, QT Framework, sometimes video has only sound
Posted: 03 Dec 2009 12:24
by chris_g
Here some snippets of the code.
VLCPlayer Constructor:
Code: Select all
VLCPlayer::VLCPlayer(QWidget *parent,
QRect *_vidRect,
bool _fullscreen,
int _controllerHeight,
int _movieWidth, int
_movieHeight, int
_trackNumber, bool
prevBtn, bool
nextBtn, float
appVol, float
appSavedVol,
bool mute)
: QWidget(parent)
{
...
//preparation of the vlc command
const char * const vlc_args[] = {
"-I", "dummy", /* Don't use any interface */
"--ignore-config", /* Don't use VLC's config */
//"--extraintf=logger", //log anything
//"--verbose=2", //be much more verbose then normal for debugging purpose
"--no-video-title-show",
audioTrack,
"--no-plugins-cache",
#if defined(Q_OS_WIN)
"--plugin-path=.\\plugins"
#elif defined(Q_OS_MAC)
"--plugin-path=./plugins"
#elif // Linux
"--plugin-path=./plugins"
#endif
};
QDesktopWidget *desktop = QApplication::desktop();
QRect screenRect = desktop->screenGeometry(desktop->primaryScreen());
this->screenWidth = screenRect.width();
this->screenHeight = screenRect.height();
this->movieWidth = _movieWidth;
this->movieHeight = _movieHeight;
this->fullScreen = _fullscreen;
this->vidRect = *_vidRect;
this->controllerHeight = _controllerHeight;
this->screenRatio = screenWidth/screenHeight;
_m = NULL; // libvlc_media_player_t *_mp;
_mp = NULL; // libvlc_media_t *_m;
this->_videoWidget=new QFrame(this);
layout = new QVBoxLayout;
layout->addWidget(_videoWidget);
layout->setMargin(0);
layout->setSpacing(0);
setLayout(layout);
...
//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_args[0]), vlc_args,&_vlcexcep); //tricky calculation of the char space used
vlcraise (&_vlcexcep);
// Create a media player playing environement
_mp = libvlc_media_player_new(_vlcinstance, &_vlcexcep);
vlcraise(&_vlcexcep);
// Calculate the rectangle for the video
playerRect = this->calcPlayerRect(*_vidRect, (double)16/(double)9 );
this->setGeometry(playerRect.x(), playerRect.y(), playerRect.width(), playerRect.height());
/* Attach event to the media player */
libvlc_event_manager_t* em_mp;
em_mp = libvlc_media_player_event_manager (_mp, &_vlcexcep);
vlcraise (&_vlcexcep);
libvlc_event_attach (em_mp, libvlc_MediaPlayerEndReached, callbacks, this, &_vlcexcep);
vlcraise (&_vlcexcep);
...
}
VLCPlayer playFile:
Code: Select all
VLCPlayer::playFile(QString file)
{
QCursor myCrsr(Qt::WaitCursor);
_videoPath = file;
if (_m) {
libvlc_media_release(_m);
}
/* Create a new LibVLC media descriptor */
_m = libvlc_media_new(_vlcinstance, file.toAscii(), &_vlcexcep);
vlcraise(&_vlcexcep);
libvlc_media_player_set_media (_mp, _m, &_vlcexcep);
vlcraise(&_vlcexcep);
// /!\ Please note /!\
//
// passing the widget to the lib shows vlc at which position it should show up
// vlc automatically 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()), &_vlcexcep );
//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
#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
vlcraise(&_vlcexcep);
myCrsr.setShape(Qt::ArrowCursor);
...
this->play();
...
}
playFile() is called from the parentWidget. I tried to call it with a delay, but this did not help.
As I said before it works fine on XP and about 7 of 10 Times on Vista.
Regards
Chris
Re: libVLC, QT Framework, sometimes video has only sound
Posted: 03 Dec 2009 14:08
by Jean-Baptiste Kempf
Does the reinterpret_cast fail sometime?
Re: libVLC, QT Framework, sometimes video has only sound
Posted: 03 Dec 2009 14:47
by chris_g
I just gave it a try, but the reinterpret_cast shows a valid uint , although the VideoRect is white or yellow.
Using libvlc_media_player_set_hwnd(_mp, _videoWidget->winId(), &_vlcexcep ) results in the same error.
Re: libVLC, QT Framework, sometimes video has only sound
Posted: 09 Dec 2009 00:21
by chris_g
Found no solution yet. Installed QT 4.6 but this does not solve the problem.
Re: libVLC, QT Framework, sometimes video has only sound
Posted: 09 Dec 2009 23:56
by chris_g
Ok it´s solved. We used VLC 1.0.2. After building a new libvlc.lib from 1.0.3, replace dlls and plugins it works on Vista as well.
Re: [solved] libVLC QT Framework, sometimes video has only sound
Posted: 11 Dec 2009 08:59
by Jean-Baptiste Kempf
1.0.3 works but not 1.0.2 ?
libVLC QT Framework, sometimes video has only sound
Posted: 11 Dec 2009 14:31
by chris_g
Yes. Without any changes in the code.
EDIT 1:
But I just have seen that it still appaers sometimes, but not that often anymore. Not good.
EDIT 2:
Ok it works and I think I could isolate the Error. I must have been one of the plugins. On my PC everything worked fine with 1.0.3 but from the Server I still got this error. I detected that I still used the old plugin versions (1.0.2) at the server. When I changed them to the new ones (1.0.3) it works from server as well.
The plugins we use are:
libmp4_plugin.dll --> We play HD-mp4
libaccess_file_plugin.dll
libavcodec_plugin.dll
libdirac_plugin.dll
libdrawable_plugin.dll
libfaad_plugin.dll
libfloat32_mixer_plugin.dll
libugly_resampler_plugin.dll
libvout_directx_plugin.dll
libwaveout_plugin.dll
That´s all we have in the pluginsfolder. We replaced all the others.