当前位置:   article > 正文

libVLC 视频抓图

libVLC 视频抓图

Windows操作系统提供了多种便捷的截图方式,常见的有以下几种:

  • 全屏截图:通过按下PrtSc键(Print Screen),可以截取整个屏幕的内容。截取的图像会保存在剪贴板中,可以通过Ctrl+V粘贴到图片编辑工具或其他软件的输入框中。
  • 当前窗口截图:同时按下Alt + PrtSc键,可以截取当前活动的窗口。同样,截图内容会被保存在剪贴板中。
  • 矩形截图:使用快捷键Windows + Shift + S,可以选择矩形截图模式,然后拖动鼠标选取屏幕上的任意矩形区域进行截图。
  • 自由形状截图:同样使用Windows + Shift + S快捷键,可以选择任意形状截图模式,允许你自由绘制截图区域的形状。

libVLC 中通过libvlc_video_take_snapshot核心接口来截图。

以下是如何使用 libVLC 设置视频裁剪区域的基本步骤:

1. 初始化 libVLC 和媒体播放器

首先,你需要初始化 libVLC 实例和媒体播放器对象。

  1. #include <vlc/vlc.h>
  2.  
  3. int main(int argc, char* argv[])
  4. {
  5.     libvlc_instance_t* inst;
  6.     libvlc_media_player_t* mp;
  7.     libvlc_media_t* m;
  8.  
  9.     // 加载 libVLC 引擎
  10.     inst = libvlc_new(0, NULL);
  11.  
  12.     // 创建一个新的 item
  13.     m = libvlc_media_new_location(inst, "your_video_path_here");
  14.     mp = libvlc_media_player_new_from_media(m);
  15.  
  16.     // 不再需要媒体对象
  17.     libvlc_media_release(m);
  18. }

2. 播放视频

  1. // 播放媒体播放器
  2. libvlc_media_player_play(mp);
  3.  
  4. // 保持程序运行,直到视频播放完成
  5. while (libvlc_media_player_is_playing(mp)) {
  6.     // 可以在这里加入延时
  7. }
  8.  
  9. // 清理 libVLC
  10. libvlc_media_player_stop(mp);
  11. libvlc_media_player_release(mp);
  12. libvlc_release(inst);
  13.  
  14. return 0;

3.截图

这里为了方便,路径写死了。

  1. if (vlc_mediaPlayer)
  2. {
  3. QString path = "./snap.png";
  4. libvlc_video_take_snapshot(vlc_mediaPlayer, 0, path.toUtf8().data(), 0, 0);
  5. }

以下是VLC播放器中使用的截图界面,我们仿照这个做一个界面。 

以下是效果图。

菜单添加action,并响应槽函数。

  1. m_snapAction = m_videoMenu->addAction("截图");
  2. connect(m_snapAction, &QAction::triggered, this, &showWidget::slotSnap);

槽函数如下图所示,为了方便,路径写死了。 

  1. void showWidget::slotSnap()
  2. {
  3. if (vlc_mediaPlayer)
  4. {
  5. QString path = "./snap.png";
  6. libvlc_video_take_snapshot(vlc_mediaPlayer, 0, path.toUtf8().data(), 0, 0);
  7. }
  8. }

生成目录下snap.png。 

