資源簡介
在VS項目中使用Qt示例程序實現視頻播放。
開發環境VS2013、Qt5.3.1、qt-adin。
代碼片段和文件信息
#include?“histogramwidget.h“
#include?
HistogramWidget::HistogramWidget(QWidget?*parent)
????:?QWidget(parent)
?????m_levels(128)
?????m_isBusy(false)
{
????m_processor.moveToThread(&m_processorThread);
????qRegistermetaType?>(“QVector“);
????connect(&m_processor?SIGNAL(histogramReady(QVector))?SLOT(setHistogram(QVector)));
????m_processorThread.start(QThread::LowestPriority);
}
HistogramWidget::~HistogramWidget()
{
????m_processorThread.quit();
????m_processorThread.wait(10000);
}
void?HistogramWidget::processframe(QVideoframe?frame)
{
????if?(m_isBusy)
????????return;?//drop?frame
????m_isBusy?=?true;
????Qmetaobject::invokeMethod(&m_processor?“processframe“
??????????????????????????????Qt::QueuedConnection?Q_ARG(QVideoframe?frame)?Q_ARG(int?m_levels));
}
void?HistogramWidget::setHistogram(QVector?histogram)
{
????m_isBusy?=?false;
????m_histogram?=?histogram;
????update();
}
void?HistogramWidget::paintEvent(QPaintEvent?*event)
{
????Q_UNUSED(event);
????QPainter?painter(this);
????if?(m_histogram.isEmpty())?{
????????painter.fillRect(0?0?width()?height()?QColor::fromRgb(0?0?0));
????????return;
????}
????qreal?barWidth?=?width()?/?(qreal)m_histogram.size();
????for?(int?i?=?0;?i?????????qreal?h?=?m_histogram[i]?*?height();
????????//?draw?level
????????painter.fillRect(barWidth?*?i?height()?-?h?barWidth?*?(i?+?1)?height()?Qt::red);
????????//?clear?the?rest?of?the?control
????????painter.fillRect(barWidth?*?i?0?barWidth?*?(i?+?1)?height()?-?h?Qt::black);
????}
}
void?frameProcessor::processframe(QVideoframe?frame?int?levels)
{
????QVector?histogram(levels);
????do?{
????????if?(!levels)
????????????break;
????????if?(!frame.map(QAbstractVideoBuffer::ReadOnly))
????????????break;
????????if?(frame.pixelFormat()?==?QVideoframe::Format_YUV420P?||
????????????frame.pixelFormat()?==?QVideoframe::Format_NV12)?{
????????????//?Process?YUV?data
????????????uchar?*b?=?frame.bits();
????????????for?(int?y?=?0;?y?ame.height();?y++)?{
????????????????uchar?*lastPixel?=?b?+?frame.width();
????????????????for?(uchar?*curPixel?=?b;?curPixel?????????????????????histogram[(*curPixel?*?levels)?>>?8]?+=?1.0;
????????????????b?+=?frame.bytesPerLine();
????????????}
????????}?else?{
????????????QImage::Format?imageFormat?=?QVideoframe::imageFormatFromPixelFormat(frame.pixelFormat());
????????????if?(imageFormat?!=?QImage::Format_Invalid)?{
????????????????//?Process?RGB?data
????????????????QImage?image(frame.bits()?frame.width()?frame.height()?imageFormat);
????????????????image?=?image.convertToFormat(QImage::Format_RGB32);
????????????????const?QRgb*?b?=?(const?QRgb*)image.bits();
????????????????for?(int?y?=?0;?y?????????????????????const?QRgb?*lastPixel?=?b?+?frame.width();
????????????????????for?(const?QRgb?*curPixel?=?b;?curPixel???????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????9595??2017-11-02?14:55??videoPla
?????文件???????8250??2017-11-02?14:55??videoPla
?????文件??????10240??2017-11-02?14:55??videoPla
?????文件???????4687??2017-11-02?14:55??videoPla
?????文件???????2740??2017-11-02?14:55??videoPla
?????文件???????1390??2017-11-02?14:56??videoPla
?????文件???????9595??2017-11-02?14:56??videoPla
?????文件???????8250??2017-11-02?14:56??videoPla
?????文件??????10240??2017-11-02?14:56??videoPla
?????文件???????4687??2017-11-02?14:56??videoPla
?????文件???????2740??2017-11-02?14:56??videoPla
?????文件???????3601??2017-11-02?14:50??videoPla
?????文件????????826??2017-11-02?14:50??videoPla
?????文件???????2263??2015-10-13?13:09??videoPla
?????文件????????171??2017-11-02?13:35??videoPla
?????文件??????14825??2017-11-02?14:55??videoPla
?????文件???????3810??2017-11-02?14:55??videoPla
?????文件?????????66??2017-11-02?13:35??videoPla
?????文件???????6343??2015-10-13?13:09??videoPla
?????文件???????3157??2015-10-13?13:09??videoPla
?????文件????????131??2017-11-02?13:35??videoPla
?????文件????????254??2017-11-02?13:35??videoPla
?????文件????????584??2017-11-02?13:35??videoPla
?????文件???????5241??2015-10-13?13:09??videoPla
?????文件???????3145??2015-10-13?13:09??videoPla
?????文件??????38123??2017-11-02?14:23??videoPla
?????文件???????4567??2017-11-02?14:23??videoPla
?????文件????????691??2017-11-20?17:50??videoPla
?????文件???????2906??2015-10-13?13:09??videoPla
?????文件???????2308??2015-10-13?13:09??videoPla
............此處省略77個文件信息
評論
共有 條評論