当前位置:   article > 正文

libVLC 视频缩放

libVLC 视频缩放

libvlc是一个常用的开源多媒体框架,它可以用来播放和处理各种类型的音频和视频文件。如果想要缩放视频,可以通过libvlc提供的API来实现。

  1. //设置视频的缩放比例。
  2. libvlc_video_set_scale()

以下是如何使用 libVLC 设置视频缩放的基本步骤:

  1. #include <vlc/vlc.h>
  2. int main(int argc, char* argv[]) {
  3. libvlc_instance_t *vlcInstance;
  4. libvlc_media_player_t *mediaPlayer;
  5. libvlc_media_t *media;
  6. // 初始化 libVLC
  7. vlcInstance = libvlc_new(0, NULL);
  8. // 创建一个媒体对象
  9. media = libvlc_media_new_path(vlcInstance, "path_to_your_video_file.mp4");
  10. // 创建一个媒体播放器
  11. mediaPlayer = libvlc_media_player_new_from_media(media);
  12. // 设置视频缩放选项
  13. libvlc_video_set_scale(mediaPlayer, 0.5); // 缩放比例为 0.5,即将视频缩小一半
  14. // 设置视频输出窗口
  15. libvlc_media_player_set_hwnd(mediaPlayer, (void*)your_window_handle);
  16. // 播放视频
  17. libvlc_media_player_play(mediaPlayer);
  18. // 等待用户输入
  19. getchar();
  20. // 释放资源
  21. libvlc_media_player_release(mediaPlayer);
  22. libvlc_media_release(media);
  23. libvlc_release(vlcInstance);
  24. return 0;
  25. }

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

以下是做出来的效果图。

首先做缩放菜单: 

  1. //.h
  2. //缩放
  3. QMenu *m_scaleMenu = nullptr;
  4. QAction *m_scale1_4 = nullptr;
  5. QAction *m_scale1_2 = nullptr;
  6. QAction *m_scale1_1 = nullptr;
  7. QAction *m_scale2_1 = nullptr;
  8. QActionGroup *m_scaleGroup = nullptr;
  9. QAction *m_preScale = nullptr;
  10. //.cpp
  11. //设置缩放菜单
  12. m_scaleMenu = new QMenu(this);
  13. m_scaleAction->setMenu(m_scaleMenu);
  14. m_scale1_4 = m_scaleMenu->addAction("1:4 四分之一");
  15. m_scale1_2 = m_scaleMenu->addAction("1:2 二分之一");
  16. m_scale1_1 = m_scaleMenu->addAction(QIcon(":/image/images/point.png"),"1:1 原始");
  17. m_scale2_1 = m_scaleMenu->addAction("2:1 双倍");
  18. m_scaleGroup = new QActionGroup(this);
  19. m_scaleGroup->addAction(m_scale1_4);
  20. m_scaleGroup->addAction(m_scale1_2);
  21. m_scaleGroup->addAction(m_scale1_1);
  22. m_scaleGroup->addAction(m_scale2_1);
  23. m_preScale = m_scale1_1;
  24. connect(m_scaleGroup, &QActionGroup::triggered, this, &showWidget::slotScaleActionTriggered);

接受槽函数的响应事件:

  1. void showWidget::slotScaleActionTriggered(QAction *action)
  2. {
  3. if (!vlc_mediaPlayer)
  4. return;
  5. if (action == m_scale1_4)
  6. libvlc_video_set_scale(vlc_mediaPlayer, 0.25);
  7. else if (action == m_scale1_2)
  8. libvlc_video_set_scale(vlc_mediaPlayer, 0.5);
  9. else if (action == m_scale1_1)
  10. libvlc_video_set_scale(vlc_mediaPlayer, 1);
  11. else if (action == m_scale2_1)
  12. libvlc_video_set_scale(vlc_mediaPlayer, 2);
  13. action->setIcon(QIcon(":/image/images/point.png"));
  14. m_preScale->setIcon(QIcon());
  15. m_preScale = action;
  16. }

设置鼠标右键弹出菜单:重写鼠标点击事件,弹出菜单。

首先设置libvlc忽略鼠标事件libvlc_video_set_mouse_input(vlc_mediaPlayer, 0);

再重写鼠标事件:

  1. void showWidget::mousePressEvent(QMouseEvent *event)
  2. {
  3.     switch (event->button())
  4.     {
  5.     case Qt::RightButton:
  6.         //this->setWindowState(Qt::WindowMinimized);
  7.         m_menu->exec(event->globalPos());
  8.         break;
  9.     default:
  10.         QWidget::mousePressEvent(event);
  11.     }
  12. }

完整代码:

头文件。

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

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

更多参考:

libVLC 事件机制-CSDN博客

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

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

libVLC 元数据-CSDN博客

libVLC 添加图片和文本水印-CSDN博客

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

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

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

闽ICP备14008679号