• 大小: 12.82MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-06-16
  • 语言: 其他
  • 标签: 视频播放  

资源简介

在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 < m_histogram.size(); 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 < frame.height(); y++) {
                uchar *lastPixel = b + frame.width();
                for (uchar *curPixel = b; curPixel < lastPixel; 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 < image.height(); y++) {
                    const QRgb *lastPixel = b + frame.width();
                    for (const QRgb *curPixel = b; curPixel < lastPixel; curPixel++)
                  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       9595  2017-11-02 14:55  videoPlayer\videoPlayer\GeneratedFiles\Debug\moc_histogramwidget.cpp

     文件       8250  2017-11-02 14:55  videoPlayer\videoPlayer\GeneratedFiles\Debug\moc_player.cpp

     文件      10240  2017-11-02 14:55  videoPlayer\videoPlayer\GeneratedFiles\Debug\moc_playercontrols.cpp

     文件       4687  2017-11-02 14:55  videoPlayer\videoPlayer\GeneratedFiles\Debug\moc_playlistmodel.cpp

     文件       2740  2017-11-02 14:55  videoPlayer\videoPlayer\GeneratedFiles\Debug\moc_videowidget.cpp

     文件       1390  2017-11-02 14:56  videoPlayer\videoPlayer\GeneratedFiles\qrc_player.cpp

     文件       9595  2017-11-02 14:56  videoPlayer\videoPlayer\GeneratedFiles\Release\moc_histogramwidget.cpp

     文件       8250  2017-11-02 14:56  videoPlayer\videoPlayer\GeneratedFiles\Release\moc_player.cpp

     文件      10240  2017-11-02 14:56  videoPlayer\videoPlayer\GeneratedFiles\Release\moc_playercontrols.cpp

     文件       4687  2017-11-02 14:56  videoPlayer\videoPlayer\GeneratedFiles\Release\moc_playlistmodel.cpp

     文件       2740  2017-11-02 14:56  videoPlayer\videoPlayer\GeneratedFiles\Release\moc_videowidget.cpp

     文件       3601  2017-11-02 14:50  videoPlayer\videoPlayer\histogramwidget.cpp

     文件        826  2017-11-02 14:50  videoPlayer\videoPlayer\histogramwidget.h

     文件       2263  2015-10-13 13:09  videoPlayer\videoPlayer\main.cpp

     文件        171  2017-11-02 13:35  videoPlayer\videoPlayer\main_.cpp

     文件      14825  2017-11-02 14:55  videoPlayer\videoPlayer\player.cpp

     文件       3810  2017-11-02 14:55  videoPlayer\videoPlayer\player.h

     文件         66  2017-11-02 13:35  videoPlayer\videoPlayer\player.qrc

     文件       6343  2015-10-13 13:09  videoPlayer\videoPlayer\playercontrols.cpp

     文件       3157  2015-10-13 13:09  videoPlayer\videoPlayer\playercontrols.h

     文件        131  2017-11-02 13:35  videoPlayer\videoPlayer\player_.cpp

     文件        254  2017-11-02 13:35  videoPlayer\videoPlayer\player_.h

     文件        584  2017-11-02 13:35  videoPlayer\videoPlayer\player_.ui

     文件       5241  2015-10-13 13:09  videoPlayer\videoPlayer\playlistmodel.cpp

     文件       3145  2015-10-13 13:09  videoPlayer\videoPlayer\playlistmodel.h

     文件      38123  2017-11-02 14:23  videoPlayer\videoPlayer\videoPlayer.vcxproj

     文件       4567  2017-11-02 14:23  videoPlayer\videoPlayer\videoPlayer.vcxproj.filters

     文件        691  2017-11-20 17:50  videoPlayer\videoPlayer\videoPlayer.vcxproj.user

     文件       2906  2015-10-13 13:09  videoPlayer\videoPlayer\videowidget.cpp

     文件       2308  2015-10-13 13:09  videoPlayer\videoPlayer\videowidget.h

............此处省略77个文件信息

评论

共有 条评论