完整源码:

  1. #pragma once
  2. #define LIBVLC_USE_PTHREAD_CANCEL 1
  3. #include <QtWidgets/QWidget>
  4. #include "ui_showWidget.h"
  5. #include <QMenu>
  6. #include <QActionGroup>
  7. #include <vlc/vlc.h>
  8. #include <QDebug>
  9. #include <QFileDialog>
  10. #include <QThread>
  11. #include <QMouseEvent>
  12. #include <QKeyEvent>
  13. enum Rate
  14. {
  15. Rate2X,
  16. Rate1_5X,
  17. Rate1_25X,
  18. Rate1_0X,
  19. Rate0_75X,
  20. Rate0_5X
  21. };
  22. class showWidget : public QWidget
  23. {
  24. Q_OBJECT
  25. public:
  26. showWidget(QWidget *parent = nullptr);
  27. ~showWidget();
  28. protected:
  29. virtual void mousePressEvent(QMouseEvent *event);
  30. virtual void mouseDoubleClickEvent(QMouseEvent *event);
  31. virtual void keyPressEvent(QKeyEvent *event);
  32. private slots:
  33. void slotOpenFile();
  34. void slotPlay();
  35. void slotPause();
  36. void slotStop();
  37. void slotValueChanged(int value);
  38. void slotCurrentIndexChanged(int index);
  39. void slotActionTriggered(QAction *action);
  40. void slotCropActionTriggered(QAction *action);
  41. void slotScaleActionTriggered(QAction *action);
  42. void slotSnap();
  43. private:
  44. //事件处理回调
  45. static void vlcEvents(const libvlc_event_t *ev, void *param);
  46. //初始化menu
  47. void initMenu();
  48. private:
  49. Ui::showWidgetClass ui;
  50. private:
  51. libvlc_instance_t *vlc_base = nullptr;
  52. libvlc_media_t *vlc_media = nullptr;
  53. libvlc_media_player_t *vlc_mediaPlayer = nullptr;
  54. QList<float> m_lstRate;
  55. QMenu *m_menu = nullptr;
  56. QAction *m_video = nullptr;
  57. QAction *m_scaleAction = nullptr; //缩放
  58. QAction *m_aspectRatioAction = nullptr; //宽高比
  59. QAction *m_cropAction = nullptr; //裁剪
  60. QAction *m_snapAction = nullptr;//截图
  61. QMenu *m_videoMenu = nullptr;
  62. //宽高比
  63. QMenu *m_aspectRatioMenu = nullptr;
  64. QAction *m_default = nullptr;
  65. QAction *m_16_9 = nullptr;
  66. QAction *m_4_3 = nullptr;
  67. QAction *m_1_1 = nullptr;
  68. QAction *m_16_10 = nullptr;
  69. QAction *m_2_21_1 = nullptr;
  70. QAction *m_2_35_1= nullptr;
  71. QAction *m_2_38_1 = nullptr;
  72. QAction *m_5_4 = nullptr;
  73. QActionGroup *m_group = nullptr;
  74. QAction *m_preAspectRatio = nullptr;
  75. //宽高比
  76. //裁剪
  77. QMenu *m_cropMenu = nullptr;
  78. QAction *m__cropDefault = nullptr;
  79. QAction *m__crop16_10 = nullptr;
  80. QAction *m__crop16_9 = nullptr;
  81. QAction *m__crop4_3 = nullptr;
  82. QAction *m__crop1_85_1 = nullptr;
  83. QAction *m__crop2_21_1 = nullptr;
  84. QAction *m__crop2_35_1 = nullptr;
  85. QAction *m__crop2_39_1 = nullptr;
  86. QAction *m__crop5_3 = nullptr;
  87. QAction *m__crop5_4 = nullptr;
  88. QAction *m__crop1_1 = nullptr;
  89. QActionGroup *m_cropGroup = nullptr;
  90. QAction *m_preCrop= nullptr;
  91. //裁剪
  92. //缩放
  93. QMenu *m_scaleMenu = nullptr;
  94. QAction *m_scale1_4 = nullptr;
  95. QAction *m_scale1_2 = nullptr;
  96. QAction *m_scale1_1 = nullptr;
  97. QAction *m_scale2_1 = nullptr;
  98. QActionGroup *m_scaleGroup = nullptr;
  99. QAction *m_preScale = nullptr;
  100. //缩放
  101. char *m_defalutRate = nullptr;
  102. char *m_defalutCrop = nullptr;
  103. float m_defalutScale = 0;
  104. };

