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 realize Qt mpv Decoding and playback

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "how to achieve Qt mpv decoding and playback". In daily operation, I believe many people have doubts about how to achieve Qt mpv decoding and playback. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to achieve Qt mpv decoding and playback". Next, please follow the editor to study!

I. Preface

I played vlc decoding and ffmpeg decoding. Not long ago, there was a customer who needed to change to mpv decoding, so I studied the use of mpv. Since I used mpv, I found that I couldn't put it down. This thing is naturally suitable for geeks and programmers. It encapsulates all kinds of processing into commands and attribute calls, such as playback progress. You only need to read the attribute time-pos. If you want to read the volume, you only need to read the attribute volume. Just set the volume and directly set the corresponding value of the property volume, my dear, this is great, isn't this our dream way of dealing with it? You only need to encapsulate a few general processing interfaces (read property mpv_get_property, set property mpv_set_property, execute command mpv_command_node, set parameter mpv_set_option) to cover most of the functions, you say easy to use no, you want this effect!

Mpv is a multi-platform open source player based on MPlayer and MPlayer2. It is an open source, cross-platform video player with a minimalist GUI interface and rich command line controls. It has extensive output device support on Linux, built-in ffmpeg decoder, supports most video and audio formats, supports local and network playback, supports ass special effects subtitles, and GPU decoding ability is excellent. MPV has all the functions of a standard player, you can play all kinds of videos, and you can control playback through common keyboard shortcuts. On the Internet, it is often praised as a divine player, a divine existence!

To display video through mpv, only the handle is found. I don't know if the callback is not supported. I went through the manuals and instructions on the official website, but I just couldn't find it. Another problem is to set the handle for playback through mpv_set_option. I don't know how to pass parameters on linux. If anyone has a way to leave a message, thank you.

Decoding and playback process:

Call mpv_create to create an instance.

Call mpv_set_option to set the playback handle.

Call mpv_set_property to set some properties such as enabling keyboard input.

Call mpv_set_option to set some parameters such as hard decoding, timeout, etc.

Call mpv_initialize to initialize the instance.

Call mpv_command_async to execute the command loadfile to open the file to play.

Call mpv_terminate_destroy to release the instance.

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. The core code bool MpvThread::init () {/ / determines whether the camera can be connected to if (checkConn & & isRtsp) {if (! checkUrl (url, checkTime)) {return false;}} / / create an instance mpvPlayer = mpv_create (); / / if (callback) {return false is processed by callback and handle, respectively. } else {/ / set playback handle if (playWidget = = NULL) {return false;} / / the following is the method on WIN. How to find the method on linux HWND wid = (HWND) playWidget- > winId (); mpv_set_option (mpvPlayer, "wid", MPV_FORMAT_INT64, & wid) } / / request-level log message mpv_request_log_messages (mpvPlayer, "info"); / / enable default binding setValue ("input-default-bindings", "yes"); / / enable keyboard input setValue ("input-vo-keyboard", "yes"); / / set hardware acceleration none auto any d3d11va dxva2 setOption ("hwdec", hardware) / / set communication protocol tcp udp setOption ("rtsp-transport", transport); / / set network timeout unit setOption ("network-timeout", 3); / / initialize instance if (mpv_initialize (mpvPlayer))

< 0) { return false; } //设置保存文件,目前发现有部分视频流不行,原因未知 this->

InitSave (); / / create event manager if (callbackevent) {attachEvents (mpvPlayer); mpv_set_wakeup_callback (mpvPlayer, wakeup, this);} QByteArray data = url.toUtf8 (); / / command (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