pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

在 Qt 中顯示解碼視頻幀的最有效方法是什么?

What is the most efficient way to display decoded video frames in Qt?(在 Qt 中顯示解碼視頻幀的最有效方法是什么?)
本文介紹了在 Qt 中顯示解碼視頻幀的最有效方法是什么?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

將圖像顯示到 Qt 小部件的最快方法是什么?我已經(jīng)使用 libavformat 和 libavcodec 解碼了視頻,所以我已經(jīng)有了原始 RGB 或 YCbCr 4:2:0 幀.我目前正在使用 QGraphicsView 和包含 QGraphicsPixmapItem 的 QGraphicsScene 對象.我目前正在通過使用內(nèi)存緩沖區(qū)中的 QImage 構(gòu)造函數(shù)將幀數(shù)據(jù)獲取到 QPixmap 中,并使用 QPixmap::fromImage() 將其轉(zhuǎn)換為 QPixmap.

What is the fastest way to display images to a Qt widget? I have decoded the video using libavformat and libavcodec, so I already have raw RGB or YCbCr 4:2:0 frames. I am currently using a QGraphicsView with a QGraphicsScene object containing a QGraphicsPixmapItem. I am currently getting the frame data into a QPixmap by using the QImage constructor from a memory buffer and converting it to QPixmap using QPixmap::fromImage().

我喜歡這樣的結(jié)果,而且看起來比較快,但我不禁想到一定有更有效的方法.我還聽說 QImage 到 QPixmap 的轉(zhuǎn)換很昂貴.我已經(jīng)實(shí)現(xiàn)了一個(gè)在小部件上使用 SDL 覆蓋的解決方案,但我想只使用 Qt,因?yàn)槲夷軌蚴褂?QGraphicsView 輕松捕獲點(diǎn)擊和其他用戶與視頻顯示的交互.

I like the results of this and it seems relatively fast, but I can't help but think that there must be a more efficient way. I've also heard that the QImage to QPixmap conversion is expensive. I have implemented a solution that uses an SDL overlay on a widget, but I'd like to stay with just Qt since I am able to easily capture clicks and other user interaction with the video display using the QGraphicsView.

我正在使用 libswscale 進(jìn)行任何所需的視頻縮放或色彩空間轉(zhuǎn)換,所以我只想知道是否有人有更有效的方法在執(zhí)行完所有處理后顯示圖像數(shù)據(jù).

I am doing any required video scaling or colorspace conversions with libswscale so I would just like to know if anyone has a more efficient way to display the image data after all processing has been performed.

謝謝.

推薦答案

感謝您的回答,但我終于重新審視了這個(gè)問題,并提出了一個(gè)相當(dāng)簡單的解決方案,可以提供良好的性能.它涉及從 QGLWidget 派生并覆蓋 paintEvent() 函數(shù).在paintEvent() 函數(shù)中,您可以調(diào)用QPainter::drawImage(...),它會使用硬件(如果可用)為您執(zhí)行縮放到指定的矩形.所以它看起來像這樣:

Thanks for the answers, but I finally revisited this problem and came up with a rather simple solution that gives good performance. It involves deriving from QGLWidget and overriding the paintEvent() function. Inside the paintEvent() function, you can call QPainter::drawImage(...) and it will perform the scaling to a specified rectangle for you using hardware if available. So it looks something like this:

class QGLCanvas : public QGLWidget
{
public:
    QGLCanvas(QWidget* parent = NULL);
    void setImage(const QImage& image);
protected:
    void paintEvent(QPaintEvent*);
private:
    QImage img;
};

QGLCanvas::QGLCanvas(QWidget* parent)
    : QGLWidget(parent)
{
}

void QGLCanvas::setImage(const QImage& image)
{
    img = image;
}

void QGLCanvas::paintEvent(QPaintEvent*)
{
    QPainter p(this);

    //Set the painter to use a smooth scaling algorithm.
    p.setRenderHint(QPainter::SmoothPixmapTransform, 1);

    p.drawImage(this->rect(), img);
}

有了這個(gè),我仍然需要將 YUV 420P 轉(zhuǎn)換為 RGB32,但是 ffmpeg 在 libswscale 中非常快速地實(shí)現(xiàn)了這種轉(zhuǎn)換.主要收益來自兩件事:

With this, I still have to convert the YUV 420P to RGB32, but ffmpeg has a very fast implementation of that conversion in libswscale. The major gains come from two things:

  • 無需軟件縮放.縮放是在視頻卡上完成的(如果有)
  • QImageQPixmap 的轉(zhuǎn)換,在 QPainter::drawImage() 函數(shù)中發(fā)生的轉(zhuǎn)換是在原始圖像分辨率下執(zhí)行的與升級的全屏分辨率相反.
  • No need for software scaling. Scaling is done on the video card (if available)
  • Conversion from QImage to QPixmap, which is happening in the QPainter::drawImage() function is performed at the original image resolution as opposed to the upscaled fullscreen resolution.

