功能:本软件实现了视频播放器的一些基本功能:视频录制,截图,快进,快退,播放,暂停,停止,全屏,转发。
工作中遇到利用vlc制作视频播放器,推送码流的工作,因此先制作了个demo,借鉴了很多大佬的作品进行整合,虽然学习了部分vlc库的代码,勉强算得上原创。
制作带录制功能的vlc视频播放器需要将vlc补上部分代码再编译,小白直接下载大佬编译好的vlc库就好(我现在官方源码还不支持录制功能,大概)。
官方vlc库(找到最新的选带.7z 后缀的下载):http://download.videolan.org/pub/videolan/vlc/
大佬编译好的带录制功能的vlc库:https://download.csdn.net/download/avsuper/9919212
我用的vc++编的,少stdint.h文件和inttypes.h文件:下载地址
推流可以借鉴雷神的几篇文章:https://blog.csdn.net/leixiaohua1020/article/details/42363701?utm_source=app&app_version=4.5.2
全屏被卡了一段时间,后来根据这个博客做了出来:http://blog.jianchihu.net/player-based-on-libvlc.html
主要框架仿照这位大佬做的:https://blog.csdn.net/hopeless123/article/details/79715298?utm_source=app&app_version=4.5.2
场外求助人员介绍完了,再介绍一下步骤:
将下载的vlc库导入程序(注意下载官方库的时候要下载这种格式的,想要有录制功能就按我给的另一个大佬的库链接下载):
下载好的vlc库如图:
将plugins文件夹和libvlc.dll与libvlccore.dll导入程序的debug下(别的路径也行,但是需要在程序里配置出路径,debug默认路径不用配置):
将sdk里面的lib和include文件夹拷到程序文件夹下:
到这里为止,已经将开发用的vlc库完全导入程序文件夹下了。
如图点击c/c++,点击最上方的下拉框选择最下面的选项,填入.h文件的路径 include,include\vlc:
如图点击Link,点击最上方的下拉框选择Input,填入lib文件的路径 lib :
再填上引用的lib,libvlc.lib libvlccore.lib :
到此为止环境配置完毕,只差代码:
void CVlcVideoDlg::OnButton1()
{
// TODO: Add your control notification handler code here
//开始录制视频
libvlc_media_player_recorder_start(m_showPlayer,"F:\\school.flv");
}
void CVlcVideoDlg::OnButton2()
{
// TODO: Add your control notification handler code here
//结束录制视频
libvlc_media_player_recorder_stop(m_showPlayer);
}
void CVlcVideoDlg::OnStaticPic()
{
// TODO: Add your control notification handler code here
OnButton9();
}
void CVlcVideoDlg::OnButton3()
{
// TODO: Add your control notification handler code here
//播放视频/暂停视频
if(m_showPlayer!=NULL)
{
if(libvlc_media_player_can_pause(m_showPlayer))
{
libvlc_media_player_pause(m_showPlayer);
}
}
}
void CVlcVideoDlg::OnButton4()
{
// TODO: Add your control notification handler code here
//停止视频
if(m_showPlayer!=NULL)
{
libvlc_media_player_stop(m_showPlayer);
}
}
void CVlcVideoDlg::OnButton5()
{
// TODO: Add your control notification handler code here
//快进视频
if(m_showPlayer!=NULL)
{
__int64 time;
__int64 changeTime=3000; //变动的时间
if(libvlc_media_player_is_seekable(m_showPlayer))
{
time = libvlc_media_player_get_time(m_showPlayer);
if (time == -1)
{
return;
}
libvlc_media_player_set_time(m_showPlayer,time + changeTime);
}
}
}
void CVlcVideoDlg::OnButton6()
{
// TODO: Add your control notification handler code here
//快退视频
if(m_showPlayer!=NULL)
{
__int64 time;
__int64 changeTime=3000; //变动的时间
if(libvlc_media_player_is_seekable(m_showPlayer))
{
time = libvlc_media_player_get_time(m_showPlayer);
if (time == -1)
{
return;
}
libvlc_media_player_set_time(m_showPlayer, time - changeTime);
}
}
}
void CVlcVideoDlg::OnButton7()
{
// TODO: Add your control notification handler code here
//截图
if(m_showPlayer!=NULL)
{
libvlc_video_take_snapshot(m_showPlayer, 0, "F://333.jpg", 0, 0);
}
}
void CVlcVideoDlg::OnButton8()
{
// TODO: Add your control notification handler code here
libvlc_media_t *media=NULL;
if(m_showPlayer!=NULL)
{
media = libvlc_media_player_get_media(m_showPlayer);
}
}
void CVlcVideoDlg::OnButton9()
{
// TODO: Add your control notification handler code here
//全屏
if(m_showPlayer!=NULL)
{
m_bIsFullScreen=!m_bIsFullScreen;
// libvlc_media_player_set_hwnd(m_showPlayer,::GetDesktopWindow());
// libvlc_set_fullscreen(m_showPlayer, true);
SetFullScreen(m_bIsFullScreen);
}
}
void CVlcVideoDlg::SetFullScreen(BOOL full)
{
if (full)
{
HideControl(TRUE);
//隐藏标题栏
SetWindowLong(GetSafeHwnd(), GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) - WS_CAPTION);
ShowWindow(SW_MAXIMIZE);
CRect rc;
GetClientRect(&rc);
m_pic.MoveWindow(rc);
}
else
{
HideControl(FALSE);
SetWindowLong(this->GetSafeHwnd(), GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) + WS_CAPTION);
ShowWindow(SW_NORMAL);
CRect rc;
GetClientRect(&rc);
rc.DeflateRect(0, 0, 0, 150);
m_pic.MoveWindow(rc);
}
}
void CVlcVideoDlg::HideControl(BOOL isHide)
{
}
void CVlcVideoDlg::OnButton10()
{
// TODO: Add your control notification handler code here
if(m_showPlayer!=NULL)
{
libvlc_media_player_stop(m_showPlayer);
}
}
void CVlcVideoDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//鼠标双击m_pic(一个picture frame,充当vlc视频播放器的窗口句柄)
if (m_showPlayer!=NULL)
{
m_bIsFullScreen=!m_bIsFullScreen;
SetFullScreen(m_bIsFullScreen);
}
CDialog::OnLButtonDblClk(nFlags, point);
}
vlc视频播放器不算难,就是需要花点时间了解配置和一些函数,如果要深造还有学习一些参数的使用。制作不易,希望用到的小伙伴评论加点赞,让我知道自己帮助到了人,呜呼。