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

How to implement Qt mpv event subscription

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

Share

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

This article mainly explains "how to achieve Qt mpv event subscription". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to achieve Qt mpv event subscription.

I. Preface

In the process of using libmpv, by subscribing to mpv events, you can know some events more accurately and on time, such as successful file opening, changes in playback status, etc., without timer to read the status, especially for this event successfully opened. If event subscription is not used, sometimes the video stream will be jammed for a while, such as non-existent video stream or bad network. There are two ways to avoid this situation, and the same is true in vlc and ffmpeg decoding. One way is to put this open directly into the thread to execute. Originally, the decoding process is a complete thread class, so initialization is performed in the thread directly through the change of the flag bit, and there is no pressure. Another way is to use event callback to open successfully. Then perform other processes such as reading information such as the width and height of the video, which generally need to be read after the file has been opened successfully.

There is no doubt that mpv also supports event subscription. Change the property events that need to be subscribed into the event subscription queue through the mpv_observe_property function. This function has four parameters. The first parameter refers to the mpv object (generated by mpv_create), and the second parameter refers to the user data. If it is not needed, enter 0 directly, which is generally not needed. The third parameter refers to the attribute name, as for what the attribute name is. You can consult the manual (http://mpv.io/manual/master/#properties) on the official website, and the fourth parameter refers to the format type of the attribute. Generally speaking, you will change and subscribe to these attribute events: duration (file length) and time-pos (current playback progress). After the event is subscribed, execute the mpv_set_wakeup_callback function to set the event callback function to handle it.

II. Functional features

Multi-thread real-time playback video stream + local video and so on.

Windows+linux+mac is supported.

Multi-thread display image, do not card the main interface.

Automatically reconnect the webcam.

You can set whether to save to a file and the file name.

You can drag the file directly to the mpvwidget control to play.

Supports h365 video streams + rtmp and other common video streams.

Playback can be paused and resumed.

Support for storing individual video files and storing video files at regular intervals.

Customize the top suspension bar and send click signal notification, which can be set whether it is enabled or not.

Can set screen stretch fill or proportional fill.

You can take screenshots (original pictures) and screenshots of the video.

Video files store MP4 files.

Qsv, dxva2, d3d11va and other hard decoding are supported.

Third, effect picture

4. Core code / / event handling static void handleEvents (mpv_handle * mpvPlayer, mpv_event * event, MpvThread * thread) {switch (event- > event_id) {case MPV_EVENT_PROPERTY_CHANGE: {mpv_event_property * property = (mpv_event_property *) event- > data; QString propertyName = property- > name; mpv_format propertyFormat = property- > format If (propertyName = = "duration") {/ / Total file length if (propertyFormat = = MPV_FORMAT_DOUBLE) {double time = * (double *) property- > data; uint length = time * 1000; thread- > doEvent (1, QVariantList ()

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