我用我以前的方法將我的處理器固定在顯示器上(解碼是在另一個(gè)線程中完成的).現(xiàn)在,我的顯示線程僅使用大約 8-9% 的內(nèi)核進(jìn)行全屏 1920x1200 30fps 播放.我敢肯定,如果我可以將 YUV 數(shù)據(jù)直接發(fā)送到視頻卡,它可能會變得更好,但現(xiàn)在已經(jīng)足夠了.

I was pegging my processor on just the display (decoding was being done in another thread) with my previous method. Now my display thread only uses about 8-9% of a core for fullscreen 1920x1200 30fps playback. I'm sure it could probably get even better if I could send the YUV data straight to the video card, but this is plenty good enough for now.

這篇關(guān)于在 Qt 中顯示解碼視頻幀的最有效方法是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 蜂窝块状沸石分子筛-吸附脱硫分子筛-萍乡市捷龙环保科技有限公司 | ?水马注水围挡_塑料注水围挡_防撞桶-常州瑞轩水马注水围挡有限公司 | 海水晶,海水素,海水晶价格-潍坊滨海经济开发区强隆海水晶厂 | 胃口福饺子加盟官网_新鲜现包饺子云吞加盟 - 【胃口福唯一官网】 | 多功能真空滤油机_润滑油全自动滤油机_高效真空滤油机价格-重庆润华通驰 | 沈阳真空机_沈阳真空包装机_沈阳大米真空包装机-沈阳海鹞真空包装机械有限公司 | 佛山市钱丰金属不锈钢蜂窝板定制厂家|不锈钢装饰线条|不锈钢屏风| 电梯装饰板|不锈钢蜂窝板不锈钢工艺板材厂家佛山市钱丰金属制品有限公司 | 广州冷却塔维修厂家_冷却塔修理_凉水塔风机电机填料抢修-广东康明节能空调有限公司 | 高速混合机_锂电混合机_VC高效混合机-无锡鑫海干燥粉体设备有限公司 | 牛奶检测仪-乳成分分析仪-北京海谊 | 德国BOSCH电磁阀-德国HERION电磁阀-JOUCOMATIC电磁阀|乾拓百科 | 邢台人才网_邢台招聘网_邢台123招聘【智达人才网】 | 云阳人才网_云阳招聘网_云阳人才市场_云阳人事人才网_云阳人家招聘网_云阳最新招聘信息 | 济南展厅设计施工_数字化展厅策划设计施工公司_山东锐尚文化传播有限公司 | 培训一点通 - 合肥驾校 - 合肥新亚驾校 - 合肥八一驾校 | 婚博会2024时间表_婚博会门票领取_婚博会地址-婚博会官网 | 高压分散机(高压细胞破碎仪)百科-北京天恩瀚拓 | Boden齿轮油泵-ketai齿轮泵-yuken油研-无锡新立液压有限公司 | 基业箱_环网柜_配电柜厂家_开关柜厂家_开关断路器-东莞基业电气设备有限公司 | 欧景装饰设计工程有限公司-无锡欧景装饰官网 | 世纪豪门官网 世纪豪门集成吊顶加盟电话 世纪豪门售后电话 | 丁基胶边来料加工,医用活塞边角料加工,异戊二烯橡胶边来料加工-河北盛唐橡胶制品有限公司 | 次氯酸钠厂家,涉水级次氯酸钠,三氯化铁生产厂家-淄博吉灿化工 | 贵州自考_贵州自学考试网 | 黑龙江「京科脑康」医院-哈尔滨失眠医院_哈尔滨治疗抑郁症医院_哈尔滨精神心理医院 | 活性氧化铝|无烟煤滤料|活性氧化铝厂家|锰砂滤料厂家-河南新泰净水材料有限公司 | 米顿罗计量泵(科普)——韬铭机械| 分子蒸馏设备(短程分子蒸馏装置)_上海达丰仪器 | 空调风机,低噪声离心式通风机,不锈钢防爆风机,前倾皮带传动风机,后倾空调风机-山东捷风风机有限公司 | 乐泰胶水_loctite_乐泰胶_汉高乐泰授权(中国)总代理-鑫华良供应链 | 水厂污泥地磅|污泥处理地磅厂家|地磅无人值守称重系统升级改造|地磅自动称重系统维修-河南成辉电子科技有限公司 | 空调风机,低噪声离心式通风机,不锈钢防爆风机,前倾皮带传动风机,后倾空调风机-山东捷风风机有限公司 | 气动隔膜泵厂家-温州永嘉定远泵阀有限公司 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 无线讲解器-导游讲解器-自助讲解器-分区讲解系统 品牌生产厂家[鹰米讲解-合肥市徽马信息科技有限公司] | 内窥镜-工业内窥镜厂家【上海修远仪器仪表有限公司】 | 名律网-法律问题咨询-找律师-法律知识| 首页|成都尚玖保洁_家政保洁_开荒保洁_成都保洁 | 缝纫客 | 重庆网站建设,重庆网站设计,重庆网站制作,重庆seo,重庆做网站,重庆seo,重庆公众号运营,重庆小程序开发 | 专业的新乡振动筛厂家-振动筛品质保障-环保振动筛价格—新乡市德科筛分机械有限公司 |