mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Multiple tests w/ videoprobe (it's a mess)
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
CONFIG += c++11
|
||||
CONFIG += c++11 debug
|
||||
|
||||
# Always use major.minor.micro version number format
|
||||
VERSION = 0.5.1
|
||||
|
||||
@@ -57,7 +57,8 @@ const uchar* VideoImplQtMultiMedia::getBits()
|
||||
// _bitsChanged = false;
|
||||
|
||||
// Return data.
|
||||
return videoSurface->bits();
|
||||
return _img.bits();
|
||||
// return videoSurface->bits();
|
||||
// return (hasBits() ? videoSurface->bits() : NULL);
|
||||
}
|
||||
|
||||
@@ -131,9 +132,20 @@ _uri("")
|
||||
_mutexLocker = new QMutexLocker(&_mutex);
|
||||
|
||||
videoSurface = new VideoSurface(this);
|
||||
videoProbe = new QVideoProbe(this);
|
||||
videoProbe->setSource(&mediaPlayer);
|
||||
_freeze = false;
|
||||
|
||||
mediaPlayer.setVideoOutput(videoSurface);
|
||||
|
||||
_bitsChanged = true;
|
||||
connect(&mediaPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
|
||||
this, SLOT(mediaStatusChanged(QMediaPlayer::MediaStatus)));
|
||||
|
||||
connect(videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(processFrame(QVideoFrame)));
|
||||
//connect(videoSurface, SIGNAL(frameAvailable(QImage)),
|
||||
// this, SLOT(processImage(QImage)));
|
||||
|
||||
// connect(&mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)),
|
||||
// this, SLOT(mediaStateChanged(QMediaPlayer::State)));
|
||||
// connect(&mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
|
||||
@@ -180,6 +192,72 @@ void VideoImplQtMultiMedia::resetMovie()
|
||||
}
|
||||
}
|
||||
|
||||
void VideoImplQtMultiMedia::mediaStatusChanged(QMediaPlayer::MediaStatus status)
|
||||
{
|
||||
if (status == QMediaPlayer::EndOfMedia)
|
||||
{
|
||||
// loadMovie(_uri);
|
||||
// _freeze = true;
|
||||
// videoSurface->setFreeze(true);
|
||||
|
||||
// resetMovie();
|
||||
}
|
||||
else if (status == QMediaPlayer::BufferedMedia)
|
||||
{
|
||||
// _freeze = false;
|
||||
// setPlayState(_playState);
|
||||
// videoSurface->setFreeze(false);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoImplQtMultiMedia::processImage(QImage img)
|
||||
{
|
||||
_img = img;
|
||||
}
|
||||
|
||||
void VideoImplQtMultiMedia::processFrame(QVideoFrame frame)
|
||||
{
|
||||
if (!frame.isValid())
|
||||
return;
|
||||
|
||||
if (_freeze)
|
||||
return;
|
||||
|
||||
// Copy current frame.
|
||||
QVideoFrame currentFrame(frame);
|
||||
QImage img;
|
||||
|
||||
// Convert frame into QImage with appropriate format.
|
||||
// Source: https://stackoverflow.com/questions/27829830/convert-qvideoframe-to-qimage
|
||||
if (currentFrame.map(QAbstractVideoBuffer::ReadOnly))
|
||||
{
|
||||
QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(currentFrame.pixelFormat());
|
||||
if (imageFormat != QImage::Format_Invalid) {
|
||||
img = QImage(currentFrame.bits(), currentFrame.width(), currentFrame.height(), currentFrame.bytesPerLine(), imageFormat);
|
||||
} else {
|
||||
qWarning() << "Strange" << endl;
|
||||
// e.g. JPEG
|
||||
int nbytes = currentFrame.mappedBytes();
|
||||
img = QImage::fromData(currentFrame.bits(), nbytes);
|
||||
}
|
||||
|
||||
|
||||
// Convert to OpenGLformat and apply transforms to straighten.
|
||||
img = QGLWidget::convertToGLFormat(img)
|
||||
.mirrored(true, false)
|
||||
.transformed(QTransform().rotate(180));
|
||||
|
||||
// qWarning() << img.isNull() << " " << img.allGray() << " " << currentFrame.bits() << " " << currentFrame << endl;
|
||||
|
||||
if (!img.isNull())
|
||||
_img = img;
|
||||
|
||||
currentFrame.unmap();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VideoImplQtMultiMedia::update()
|
||||
{
|
||||
// // Check for end-of-stream or terminate.
|
||||
@@ -206,7 +284,9 @@ void VideoImplQtMultiMedia::update()
|
||||
|
||||
// Start playing.
|
||||
if (!filename.isEmpty()) {
|
||||
mediaPlayer.stop();
|
||||
mediaPlayer.setMedia(QUrl::fromLocalFile(filename));
|
||||
setPlayState(_playState);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include "VideoSurface.h"
|
||||
|
||||
#include <QMediaPlayer>
|
||||
#include <QVideoProbe>
|
||||
|
||||
#include <QtOpenGL>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
@@ -132,6 +134,11 @@ public:
|
||||
|
||||
void resetMovie();
|
||||
|
||||
public slots:
|
||||
void mediaStatusChanged(QMediaPlayer::MediaStatus status);
|
||||
void processImage(QImage img);
|
||||
void processFrame(QVideoFrame frame);
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
@@ -186,6 +193,11 @@ private:
|
||||
|
||||
QMediaPlayer mediaPlayer;
|
||||
|
||||
QImage _img;
|
||||
|
||||
QVideoProbe* videoProbe;
|
||||
bool _freeze;
|
||||
|
||||
VideoSurface* videoSurface;
|
||||
|
||||
};
|
||||
|
||||
@@ -46,7 +46,8 @@
|
||||
namespace mmp {
|
||||
|
||||
VideoSurface::VideoSurface(QObject *parent)
|
||||
: QAbstractVideoSurface(parent)
|
||||
: QAbstractVideoSurface(parent),
|
||||
_freeze(false)
|
||||
// , imageFormat(QImage::Format_Invalid)
|
||||
// , framePainted(false)
|
||||
{
|
||||
@@ -79,8 +80,16 @@ QList<QVideoFrame::PixelFormat> VideoSurface::supportedPixelFormats(
|
||||
|
||||
bool VideoSurface::present(const QVideoFrame &frame)
|
||||
{
|
||||
return true;
|
||||
if (!frame.isValid())
|
||||
return false;
|
||||
|
||||
if (_freeze)
|
||||
return true;
|
||||
|
||||
// Copy current frame.
|
||||
QVideoFrame currentFrame(frame);
|
||||
QImage _img;
|
||||
|
||||
// Convert frame into QImage with appropriate format.
|
||||
// Source: https://stackoverflow.com/questions/27829830/convert-qvideoframe-to-qimage
|
||||
@@ -88,29 +97,37 @@ bool VideoSurface::present(const QVideoFrame &frame)
|
||||
{
|
||||
QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(currentFrame.pixelFormat());
|
||||
if (imageFormat != QImage::Format_Invalid) {
|
||||
_img = QImage(currentFrame.bits(), currentFrame.width(), currentFrame.height(), imageFormat);
|
||||
_img = QImage(currentFrame.bits(), currentFrame.width(), currentFrame.height(), currentFrame.bytesPerLine(), imageFormat);
|
||||
} else {
|
||||
// e.g. JPEG
|
||||
int nbytes = currentFrame.mappedBytes();
|
||||
_img = QImage::fromData(currentFrame.bits(), nbytes);
|
||||
}
|
||||
|
||||
currentFrame.unmap();
|
||||
|
||||
// Convert to OpenGLformat and apply transforms to straighten.
|
||||
_img = QGLWidget::convertToGLFormat(_img)
|
||||
.mirrored(true, false)
|
||||
.transformed(QTransform().rotate(180));
|
||||
|
||||
emit frameAvailable(_img);
|
||||
currentFrame.unmap();
|
||||
|
||||
if (_img.allGray())
|
||||
{
|
||||
int x = 4;
|
||||
qDebug() << frame.endTime() << " " << frame.isValid() << endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
const uchar* VideoSurface::bits()
|
||||
{
|
||||
return _img.bits();
|
||||
}
|
||||
//const uchar* VideoSurface::bits()
|
||||
//{
|
||||
// return _img.bits();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
#include <QGraphicsItem>
|
||||
#include <QAudio>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
namespace mmp {
|
||||
|
||||
class VideoSurface
|
||||
@@ -65,9 +67,15 @@ public:
|
||||
|
||||
const uchar* bits();
|
||||
|
||||
void setFreeze(bool freeze) { _freeze = freeze; }
|
||||
|
||||
signals:
|
||||
void frameAvailable(QImage img);
|
||||
|
||||
private:
|
||||
// Each frame is saved internally in a QImage.
|
||||
QImage _img;
|
||||
// QImage _img;
|
||||
bool _freeze;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user