Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the general GPU display method for Qt?

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "Qt general GPU display method is what", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Qt general GPU display method is what" it!

I. Preface

Using GPU to draw real-time video has always been a difficulty, if it is the security industry to do video surveillance development of this piece of personnel, this hurdle must be crossed, I have been engaged in the security industry's electronic fence this quite niche market segment development, video surveillance this is only the surrounding technology to play and discuss, about GPU drawing this really took a lot of detours.

Before decoding with ffmpeg, hard decoding has been done, such as supporting qsv, dxva2, d3d11va and other hard decoding processing, but after decoding at that time, it was still converted to QImage to draw, so it was greatly reduced. Although you can see that the utilization rate of GPU is there, the still time-consuming operation is still displayed in CPU, which is very embarrassing. Qt encapsulates most of the opengl operations. Directly made into a QOPenGLWidget, not only support ffmpeg decoding out of the yuyv format data display, but also support hard decoding out of the nv12 format data display, very good and very powerful, then greatly reduce the pressure on CPU, specially handed over to GPU to draw, after such a thorough transformation, the efficiency is improved at least 5 times, not too powerful! If opengl drawing is enabled, the corresponding memory will increase a lot. Maybe opengl drawing needs to open up a lot of memory to exchange data.

Using GPU display needs to support both yuyv format and nv12 format, because some poorly configured computers, hard decoding is likely to stop, at this time, you need to use opengl to directly draw ffmpeg soft decoded yuyv data to achieve automatic switching, so that it is compatible with all possible situations. It is found that the performance of ffmpeg4 is better than that of ffmpeg3,64 bit and better than that of 32-bit. On 64-bit operating system, the performance of UDP protocol is better than that of TCP, but it may lose packets.

Scheme CPU memory GPUnone+none12%147MB0%dxva2+none3%360MB38%d3d11va+none2%277MB62%none+painter30%147MB0%dxva2+painter30%360MB38%d3d11va+painter21%277MB62%none+yuyv17%177MB22%dxva2+yuyv25%400MB38%d3d11va+yuyv18%30MB65%qsv+nv1222%970MB40%dxva2+nv1220%380MB40%d3d11va+nv1215%320MB62% II, functional features

Supports multi-screen switching, full-screen switching, etc., including 1 "4" 6 "8" 9 "13" 16 "25" 36 "64 screen switching.

Support alt+enter full screen, esc exit full screen.

Custom message box + error box + inquiry box + prompt box in the lower right corner (including multiple formats).

17 sets of skin styles are changed at will, all styles are unified, including menus and so on.

The head dashboard mouse moves up to highlight, and eight directions are accurately identified.

The bottom screen toolbar (screen division switch + screenshot sound, etc.) is moved up to highlight.

You can change the logo+ Chinese software name + English software name in the upper left corner of the configuration file.

Encapsulated Baidu map, view switching, motion trajectory, equipment location, mouse press to obtain longitude and latitude and so on.

Support picture map, the device button can drag freely on the picture map to automatically save location information.

On Baidu Maps and Picture Maps, double-click the video to preview the camera real-time video.

Stack forms, each form is a separate qwidget, making it easy to write your own code.

Top right mouse button menu, can dynamically control the time CPU+ upper left corner panel + lower left corner panel + upper right corner panel + lower right corner panel show and hide, support to restore the default layout.

Toolbars can place multiple small icons and close icons.

The left side and the right side can be dragged and stretched, and the width and height position can be automatically remembered and restored after restart.

Double-click the camera node to automatically play the video, double-click the node to automatically add videos in turn, automatically jump to the next one, and double-click the parent node to automatically add all the videos under that node.

The camera node is dragged to the corresponding form to play the video, and the local file can be dragged to play directly.

The video screen form supports dragging and swapping and instant response.

Double-click the node + drag the node + drag the form to change the position, and the url.txt is automatically updated.

Support loading channel video playback from url.txt, automatically memorizing the video corresponding to the last channel, and automatically opening and playing after the software starts.

Lower right corner volume bar control, lose focus automatically hide, volume bar with mute icon.

Integrate Baidu online map and offline map, you can add the corresponding location of the device, automatically generate the map, support zooming and adding coverings and so on.

Drag the video out of the channel form to automatically delete the video.

The right mouse button can delete the current + all videos and take screenshots of current + all videos.

Video recorder management, camera management, you can add, delete, modify, import and export print information, and immediately apply new equipment information to generate a tree list without restarting.

In the pro file, you are free to open or load the map.

Video playback can be switched freely by two kernels, vlc+ffmpeg, both of which can be set in pro.

