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 vlc Reading and Control by Qt

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article is about how Qt implements vlc reading and control. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

I. Preface

Vlc itself is a full-featured and powerful player, and he has all the playback features you can think of, such as obtaining the length of the video file, the cover of the album, the current playback progress, setting the playback progress, sound control, mute control, etc., these vlc are sealed for you, you can directly call the corresponding api function.

Look at vlc's official update frequency of vlc is also quite high, so after a variety of new video standards and formats come out, he is also constantly updating and improving, such as H265 ~ 8K video, etc., can be played normally, looking up the dynamic library directory of vlc, you can see that part of the decoding of vlc uses ffmpeg, so you know why he is so powerful, it turns out that he relies on ffmpeg, a super powerful full-function decoding library.

There are two ways to use vlc to control this block. One is to read it regularly in the thread, such as reading playback progress, current status, current volume, mute, etc., and the other is in the form of event callback. By default, it is recommended that the event callback mechanism can get a lot of event messages and is more efficient. You just need to call libvlc_event_attach to subscribe to the events you are interested in before opening the video, and call libvlc_event_detach to unsubscribe events when you don't need it, such as when you close it.

II. Functional features

Multithreading plays video streams and local videos in real time.

Support windows+linux+mac, support vlc2 and vlc3.

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

Automatically reconnect the webcam.

The border size can be set, that is, the offset and the border color.

You can set whether to draw OSD tags, that is, label text or pictures and label locations.

There are two OSD locations and styles that can be set.

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

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

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

Playback can be paused and resumed.

Callback mode and handle mode are supported.

Support thread reading progress and other information and event callback two processing modes.

Automatically signal whether the current playback position and volume are muted or not.

Provides the interface to set the playback position and volume and set mute.

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.

Third, effect picture

IV. Related sites

Domestic site: https://gitee.com/feiyangqingyun/QWidgetDemo

International site: https://github.com/feiyangqingyun/QWidgetDemo

Personal homepage: https://blog.csdn.net/feiyangqingyun

Zhihu homepage: https://www.zhihu.com/people/feiyangqingyun/

Experience address: https://blog.csdn.net/feiyangqingyun/article/details/97565652

5. The core code void VlcThread::setSize (int width, int height) {if (vlcPlayer! = NULL) {QString option = QString ("% 1int height% 2") .Arg (width) .arg (height); QByteArray data = option.toUtf8 (); const char * arg = data.constData () / / to dynamically change the aspect ratio once the video is opened, the value can only be recognized by vlc, such as 16:9 1:1 / / const char * arg = "4:3"; libvlc_video_set_aspect_ratio (vlcPlayer, arg);} bool VlcThread::getIsPlaying () {bool isPlaying = false; if (vlcPlayer! = NULL) {int result = libvlc_media_player_is_playing (vlcPlayer) IsPlaying = (result! = 0);} return isPlaying;} VlcThread::VlcState VlcThread::getState () {VlcState state = VlcThread::VlcState_NothingSpecial; if (vlcPlayer! = NULL) {state = (VlcState) libvlc_media_player_get_state (vlcPlayer);} return state;} uint VlcThread::getLength () {uint length = 0; if (vlcPlayer! = NULL) {length = libvlc_media_player_get_length (vlcPlayer) } return length;} uint VlcThread::getPosition () {uint positon = 0; if (vlcPlayer! = NULL) {positon = libvlc_media_player_get_time (vlcPlayer);} return positon;} void VlcThread::setPosition (int position) {if (vlcPlayer! = NULL & &! isRtsp) {libvlc_media_player_set_time (vlcPlayer, position);} bool VlcThread::getMute () {bool ok = false If (vlcPlayer! = NULL) {int result = libvlc_audio_get_mute (vlcPlayer); ok = (result = = 0);} return ok;} void VlcThread::setMute (bool mute) {if (vlcPlayer! = NULL) {libvlc_audio_set_mute (vlcPlayer, mute? 1: 0);} int VlcThread::getVolume () {int volume = 0 If (vlcPlayer! = NULL) {volume = libvlc_audio_get_volume (vlcPlayer);} return volume;} void VlcThread::setVolume (int volume) {if (vlcPlayer! = NULL) {libvlc_audio_set_volume (vlcPlayer, volume);}} int VlcThread::getTrack () {int track = 0; if (vlcPlayer! = NULL) {track = libvlc_audio_get_track (vlcPlayer);} return track } int VlcThread::getTrackCount () {int trackCount = 0; if (vlcPlayer! = NULL) {trackCount = libvlc_audio_get_track_count (vlcPlayer);} return trackCount;} void VlcThread::setTrack (int track) {if (vlcPlayer! = NULL) {track = libvlc_audio_set_track (vlcPlayer, track);}} Thank you for reading! This is the end of this article on "how to achieve vlc reading and control in Qt". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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