資源簡介
基于QT5.7和C++的視頻播放器源碼,可實現視頻播放和音樂播放

代碼片段和文件信息
#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();
??????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-01-05?16:33??mediapla
?????文件????????3718??2018-01-05?15:40??mediapla
?????文件?????????931??2018-01-04?16:46??mediapla
?????文件????????3717??2018-01-04?16:05??mediapla
?????文件?????????165??2018-01-04?15:55??mediapla
?????文件????????1155??2018-01-04?16:53??mediapla
?????文件?????????643??2018-01-04?16:46??mediapla
?????文件???????23809??2018-01-05?16:17??mediapla
?????文件???????13621??2018-01-04?16:51??mediapla
?????文件????????2066??2018-01-04?16:16??mediapla
?????文件????????4552??2018-01-04?16:05??mediapla
?????文件????????1307??2018-01-04?16:16??mediapla
?????文件????????4552??2018-01-04?16:05??mediapla
?????文件?????????160??2018-01-04?15:57??mediapla
?????文件???????13619??2018-01-04?16:05??mediapla
?????文件?????????120??2018-01-04?15:56??mediapla
?????文件????????3403??2018-01-04?16:51??mediapla
?????文件????????1265??2018-01-04?16:16??mediapla
?????文件????????1052??2018-01-04?17:09??mediapla
?????文件?????????377??2018-01-04?16:19??mediapla
?????文件?????????114??2018-01-04?15:48??mediapla
?????文件?????????195??2018-01-04?15:48??mediapla
- 上一篇:C++課程設計之簡易英漢字典
- 下一篇:實驗室設備管理系統C++
評論
共有 條評論