In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to implement general video controls in Qt". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
I. Preface
In the previous video surveillance system, according to the needs of different users, we have made many kinds of video surveillance kernels, including ffmpeg kernel, vlc kernel, mpv kernel, and Haikang sdk kernel. In order to achieve general functions, it is very convenient to switch between different kernels. For example, pro directly changes the variable name of a DEFINE, so you need to make the use of various kernels into the same interface, so it looks neat. Therefore, the latter specially refines a general video control, which has no specific video playback control function, and needs to be implemented by calling specific methods according to different kernels. When you need to add protocols from Dahua sdk or other third-party manufacturers, you can directly apply this general video control. Adding a new monitoring kernel in the future can save a lot of work. Basically, you only need to do kernel parsing. The rest of the general interface and drawing images are directly handed over to the general video control.
General video control functions:
Border size can be set
Border color can be set
Two OSD tags can be set.
You can set whether to draw OSD tags or not
Label text or picture can be set
Can set OSD position upper left corner + lower left corner + upper right corner + lower right corner
OSD style text + date + time + date time + picture can be set.
Custom translucent suspension form, a row of buttons
The hover button can be customized, including background color + press color
Send a signal informing which hover button has been clicked
Be able to identify dragged files and notify url
Provide interfaces such as open close pause
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 VideoWidget::paintEvent (QPaintEvent *) {/ / if you don't need to draw if (! drawImage) {return;} / / qDebug () drawRect (rect ()); painter- > restore ();} void VideoWidget::drawBg (QPainter * painter) {painter- > save () / / draw text if the background picture is empty, otherwise draw the background image if (bgImage.isNull ()) {painter- > setFont (this- > font ()); painter- > setPen (palette (). Foreground (). Color ()); painter- > drawText (rect (), Qt::AlignCenter, bgText) } else {/ / Center int pixX = rect (). Center (). X ()-bgImage.width () / 2; int pixY = rect (). Center (). Y ()-bgImage.height () / 2; QPoint point (pixX, pixY); painter- > drawImage (point, bgImage);} painter- > restore ();} void VideoWidget::drawImg (QPainter * painter, QImage img) {painter- > save () Int offset = borderWidth * 1 + 0; if (fillImage) {QRect rect (offset / 2, offset / 2, width ()-offset, height ()-offset); painter- > drawImage (rect, img);} else {/ / automatically centering img = img.scaled (width ()-offset, height ()-offset, Qt::KeepAspectRatio) Int pixX = rect (). Center (). X ()-img.width () / 2; int pixY = rect (). Center (). Y ()-img.height () / 2; QPoint point (pixX, pixY); painter- > drawImage (point, img);} painter- > restore () } void VideoWidget::drawOSD (QPainter * painter, bool osdVisible, int osdFontSize, const QString & osdText, const QColor & osdColor, const QImage & osdImage, const VideoWidget::OSDFormat & osdFormat) Const VideoWidget::OSDPosition & osdPosition) {if (! osdVisible) {return } painter- > save (); / / offset the tag position as much as possible to avoid occlusion of QRect osdRect (rect (). X () + (borderWidth * 2), rect (). Y () + (borderWidth * 2), width ()-(borderWidth * 5), height ()-(borderWidth * 5); int flag = Qt::AlignLeft | Qt::AlignTop; QPoint point = QPoint (osdRect.x (), osdRect.y ()) If (osdPosition = = OSDPosition_Left_Top) {flag = Qt::AlignLeft | Qt::AlignTop; point = QPoint (osdRect.x (), osdRect.y ());} else if (osdPosition = = OSDPosition_Left_Bottom) {flag = Qt::AlignLeft | Qt::AlignBottom; point = QPoint (osdRect.x (), osdRect.height ()-osdImage.height ()) } else if (osdPosition = = OSDPosition_Right_Top) {flag = Qt::AlignRight | Qt::AlignTop; point = QPoint (osdRect.width ()-osdImage.width (), osdRect.y ());} else if (osdPosition = = OSDPosition_Right_Bottom) {flag = Qt::AlignRight | Qt::AlignBottom; point = QPoint (osdRect.width ()-osdImage.width (), osdRect.height ()-osdImage.height ()) } if (osdFormat = = OSDFormat_Image) {painter- > drawImage (point, osdImage);} else {QDateTime now = QDateTime::currentDateTime (); QString text = osdText; if (osdFormat = = OSDFormat_Date) {text = now.toString ("yyyy-MM-dd");} else if (osdFormat = = OSDFormat_Time) {text = now.toString ("HH:mm:ss") } else if (osdFormat = = OSDFormat_DateTime) {text = now.toString ("yyyy-MM-dd HH:mm:ss");} / / set color and font size QFont font; font.setPixelSize (osdFontSize); painter- > setPen (osdColor); painter- > setFont (font); painter- > drawText (osdRect, flag, text);} painter- > restore () } this is the end of the content of "how to implement a general video control in Qt". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.