This article is compiled by the editor of Programming Notes# for you. It mainly introduces the knowledge related to writing video players (vlc kernel) with Qt. I hope it will be of some reference value to you.
In the process of researching qt+vlc, I want to directly make a player for independent projects. Vlc also supports hardware acceleration, except that some computer hardware does not support it. It is fast to write a player with the vlc core, just call the api directly, logic processing and ui display are basically done in minutes, it is better to add some beautification to make it more perfect, many players on the market are written by the vlc core, or ffmpeg written.
You can execute file download: https://pan.baidu.com/s/1KHTsgQUvtzWa3rLB_Tmo7A
1: Multi-threaded real-time playback of rtsp video stream
2: Support windows+linux+mac
3: Multi-threaded Display the image without getting stuck on the main interface
4: Automatically reconnect the webcam
5: You can set the size of the border Offset and border color
6: You can set whether to draw the OSD label, that is, label text or picture and label position
7: You can set two OSD positions and styles
8: You can set whether to save To file and file name
9: Can play local video files, support setting frame rate
10: Support h265 video stream + rtmp and other common video streams
11: Can pause and continue playing
br />12: Support callback mode and handle mode
13: Automatically send the current playback position and volume as a signal whether to mute or not
14: Provide an interface to set the playback position and volume and set mute
#ifndef VLCTHREAD_H
#define VLCTHREAD_H
#include
class QLabel;
class libvlc_instance_t ;
class libvlc_media_t;
class libvlc_media_player_t;
class VlcThread : public QThread
{
Q_OBJECT
public:
enum VlcState {
VlcState_NothingSpecial = 0,
VlcState_Opening = 1,
VlcState_Buffering = 2,
VlcState_Playing = 3,
VlcState_Paused = 4,
VlcState_Stopped = 5,
VlcState_End ed = 6,
VlcState_Error = 7
};
explicit VlcThread(QObject *parent = 0);
~VlcThread();
protected:
void run();
private:
bool stopped; //stop thread flag Bit
bool isPlayVideo; //Start playback flag
bool isPauseVideo; //Pause playback flag
bool isStopVideo; //Stop playback flag
bool isReadPosition; //Read current position flag Bit
QLabel *lab; //Display video label
QString fileName; //File name
QString suffix; //File extension
libvlc_instance_t *vlcInst;
libvlc_media_t * vlcMedia;
libvlc_media_player_t *vlcPlayer;
public:
//Get file name
QString getFileName() const;
//Get extension name
QString getSuffix() const;
private slots :
//Read file length
void readLength();
//Get current position
void readPosition();
//Start playing
void playVideo();
//Pause playback
void pauseVideo();
//Stop playback
void stopVideo();
signals:
//Start playing signal
void playStart();
//Stop playing signal
void playStop();
//Pause playing signal
void playPause();
//Current playback duration
void filePositionReceive(uint position, bool isPlay);
//Total duration
void fileLengthReceive(uint length);
//Volume size
void fileVolumeReceive(int volume, bool mute);
public slots:
//Set the carrier to play
void setWidget(QLabel *lab);
//Set file
void setFileName(const QString &fileName);
//Set vlc parameters
void setOption(const QString &args);
//Set cache duration, in milliseconds
> void setDelayTime(int delayTime);
//Set to save the video file
void save(const QString &videoFilePath);
//Set the video aspect ratio
void setWidthHeight(int width, int height) ;
//Set display image
void setImage(QLabel *lab, const QString &fileName, int width, int height);
//Play
void play();
//Pause
void pause();
//stop
void stop();
//stop thread
void stopAll();
//save snapshot
void snapshot( const QString &imageFilePath);
//Check if it is alive
bool getIsPlaying();
//Get the current state
VlcState getStatus();
//Get the length
uint getLength( );
//Get the current playback position
uint getPosition();
//Set the playback position
void setPosition(int position);
//Get the mute status
bool getMute ();
//Set mute
void setMute(bool mute);
//Get volume
int getVolumn();
//Set volume
void setVolumn(int volumen );
//Get audio track
int getTrack();
//Get the number of audio tracks
int getTrackCount();
//Set audio track
void setTrack(int track);
};
#endif // VLCTHREAD_H