PDA

View Full Version : LibVLC into an opengl QGraphicsScene



bunjee
20th January 2012, 13:33
Greetings QtCenters,

I'm currently trying to render a VLC video inside a QGraphicsScene.

I'm using the following code:

//------------------------------------------------------------------------------------------
// VLC callbacks
//------------------------------------------------------------------------------------------

/* static */ void * Player::lock(void * data, void ** buffer)
{
Player * player = static_cast<Player *> (data);

*buffer = player->_image.bits();

return NULL;
}

/* static */ void Player::unlock(void * data, void *, void * const *)
{
Player * player = static_cast<Player *> (data);

QCoreApplication::postEvent(player, new QEvent(QEvent::User));
}

//------------------------------------------------------------------------------------------

bool Player::event(QEvent * event)
{
if (event->type() == QEvent::User)
{
update();

return true;
}
else return QObject::event(event);
}

void Player::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
painter->setRenderHint(QPainter::SmoothPixmapTransform, true);

painter->setBrush(Qt::black);

painter->drawRect(option->rect);

painter->drawImage(0, 0, _image);

// The next call is very slow, even using an Opengl viewport
painter->drawImage(_targetRect, _image, QRectF(0, 0, _image.width(), _image.height()));
}

I'm testing with a 1080p video. For some reason the drawImage call seems to slow things down. This is not a surprise in software, but it's also pretty slow in Opengl.

My question is, assuming I want to use Opengl, is there a faster way to render a video frame into a QGraphicsScene using Qt 4.8 ?

Thanks.