You can set 1 "4" 9 "16 screen polling, you can set the polling interval and the polling stream type, etc. Click the start polling button on the right side of the toolbar at the bottom of the main interface, and click stop polling again.

By default, the mouse pointer is automatically hidden without operation for more than 10 seconds.

Support onvif search equipment, support any onvif camera, including but not limited to Haikang Dahuayu Shitian Weiye Huawei and so on.

Support onvif pan control, can move the head camera up and down, including reset and focal length adjustment, etc.

It also supports sqlite, mysql, postsql and other databases.

Can save video, can be selected for storage or single file storage, optional storage interval.

The video stream communication mode tcp+udp can be set, and the video decoding can be set as speed priority, quality priority, balance and so on.

Can set hard decoding type, support qsv, dxva2, d3d11va and so on.

Opengl is used by default to draw video, ultra-low CPU resource consumption, support for yuyv and nv12 two formats to draw, very powerful.

Highly customizable, users can easily derive their own functions on this basis, supporting linux and mac systems.

Third, effect picture

4. Core code void YUVOpenGLWidget2::initializeGL () {initializeOpenGLFunctions (); glDisable (GL_DEPTH_TEST); / / transfer vertex and texture coordinates static const GLfloat ver [] = {- 1.0f,-1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f} Static const GLfloat tex [] = {0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f}; / / set vertices, texture array and enable glVertexAttribPointer (0,2, GL_FLOAT, 0,0, ver); glEnableVertexAttribArray (0); glVertexAttribPointer (1,2, GL_FLOAT, 0,0, tex); glEnableVertexAttribArray (1); / / initialize shader this- > initShader () / / initialize textures this- > initTextures (); / / initialize color this- > initColor ();} void YUVOpenGLWidget2::paintGL () {if (! dataY | | dataU | |! dataV | | width = = 0 | | height = = 0) {this- > initColor (); return;} glActiveTexture (GL_TEXTURE0); glBindTexture (GL_TEXTURE_2D, textureY); glPixelStorei (GL_UNPACK_ROW_LENGTH, linesizeY) GlTexImage2D (GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, dataY); glUniform1i (textureUniformY, 0); glActiveTexture (GL_TEXTURE0 + 1); glBindTexture (GL_TEXTURE_2D, textureU); glPixelStorei (GL_UNPACK_ROW_LENGTH, linesizeU); glTexImage2D (GL_TEXTURE_2D, 0, GL_RED, width > > 1, height > > 1,0, GL_RED, GL_UNSIGNED_BYTE, dataU); glUniform1i (textureUniformU, 1) GlActiveTexture (GL_TEXTURE0 + 2); glBindTexture (GL_TEXTURE_2D, textureV); glPixelStorei (GL_UNPACK_ROW_LENGTH, linesizeV); glTexImage2D (GL_TEXTURE_2D, 0, GL_RED, width > > 1, height > > 1, 0, GL_RED, GL_UNSIGNED_BYTE, dataV); glUniform1i (textureUniformV, 2); glDrawArrays (GL_TRIANGLE_STRIP, 0,4) } void YUVOpenGLWidget2::initColor () {/ / take the background color of the artboard QColor color = palette (). Background (). Color (); / / set the background cleaning color glClearColor (color.redF (), color.greenF (), color.blueF (), color.alphaF ()); / / clear the color background glClear (GL_COLOR_BUFFER_BIT) } void YUVOpenGLWidget2::initShader () {/ / load vertex and element scripts program.addShaderFromSourceCode (QOpenGLShader::Vertex, vertShader); program.addShaderFromSourceCode (QOpenGLShader::Fragment, fragShader); / / set vertex position program.bindAttributeLocation ("vertexIn", 0); / / set texture position program.bindAttributeLocation ("textureIn", 1); / / compile shader program.link (); program.bind () / / get the address from shader textureUniformY = program.uniformLocation ("textureY"); textureUniformU = program.uniformLocation ("textureU"); textureUniformV = program.uniformLocation ("textureV");} void YUVOpenGLWidget2::initTextures () {/ / create texture glGenTextures (1, & textureY); glBindTexture (GL_TEXTURE_2D, textureY); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) GlTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glGenTextures (1, & textureU); glBindTexture (GL_TEXTURE_2D, textureU); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) GlTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glGenTextures (1, & textureV); glBindTexture (GL_TEXTURE_2D, textureV); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) GlTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) } Thank you for your reading, the above is the content of "what is the Qt general GPU display method". After the study of this article, I believe you have a deeper understanding of what the Qt general GPU display method is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report