CopperSpice API  1.9.1
Video Overview

CsMultimedia offers both high and low level C++ classes for playing and manipulating video data. Some of these classes also overlap with both camera and audio classes, which can be useful.

Playing Video

You can use the QMediaPlayer class to decode a video file, and display it using QVideoWidget, QGraphicsVideoItem, or a custom class.

The following is an example of how to use QVideoWidget.

player = new QMediaPlayer;
playlist = new QMediaPlaylist(player);
playlist->addMedia(QUrl("http://example.com/myclip1.mp4"));
playlist->addMedia(QUrl("http://example.com/myclip2.mp4"));
videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
playlist->setCurrentIndex(1);
player->play();

The following is an example of how to use QGraphicsVideoItem.

player = new QMediaPlayer(this);
player->setVideoOutput(item);
graphicsView->scene()->addItem(item);
graphicsView->show();
player->setMedia(QUrl("http://example.com/myclip4.ogv"));
player->play();

Working with Low Level Video Frames

CsMultimedia offers a number of low level classes to make handling video frames a bit easier. These classes are primarily used when writing code that processes video or camera frames. For example, detecting barcodes, or applying a fancy vignette effect, or displaying video in a special way that is otherwise unsupported.

The QVideoFrame class encapsulates a video frame and allows the contents to be mapped into system memory for manipulation or processing, while deriving a class from QAbstractVideoSurface allows you to receive these frames from QMediaPlayer and QCamera.

In order to use myVideoSurface, create an instance of this class and then pass the object to QMediaPlayer::setVideoOutput().

class MyVideoSurface : public QAbstractVideoSurface
{
QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const
{
// Return the formats you will support
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB565;
}
bool present(const QVideoFrame &frame) {
// Handle the frame and do your processing
return true;
}
};