[vlc-qt] Get wrong frame buffer
Posted: 29 Sep 2021 11:06
Hi, I referred vlc-qt https://github.com/vlc-qt & vlc-qt examples simple-player https://github.com/vlc-qt/examples/tree ... ple-player with VLC 3.0.16 https://get.videolan.org/vlc/3.0.16/win64/ to create a small player. Finally, It can play video on VlcWidgetVideo!
mainwindow.cpp:
Now, I want to get the frame buffer to do something. I referred some articles. I created a sub-class which inherits from VlcVideoStream class & implemented frameUpdated():
FrameProcessor.h:
FrameProcessor.cpp:
mainwindow.cpp:
I expected I could receive some frame data in VlcFrameProcessor::frameUpdated(). INDEED, it can! It can receive width, height & frameBuffer.
However, it causes the screen became ALL GREEN and all content of frameBuffer are always 20 as the picture below...
https://imgur.com/a/iUOZqEJ
By the way, it don't affect the audio, which still can play well.
Any help will be highly appreciated!
PS. I'm not sure if I can post the QT-VLC issue here. If it can't, please notify me. Thanks!
mainwindow.cpp:
Code: Select all
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
VlcCommon::setPluginPath(qApp->applicationDirPath() + "/plugins");
VlcInstance *instance = new VlcInstance(VlcCommon::args(), NULL);
VlcMediaPlayer *player = new VlcMediaPlayer(instance);
//Show on QT GUI
player->setVideoWidget(ui->video);
ui->video->setMediaPlayer(player);
VlcMedia *media = new VlcMedia("/debug/sample-mp4-file.mp4", true, instance);
player->open(media);
}
FrameProcessor.h:
Code: Select all
#include <QtCore/QDebug>
#include "src/core/VideoStream.h"
class VlcFrameProcessor : public VlcVideoStream
{
public:
VlcFrameProcessor(QObject *parent);
virtual void frameUpdated();
};
Code: Select all
#include "FrameProcessor.h"
VlcFrameProcessor::VlcFrameProcessor(QObject *parent) : VlcVideoStream(Vlc::YUVFormat, parent){ }
void VlcFrameProcessor::frameUpdated() {
qDebug() << "frame update.";
QByteArray byteArray = this->renderFrame()->frameBuffer;
quint16 width, height;
memcpy(&width, &(this->renderFrame()->width), sizeof (quint16));
memcpy(&height, &(this->renderFrame()->height), sizeof (quint16));
qDebug() << "frame w:" << width << " h:" << height;
}
Code: Select all
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
VlcCommon::setPluginPath(qApp->applicationDirPath() + "/plugins");
VlcInstance *instance = new VlcInstance(VlcCommon::args(), NULL);
VlcMediaPlayer *player = new VlcMediaPlayer(instance);
//Show on QT GUI
player->setVideoWidget(ui->video);
ui->video->setMediaPlayer(player);
//I only add 2 lines!
VlcFrameProcessor *mProcessor = new VlcFrameProcessor(NULL);
mProcessor->init(player);
VlcMedia *media = new VlcMedia("/debug/sample-mp4-file.mp4", true, instance);
player->open(media);
}
However, it causes the screen became ALL GREEN and all content of frameBuffer are always 20 as the picture below...
https://imgur.com/a/iUOZqEJ
By the way, it don't affect the audio, which still can play well.
Any help will be highly appreciated!
PS. I'm not sure if I can post the QT-VLC issue here. If it can't, please notify me. Thanks!