-
UID:110085
-
- 注册时间2010-12-21
- 最后登录2024-04-18
- 在线时间3537小时
-
- 发帖2740
- 搜Ta的帖子
- 精华2
- 金钱32703
- 威望3368
- 贡献值588
- 好评度3386
-
访问TA的空间加好友用道具
|
前几天写了个ffmpeg版本,今天特意抽空改写个vlc版本,之前vlc播放视频后,被接管了不能识别到鼠标,需要重新编译vlc源码得到支持鼠标消息的版本。 /** * vlc视频播放类 作者:feiyangqingyun(QQ:517216493) 2018-5-2 * 1:多线程实时播放rtsp视频流 * 2:支持windows+linux+mac * 3:多线程 显示图像,不卡主 界面 * 4:自动重连网络摄像头 * 5:可设置边框大小即偏移量和边框颜色 * 6:可设置是否绘制OSD标签即标签文本或 图片和标签位置 * 7:可设置两种OSD位置和风格 * 8:可设置是否保存到 文件以及文件名 * 9:可播放本地视频文件,支持设置帧率 * 10:支持h265视频流+rtmp等常见视频流 * 11:可暂停播放和继续播放 */ window.open('http://www.qtcn.org/bbs/attachment/Mon_1807/44_110085_b31558552184eb0.jpg?178');" style="max-width:700px;max-height:700px;" onload="if(is_ie6&&this.offsetWidth>700)this.width=700;" >可执行文件下载: https://pan.baidu.com/s/18qX9cGfC9V0-ADmQ6vus_A 头文件代码 - #ifndef VLC_H
- #define VLC_H
- #include <QtGui>
- #include <QtNetwork>
- #if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
- #include <QtWidgets>
- #endif
- #include "libvlc_head.h"
- class VlcWidget;
- class VlcObject : public QObject
- {
- Q_OBJECT
- public:
- enum VlcState {
- VlcState_NothingSpecial = 0,
- VlcState_Opening = 1,
- VlcState_Buffering = 2,
- VlcState_Playing = 3,
- VlcState_Paused = 4,
- VlcState_Stopped = 5,
- VlcState_Ended = 6,
- VlcState_Error = 7
- };
- explicit VlcObject(QObject *parent = 0);
- private:
- QMutex mutex; //锁对象
- QDateTime lastTime; //最后的消息时间
- bool isRtsp; //是否是视频流
- libvlc_instance_t *vlcInst; //载体对象
- libvlc_media_t *vlcMedia; //媒体对象
- libvlc_media_player_t *vlcPlayer; //播放对象
- int videoWidth; //视频宽度
- int videoHeight; //视频高度
- int checkTime; //检测超时时间
- bool checkConn; //检测视频流连接
- bool saveFile; //是否保存文件
- QString fileName; //保存文件名称
- QString url; //视频流地址
- QString suffix; //拓展名
- public:
- //获取最后的活动时间
- QDateTime getLastTime();
- //获取url地址
- QString getUrl();
- //快照
- void snap(const QString &fileName, int width = 640, int height = 480);
- //设置参数
- void setOption(const QString &args);
- //设置视频宽高比例
- void setSize(int width, int height);
- //获取是否正在播放
- bool getIsPlaying();
- //获取当前状态
- VlcState getState();
- //获取长度
- uint getLength();
- //获取当前播放位置
- uint getPosition();
- //设置播放位置
- void setPosition(int position);
- //获取静音状态
- bool getMute();
- //设置静音
- void setMute(bool mute);
- //获取音量
- int getVolumn();
- //设置音量
- void setVolumn(int volumn);
- //获取音轨
- int getTrack();
- //获取音轨数量
- int getTrackCount();
- //设置音轨
- void setTrack(int track);
- signals:
- //播放成功
- void receivePlayOk();
- //播放失败
- void receivePlayError();
- //播放结束
- void receivePlayFinsh();
- //收到图片信号
- void receiveImage(const QImage &image);
- public slots:
- //设置视频宽度
- void setVideoWidth(int videoWidth);
- //设置视频高度
- void setVideoHeight(int videoHeight);
- //设置检测连接超时
- void setCheckTime(int checkTime);
- //设置是否检测连接
- void setCheckConn(bool checkConn);
- //设置是否保存文件
- void setSaveFile(bool saveFile);
- //设置保存文件名称
- void setFileName(const QString &fileName);
- //设置视频流地址
- void setUrl(const QString &url);
- //校验url
- bool checkUrl();
- //初始化视频对象
- bool init();
- //播放视频对象
- bool play();
- //暂停播放
- void pause();
- //继续播放
- void next();
- //释放对象
- void free();
- //停止采集线程
- void stop();
- };
- //实时视频显示窗体类
- class VlcWidget : public QWidget
- {
- Q_OBJECT
- Q_ENUMS(OSDFormat)
- Q_ENUMS(OSDPosition)
- Q_PROPERTY(bool copyImage READ getCopyImage WRITE setCopyImage)
- Q_PROPERTY(bool checkLive READ getCheckLive WRITE setCheckLive)
- Q_PROPERTY(bool drawImage READ getDrawImage WRITE setDrawImage)
- Q_PROPERTY(bool fillImage READ getFillImage WRITE setFillImage)
- Q_PROPERTY(int timeout READ getTimeout WRITE setTimeout)
- Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth)
- Q_PROPERTY(QColor borderColor READ getBorderColor WRITE setBorderColor)
- Q_PROPERTY(QColor focusColor READ getFocusColor WRITE setFocusColor)
- Q_PROPERTY(QString bgText READ getBgText WRITE setBgText)
- Q_PROPERTY(QImage bgImage READ getBgImage WRITE setBgImage)
- Q_PROPERTY(bool osd1Visible READ getOSD1Visible WRITE setOSD1Visible)
- Q_PROPERTY(int osd1FontSize READ getOSD1FontSize WRITE setOSD1FontSize)
- Q_PROPERTY(QString osd1Text READ getOSD1Text WRITE setOSD1Text)
- Q_PROPERTY(QColor osd1Color READ getOSD1Color WRITE setOSD1Color)
- Q_PROPERTY(QImage osd1Image READ getOSD1Image WRITE setOSD1Image)
- Q_PROPERTY(OSDFormat osd1Format READ getOSD1Format WRITE setOSD1Format)
- Q_PROPERTY(OSDPosition osd1Position READ getOSD1Position WRITE setOSD1Position)
- Q_PROPERTY(bool osd2Visible READ getOSD2Visible WRITE setOSD2Visible)
- Q_PROPERTY(int osd2FontSize READ getOSD2FontSize WRITE setOSD2FontSize)
- Q_PROPERTY(QString osd2Text READ getOSD2Text WRITE setOSD2Text)
- Q_PROPERTY(QColor osd2Color READ getOSD2Color WRITE setOSD2Color)
- Q_PROPERTY(QImage osd2Image READ getOSD2Image WRITE setOSD2Image)
- Q_PROPERTY(OSDFormat osd2Format READ getOSD2Format WRITE setOSD2Format)
- Q_PROPERTY(OSDPosition osd2Position READ getOSD2Position WRITE setOSD2Position)
- public:
- //标签格式
- enum OSDFormat {
- OSDFormat_Text = 0, //文本
- OSDFormat_Date = 1, //日期
- OSDFormat_Time = 2, //时间
- OSDFormat_DateTime = 3, //日期时间
- OSDFormat_Image = 4 //图片
- };
- //标签位置
- enum OSDPosition {
- OSDPosition_Left_Top = 0, //左上角
- OSDPosition_Left_Bottom = 1, //左下角
- OSDPosition_Right_Top = 2, //右上角
- OSDPosition_Right_Bottom = 3 //右下角
- };
- explicit VlcWidget(QWidget *parent = 0);
- ~VlcWidget();
- protected:
- void paintEvent(QPaintEvent *);
- void drawBorder(QPainter *painter);
- void drawBg(QPainter *painter);
- void drawImg(QPainter *painter, QImage img);
- void drawOSD(QPainter *painter,
- int osdFontSize,
- const QString &osdText,
- const QColor &osdColor,
- const QImage &osdImage,
- const OSDFormat &osdFormat,
- const OSDPosition &osdPosition);
- private:
- VlcObject *vlc; //实时视频采集对象
- QTimer *timerCheck; //定时器检查设备是否在线
- QImage image; //要显示的图片
- bool copyImage; //是否拷贝图片
- bool checkLive; //检测是否活着
- bool drawImage; //是否绘制图片
- bool fillImage; //自动拉伸填充
- int timeout; //超时时间
- int borderWidth; //边框宽度
- QColor borderColor; //边框颜色
- QColor focusColor; //有焦点边框颜色
- QString bgText; //默认无图像显示文字
- QImage bgImage; //默认无图像背景图片
- bool osd1Visible; //显示标签1
- int osd1FontSize; //标签1字号
- QString osd1Text; //标签1文本
- QColor osd1Color; //标签1颜色
- QImage osd1Image; //标签1图片
- OSDFormat osd1Format; //标签1文本格式
- OSDPosition osd1Position; //标签1位置
- bool osd2Visible; //显示标签2
- int osd2FontSize; //标签2字号
- QString osd2Text; //标签2文本
- QColor osd2Color; //标签2颜色
- QImage osd2Image; //标签2图片
- OSDFormat osd2Format; //标签2文本格式
- OSDPosition osd2Position; //标签2位置
- public:
- QImage getImage() const;
- bool getIsPlaying() const;
- bool getCopyImage() const;
- bool getCheckLive() const;
- bool getDrawImage() const;
- bool getFillImage() const;
- int getTimeout() const;
- int getBorderWidth() const;
- QColor getBorderColor() const;
- QColor getFocusColor() const;
- QString getBgText() const;
- QImage getBgImage() const;
- bool getOSD1Visible() const;
- int getOSD1FontSize() const;
- QString getOSD1Text() const;
- QColor getOSD1Color() const;
- QImage getOSD1Image() const;
- OSDFormat getOSD1Format() const;
- OSDPosition getOSD1Position() const;
- bool getOSD2Visible() const;
- int getOSD2FontSize() const;
- QString getOSD2Text() const;
- QColor getOSD2Color() const;
- QImage getOSD2Image() const;
- OSDFormat getOSD2Format() const;
- OSDPosition getOSD2Position() const;
- private slots:
- //接收图像并绘制
- void updateImage(const QImage &image);
- //校验设备
- void checkVideo();
- signals:
- //播放成功
- void receivePlayOk();
- //播放失败
- void receivePlayError();
- //播放结束
- void receivePlayFinsh();
- //收到图片信号
- void receiveImage(const QImage &image);
- public slots:
- //设置视频宽度
- void setVideoWidth(int videoWidth);
- //设置视频高度
- void setVideoHeight(int videoHeight);
- //设置检测连接超时
- void setCheckTime(int checkTime);
- //设置是否检测连接
- void setCheckConn(bool checkConn);
- //设置是否保存文件
- void setSaveFile(bool saveFile);
- //设置保存文件名称
- void setFileName(const QString &fileName);
- //设置视频流地址
- void setUrl(const QString &url);
- //设置是否拷贝图片
- void setCopyImage(bool copyImage);
- //设置是否检测活着
- void setCheckLive(bool checkLive);
- //设置是否实时绘制图片
- void setDrawImage(bool drawImage);
- //设置是否拉伸填充
- void setFillImage(bool fillImage);
- //设置超时时间
- void setTimeout(int timeout);
- //设置边框宽度
- void setBorderWidth(int borderWidth);
- //设置边框颜色
- void setBorderColor(const QColor &borderColor);
- //设置有焦点边框颜色
- void setFocusColor(const QColor &focusColor);
- //设置无图像文字
- void setBgText(const QString &bgText);
- //设置无图像背景图
- void setBgImage(const QImage &bgImage);
- //设置标签1是否可见
- void setOSD1Visible(bool osdVisible);
- //设置标签1文字字号
- void setOSD1FontSize(int osdFontSize);
- //设置标签1文本
- void setOSD1Text(const QString &osdText);
- //设置标签1文字颜色
- void setOSD1Color(const QColor &osdColor);
- //设置标签1图片
- void setOSD1Image(const QImage &osdImage);
- //设置标签1格式
- void setOSD1Format(const OSDFormat &osdFormat);
- //设置标签1位置
- void setOSD1Position(const OSDPosition &osdPosition);
- //设置标签2是否可见
- void setOSD2Visible(bool osdVisible);
- //设置标签2文字字号
- void setOSD2FontSize(int osdFontSize);
- //设置标签2文本
- void setOSD2Text(const QString &osdText);
- //设置标签2文字颜色
- void setOSD2Color(const QColor &osdColor);
- //设置标签2图片
- void setOSD2Image(const QImage &osdImage);
- //设置标签2格式
- void setOSD2Format(const OSDFormat &osdFormat);
- //设置标签2位置
- void setOSD2Position(const OSDPosition &osdPosition);
- //打开设备
- void open();
- //暂停
- void pause();
- //继续
- void next();
- //关闭设备
- void close();
- //重新加载
- void restart();
- //清空
- void clear();
- //快照
- void snap(const QString &fileName, int width = 640, int height = 480);
- };
- #endif // VLC_H
|