cpp

  1. #include "showWidget.h"
  2. #include <QTimer>
  3. #include <QTime>
  4. #pragma execution_character_set("utf-8")
  5. showWidget::showWidget(QWidget *parent)
  6. : QWidget(parent)
  7. {
  8. ui.setupUi(this);
  9. this->setWindowTitle("视频播放器");
  10. ui.cbxRate->setCurrentIndex(Rate1_0X);
  11. m_lstRate << 2.0 << 1.5 << 1.25 << 1.0 << 0.75 << 0.5;
  12. initMenu();
  13. ui.btnOpen->setFocusPolicy(Qt::NoFocus);
  14. ui.btnPlay->setFocusPolicy(Qt::NoFocus);
  15. ui.btnPause->setFocusPolicy(Qt::NoFocus);
  16. ui.btnStop->setFocusPolicy(Qt::NoFocus);
  17. ui.hSliderVolumn->setFocusPolicy(Qt::NoFocus);
  18. ui.cbxRate->setFocusPolicy(Qt::NoFocus);
  19. connect(ui.btnOpen, &QPushButton::clicked, this, &showWidget::slotOpenFile);
  20. connect(ui.btnPlay, &QPushButton::clicked, this, &showWidget::slotPlay);
  21. connect(ui.btnPause, &QPushButton::clicked, this, &showWidget::slotPause);
  22. connect(ui.btnStop, &QPushButton::clicked, this, &showWidget::slotStop);
  23. connect(ui.btnSnap, &QPushButton::clicked, this, &showWidget::slotSnap);
  24. connect(ui.hSliderVolumn, &QSlider::valueChanged, this, &showWidget::slotValueChanged);
  25. connect(ui.cbxRate,SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentIndexChanged(int)));
  26. }
  27. showWidget::~showWidget()
  28. {
  29. libvlc_release(vlc_base); //减少libvlc实例的引用计数,并销毁
  30. }
  31. void showWidget::mousePressEvent(QMouseEvent *event)
  32. {
  33. switch (event->button())
  34. {
  35. case Qt::RightButton:
  36. //this->setWindowState(Qt::WindowMinimized);
  37. m_menu->exec(event->globalPos());
  38. break;
  39. default:
  40. QWidget::mousePressEvent(event);
  41. }
  42. }
  43. void showWidget::mouseDoubleClickEvent(QMouseEvent *event)
  44. {
  45. if (this->isFullScreen())
  46. {
  47. this->showNormal();
  48. }
  49. else
  50. {
  51. this->showFullScreen();
  52. }
  53. }
  54. void showWidget::keyPressEvent(QKeyEvent *event)
  55. {
  56. if (!vlc_mediaPlayer)
  57. return;
  58. int value = ui.hSliderVolumn->value();
  59. if (event->key() == Qt::Key_W) //添加音量
  60. {
  61. qDebug() << "up";
  62. slotValueChanged(value+10);
  63. }
  64. else if (event->key() == Qt::Key_S) //减小音量
  65. {
  66. slotValueChanged(value - 10);
  67. }
  68. else if (event->key() == Qt::Key_Space)
  69. {
  70. if (vlc_mediaPlayer && libvlc_media_player_get_state(vlc_mediaPlayer) == libvlc_Playing)
  71. {
  72. libvlc_media_player_pause(vlc_mediaPlayer);
  73. }
  74. else if (vlc_mediaPlayer && libvlc_media_player_get_state(vlc_mediaPlayer) == libvlc_Paused)
  75. {
  76. libvlc_media_player_play(vlc_mediaPlayer);
  77. }
  78. }
  79. }
  80. void showWidget::slotOpenFile()
  81. {
  82. /*选择文件*/
  83. QString filename = QFileDialog::getOpenFileName(this, "选择打开的文件", "D:/", tr("*.*"));
  84. std::replace(filename.begin(), filename.end(), QChar('/'), QChar('\\'));
  85. vlc_base = libvlc_new(0, NULL);
  86. vlc_media = libvlc_media_new_path(vlc_base, filename.toUtf8().data());
  87. if (!vlc_media) {
  88. return;
  89. }
  90. // 创建libvlc实例和媒体播放器
  91. vlc_mediaPlayer = libvlc_media_player_new_from_media(vlc_media);
  92. if (!vlc_mediaPlayer) {
  93. return;
  94. }
  95. // 等待元数据加载完成
  96. libvlc_media_parse(vlc_media);
  97. m_defalutRate = libvlc_video_get_aspect_ratio(vlc_mediaPlayer);
  98. m_defalutCrop = libvlc_video_get_crop_geometry(vlc_mediaPlayer);
  99. libvlc_video_set_mouse_input(vlc_mediaPlayer, 0);
  100. libvlc_video_set_key_input(vlc_mediaPlayer, 0);
  101. // 获取各种元数据
  102. const char *title = libvlc_media_get_meta(vlc_media, libvlc_meta_Title);
  103. const char *artist = libvlc_media_get_meta(vlc_media, libvlc_meta_Artist);
  104. const char *album = libvlc_media_get_meta(vlc_media, libvlc_meta_Album);
  105. const char *url = libvlc_media_get_meta(vlc_media, libvlc_meta_URL);
  106. const char *date = libvlc_media_get_meta(vlc_media, libvlc_meta_Date);
  107. const char *lang = libvlc_media_get_meta(vlc_media, libvlc_meta_Language);
  108. int duration = libvlc_media_get_duration(vlc_media); // 获取时长(单位:毫秒)
  109. qDebug("Title: %s", title ? title : "N/A");
  110. qDebug("Artist: %s", artist ? artist : "N/A");
  111. qDebug("Album: %s", album ? album : "N/A");
  112. qDebug("Duration: %d ms", duration);
  113. qDebug("url: %s", url ? url : "N/A");
  114. qDebug("date: %s", date ? date : "N/A");
  115. qDebug("lang: %s", lang ? lang : "N/A");
  116. libvlc_media_track_t **tracks;
  117. int track_count = libvlc_media_tracks_get(vlc_media,&tracks);
  118. for (unsigned i = 0; i < track_count; i++)
  119. {
  120. libvlc_media_track_t* track = tracks[i];
  121. // 显示轨道信息
  122. printf("Track #%u: %s\n", i, track->psz_description);
  123. // 这里可以获取到每一个轨道的信息,比如轨道类型 track->i_type
  124. // 可能是 libvlc_track_video, libvlc_track_audio 或者 libvlc_track_text (字幕)
  125. if (track->i_type == libvlc_track_video) {
  126. // 处理视频轨道信息
  127. qDebug("width = %d",track->video->i_width);
  128. qDebug("height = %d", track->video->i_height);
  129. qDebug("rate_num = %d", track->video->i_frame_rate_num);
  130. qDebug("rate_den = %d", track->video->i_frame_rate_den);
  131. }
  132. else if (track->i_type == libvlc_track_audio) {
  133. // 处理音频轨道信息
  134. qDebug("channels = %d", track->audio->i_channels);
  135. qDebug("rate = %d", track->audio->i_rate);
  136. }
  137. else if (track->i_type == libvlc_track_text) {
  138. // 处理字幕轨道信息
  139. }
  140. }
  141. //获取事件管理器
  142. libvlc_event_manager_t *em = libvlc_media_player_event_manager(vlc_mediaPlayer);
  143. // 注册事件监听器
  144. libvlc_event_attach(em, libvlc_MediaPlayerTimeChanged, vlcEvents, this);
  145. libvlc_event_attach(em, libvlc_MediaPlayerEndReached, vlcEvents, this);
  146. libvlc_event_attach(em, libvlc_MediaPlayerStopped, vlcEvents, this);
  147. libvlc_event_attach(em, libvlc_MediaPlayerPlaying, vlcEvents, this);
  148. libvlc_event_attach(em, libvlc_MediaPlayerPaused, vlcEvents, this);
  149. libvlc_media_player_set_hwnd(vlc_mediaPlayer, (void *)ui.widgetShow->winId());
  150. QTimer::singleShot(1000, this, &showWidget::slotPlay);
  151. }
  152. void showWidget::slotPlay()
  153. {
  154. if (vlc_mediaPlayer)
  155. {
  156. libvlc_media_player_play(vlc_mediaPlayer);
  157. m_defalutScale = libvlc_video_get_scale(vlc_mediaPlayer);
  158. }
  159. }
  160. void showWidget::slotPause()
  161. {
  162. if (vlc_mediaPlayer)
  163. libvlc_media_player_pause(vlc_mediaPlayer);
  164. }
  165. void showWidget::slotStop()
  166. {
  167. if (vlc_mediaPlayer)
  168. libvlc_media_player_stop(vlc_mediaPlayer);
  169. }
  170. void showWidget::slotValueChanged(int value)
  171. {
  172. if (vlc_mediaPlayer)
  173. libvlc_audio_set_volume(vlc_mediaPlayer, value);
  174. }
  175. void showWidget::slotCurrentIndexChanged(int index)
  176. {
  177. if (vlc_mediaPlayer)
  178. libvlc_media_player_set_rate(vlc_mediaPlayer, m_lstRate[index]);
  179. }
  180. void showWidget::slotActionTriggered(QAction *action)
  181. {
  182. if (!vlc_mediaPlayer)
  183. return;
  184. if (action == m_default)
  185. libvlc_video_set_aspect_ratio(vlc_mediaPlayer,m_defalutRate);
  186. else if(action == m_16_9)
  187. libvlc_video_set_aspect_ratio(vlc_mediaPlayer, "16:9");
  188. else if (action == m_4_3)
  189. libvlc_video_set_aspect_ratio(vlc_mediaPlayer, "4:3");
  190. else if (action == m_1_1)
  191. libvlc_video_set_aspect_ratio(vlc_mediaPlayer, "1:1");
  192. else if (action == m_16_10)
  193. libvlc_video_set_aspect_ratio(vlc_mediaPlayer, "16:10");
  194. else if (action == m_2_21_1)
  195. libvlc_video_set_aspect_ratio(vlc_mediaPlayer, "221:100");
  196. else if (action == m_2_35_1)
  197. libvlc_video_set_aspect_ratio(vlc_mediaPlayer, "235:100");
  198. else if (action == m_2_38_1)
  199. libvlc_video_set_aspect_ratio(vlc_mediaPlayer, "238:100");
  200. else if (action == m_5_4)
  201. libvlc_video_set_aspect_ratio(vlc_mediaPlayer, "5:4");
  202. action->setIcon(QIcon(":/image/images/point.png"));
  203. m_preAspectRatio->setIcon(QIcon());
  204. m_preAspectRatio = action;
  205. }
  206. void showWidget::slotCropActionTriggered(QAction *action)
  207. {
  208. if (!vlc_mediaPlayer)
  209. return;
  210. if (action == m__cropDefault)
  211. libvlc_video_set_crop_geometry(vlc_mediaPlayer, m_defalutCrop);
  212. else if (action == m__crop16_10)
  213. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "16:10");
  214. else if (action == m__crop16_9)
  215. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "16:9");
  216. else if (action == m__crop4_3)
  217. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "4:3");
  218. else if (action == m__crop1_85_1)
  219. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "185:100");
  220. else if (action == m__crop2_21_1)
  221. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "221:100");
  222. else if (action == m__crop2_35_1)
  223. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "235:100");
  224. else if (action == m__crop2_39_1)
  225. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "239:100");
  226. else if (action == m__crop5_3)
  227. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "5:3");
  228. else if (action == m__crop5_4)
  229. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "5:4");
  230. else if (action == m__crop1_1)
  231. libvlc_video_set_crop_geometry(vlc_mediaPlayer, "1:1");
  232. action->setIcon(QIcon(":/image/images/point.png"));
  233. m_preCrop->setIcon(QIcon());
  234. m_preCrop = action;
  235. }
  236. void showWidget::slotScaleActionTriggered(QAction *action)
  237. {
  238. if (!vlc_mediaPlayer)
  239. return;
  240. if (action == m_scale1_4)
  241. libvlc_video_set_scale(vlc_mediaPlayer, 0.25);
  242. else if (action == m_scale1_2)
  243. libvlc_video_set_scale(vlc_mediaPlayer, 0.5);
  244. else if (action == m_scale1_1)
  245. libvlc_video_set_scale(vlc_mediaPlayer, 1);
  246. else if (action == m_scale2_1)
  247. libvlc_video_set_scale(vlc_mediaPlayer, 2);
  248. action->setIcon(QIcon(":/image/images/point.png"));
  249. m_preScale->setIcon(QIcon());
  250. m_preScale = action;
  251. }
  252. void showWidget::slotSnap()
  253. {
  254. if (vlc_mediaPlayer)
  255. {
  256. QString path = "./snap.png";
  257. libvlc_video_take_snapshot(vlc_mediaPlayer, 0, path.toUtf8().data(), 0, 0);
  258. }
  259. }
  260. //事件回调
  261. void showWidget::vlcEvents(const libvlc_event_t *ev, void *param)
  262. {
  263. showWidget *w = (showWidget*)param;
  264. //处理不同的事件
  265. switch (ev->type) {
  266. case libvlc_MediaPlayerTimeChanged:
  267. {
  268. //qDebug() << "VLC媒体播放器时间已更改";
  269. qint64 len = libvlc_media_player_get_time(w->vlc_mediaPlayer);
  270. libvlc_time_t lenSec = len / 1000;
  271. libvlc_time_t totalLen = libvlc_media_player_get_length(w->vlc_mediaPlayer);
  272. libvlc_time_t totalLenSec = totalLen / 1000;
  273. int thh, tmm, tss;
  274. thh = lenSec / 3600;
  275. tmm = (lenSec % 3600) / 60;
  276. tss = (lenSec % 60);
  277. QTime time(thh, tmm, tss);
  278. w->ui.lbCurTime->setText(time.toString("hh:mm:ss"));
  279. thh = totalLenSec / 3600;
  280. tmm = (totalLenSec % 3600) / 60;
  281. tss = (totalLenSec % 60);
  282. QTime TotalTime(thh, tmm, tss);
  283. w->ui.lbTotalTime->setText(TotalTime.toString("hh:mm:ss"));
  284. double pos = (double)lenSec / totalLenSec * 100;
  285. w->ui.horizontalSlider->setValue(pos);
  286. }
  287. break;
  288. case libvlc_MediaPlayerEndReached:
  289. qDebug() << "VLC播放完毕.";
  290. break;
  291. case libvlc_MediaPlayerStopped:
  292. qDebug() << "VLC停止播放";
  293. break;
  294. case libvlc_MediaPlayerPlaying:
  295. qDebug() << "VLC开始播放";
  296. break;
  297. case libvlc_MediaPlayerPaused:
  298. qDebug() << "VLC暂停播放";
  299. break;
  300. }
  301. }
  302. void showWidget::initMenu()
  303. {
  304. //总菜单
  305. m_menu = new QMenu(this);
  306. m_video = m_menu->addAction("视频");
  307. //视频菜单
  308. m_videoMenu = new QMenu(this);
  309. m_scaleAction = m_videoMenu->addAction("缩放");
  310. m_aspectRatioAction = m_videoMenu->addAction("宽高比");
  311. m_cropAction = m_videoMenu->addAction("裁剪");
  312. m_snapAction = m_videoMenu->addAction("截图");
  313. connect(m_snapAction, &QAction::triggered, this, &showWidget::slotSnap);
  314. m_video->setMenu(m_videoMenu);
  315. //宽高比菜单
  316. m_aspectRatioMenu = new QMenu(this);
  317. m_aspectRatioAction->setMenu(m_aspectRatioMenu);
  318. //设置宽高比菜单
  319. m_default = m_aspectRatioMenu->addAction(QIcon(":/image/images/point.png"), "默认");
  320. m_16_9 = m_aspectRatioMenu->addAction("16:9");
  321. m_4_3 = m_aspectRatioMenu->addAction("4:3");
  322. m_1_1 = m_aspectRatioMenu->addAction("1:1");
  323. m_16_10 = m_aspectRatioMenu->addAction("16:10");
  324. m_2_21_1 = m_aspectRatioMenu->addAction("2.21:1");
  325. m_2_35_1 = m_aspectRatioMenu->addAction("2.35:1");
  326. m_2_38_1 = m_aspectRatioMenu->addAction("2.38:1");
  327. m_5_4 = m_aspectRatioMenu->addAction("5:4");
  328. m_preAspectRatio = m_default;
  329. m_group = new QActionGroup(this);
  330. m_group->addAction(m_default);
  331. m_group->addAction(m_16_9);
  332. m_group->addAction(m_4_3);
  333. m_group->addAction(m_1_1);
  334. m_group->addAction(m_16_10);
  335. m_group->addAction(m_2_21_1);
  336. m_group->addAction(m_2_35_1);
  337. m_group->addAction(m_2_38_1);
  338. m_group->addAction(m_5_4);
  339. connect(m_group, &QActionGroup::triggered, this, &showWidget::slotActionTriggered);
  340. //设置裁剪菜单
  341. m_cropMenu = new QMenu(this);
  342. m_cropAction->setMenu(m_cropMenu);
  343. m__cropDefault = m_cropMenu->addAction(QIcon(":/image/images/point.png"), "默认");
  344. m__crop16_10 = m_cropMenu->addAction("16:10");
  345. m__crop16_9 = m_cropMenu->addAction("16:9");
  346. m__crop4_3 = m_cropMenu->addAction("4:3");
  347. m__crop1_85_1 = m_cropMenu->addAction("1.85:1");
  348. m__crop2_21_1 = m_cropMenu->addAction("2.21:1");
  349. m__crop2_35_1 = m_cropMenu->addAction("2.35:1");
  350. m__crop2_39_1 = m_cropMenu->addAction("2.39:1");
  351. m__crop5_3 = m_cropMenu->addAction("5:3");
  352. m__crop5_4 = m_cropMenu->addAction("5:4");
  353. m__crop1_1 = m_cropMenu->addAction("1:1");
  354. m_preCrop = m__cropDefault;
  355. m_cropGroup = new QActionGroup(this);
  356. m_cropGroup->addAction(m__cropDefault);
  357. m_cropGroup->addAction(m__crop16_10);
  358. m_cropGroup->addAction(m__crop16_9);
  359. m_cropGroup->addAction(m__crop4_3);
  360. m_cropGroup->addAction(m__crop1_85_1);
  361. m_cropGroup->addAction(m__crop2_21_1);
  362. m_cropGroup->addAction(m__crop2_35_1);
  363. m_cropGroup->addAction(m__crop2_39_1);
  364. m_cropGroup->addAction(m__crop5_3);
  365. m_cropGroup->addAction(m__crop5_4);
  366. m_cropGroup->addAction(m__crop1_1);
  367. connect(m_cropGroup, &QActionGroup::triggered, this, &showWidget::slotCropActionTriggered);
  368. //设置缩放菜单
  369. m_scaleMenu = new QMenu(this);
  370. m_scaleAction->setMenu(m_scaleMenu);
  371. m_scale1_4 = m_scaleMenu->addAction("1:4 四分之一");
  372. m_scale1_2 = m_scaleMenu->addAction("1:2 二分之一");
  373. m_scale1_1 = m_scaleMenu->addAction(QIcon(":/image/images/point.png"),"1:1 原始");
  374. m_scale2_1 = m_scaleMenu->addAction("2:1 双倍");
  375. m_scaleGroup = new QActionGroup(this);
  376. m_scaleGroup->addAction(m_scale1_4);
  377. m_scaleGroup->addAction(m_scale1_2);
  378. m_scaleGroup->addAction(m_scale1_1);
  379. m_scaleGroup->addAction(m_scale2_1);
  380. m_preScale = m_scale1_1;
  381. connect(m_scaleGroup, &QActionGroup::triggered, this, &showWidget::slotScaleActionTriggered);
  382. }

更多参考:

libVLC 事件机制-CSDN博客

libVLC windows开发环境搭建-CSDN博客

https://sunnnnnn666.blog.csdn.net/article/details/137023036

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/329315?site
推荐阅读
相关标签
  

闽ICP备14008679号