EasyPlayerPro Windows播放器电子放大/局部放大播放功能实现

背景描述

在视频监控软件中,我们看到很多的软件都有电子放大功能, 按住鼠标左键不放,框选一个区域,再松开鼠标左键,即对选中的区域进行放大显示, 且可以重复该操作,逐步放大所需显示的区域, 有没有觉得,这个功能在视频监控软件中还是有他的用武地. 今天我们就来实现该功能;

EasyPlayerPro

实现流程

//设置电子放大起起始点
int		SetElectronicZoomStartPoint(int channelId, float fXPercent, float fYPercent, unsigned char showBox);
//设置电子放大结束点(在鼠标移动过程中可一直调用该函数)
int		SetElectronicZoomEndPoint(int channelId, float fXPercent, float fYPercent);
//设置是否放大显示
int		SetElectronicZoom(int channelId, int zoomIn);
//复位
void	ResetElectronicZoom(int channelId);
//直接设置显示区域,用于电子放大, 在某些场合, 需要直接进行缩放显示, 即可调用该函数实现
int		SetRenderRect(int channelId, LPRECT lpSrcRect);

EasyPlayerPro

##代码实现

int	ChannelManager::ElectronicZoomProcess(MEDIA_VIDEO_CHANNEL_OBJ_T *pMediaChannel, EASY_FRAME_INFO *frameInfo)
{
if (NULL == pMediaChannel)				return 0;
if (NULL == frameInfo)					return 0;

ELECTRONIC_ZOOM_T *pElectoricZoom = pMediaChannel->pElectoricZoom;
if (NULL == pElectoricZoom)				return 0;

int nLeft = 0, nTop = 0, nRight = 0, nBottom = 0;
if (pElectoricZoom->zoomIn >= 0x01)
{
	RECT rcClient;
	GetClientRect(pMediaChannel->mediaDisplay.hWnd, &rcClient);

	float fLeftPercent =	pElectoricZoom->fStartPointX;
	float fTopPercent  =	pElectoricZoom->fStartPointY;
	float fRightPercent =	pElectoricZoom->fEndPointX;
	float fBottomPercent  = pElectoricZoom->fEndPointY;

	if (fRightPercent > fLeftPercent && fBottomPercent > fTopPercent)				//逐步放大
	{
		if (pElectoricZoom->fVideoWidth > 0)
		{
			int video_width = (int)pElectoricZoom->fVideoWidth;
			int video_height= (int)pElectoricZoom->fVideoHeight;
			nLeft = (int)((float)video_width / 100.0f * fLeftPercent);
			nTop  = (int)((float)video_height/ 100.0f * fTopPercent);
			nRight = (int)((float)video_width / 100.0f * fRightPercent);
			nBottom  = (int)((float)video_height/ 100.0f * fBottomPercent);

			if (nRight > nLeft && nBottom > nTop)
			{
				pElectoricZoom->fVideoWidth = (float)(nRight - nLeft);
				pElectoricZoom->fVideoHeight = (float)(nBottom - nTop);

				nLeft = pElectoricZoom->startVideoLeft + nLeft;
				nTop = pElectoricZoom->startVideoTop + nTop;
				nRight = pElectoricZoom->startVideoLeft + nRight;
				nBottom = pElectoricZoom->startVideoTop + nBottom;

				pElectoricZoom->startVideoLeft = nLeft;
				pElectoricZoom->startVideoTop = nTop;

				if (pElectoricZoom->zoomIndex + 1 <MAX_ZOOM_IN_TIMES)
				{
					SetRect(&pElectoricZoom->zoomParam[pElectoricZoom->zoomIndex].rect, nLeft, nTop, nRight, nBottom);
					pElectoricZoom->zoomParam[pElectoricZoom->zoomIndex].fVideoWidth = pElectoricZoom->fVideoWidth;
					pElectoricZoom->zoomParam[pElectoricZoom->zoomIndex].fVideoHeight = pElectoricZoom->fVideoHeight;
					pElectoricZoom->zoomParam[pElectoricZoom->zoomIndex].startVideoLeft = pElectoricZoom->startVideoLeft;
					pElectoricZoom->zoomParam[pElectoricZoom->zoomIndex].startVideoTop = pElectoricZoom->startVideoTop;
					pElectoricZoom->zoomIndex ++;
				}
			}
			else
			{
				int idx = pElectoricZoom->zoomIndex-2;
				if (idx > 0)
				{
					nLeft = pElectoricZoom->zoomParam[idx].rect.left;
					nTop = pElectoricZoom->zoomParam[idx].rect.top;
					nRight = pElectoricZoom->zoomParam[idx].rect.right;
					nBottom = pElectoricZoom->zoomParam[idx].rect.bottom;

					pElectoricZoom->fVideoWidth = pElectoricZoom->zoomParam[idx].fVideoWidth;
					pElectoricZoom->fVideoHeight = pElectoricZoom->zoomParam[idx].fVideoHeight;
					pElectoricZoom->startVideoLeft = pElectoricZoom->zoomParam[idx].startVideoLeft;
					pElectoricZoom->startVideoTop = pElectoricZoom->zoomParam[idx].startVideoTop;
				}
			}
		}
		else
		{
			int video_width = frameInfo->width;
			int video_height= frameInfo->height;
			nLeft = (int)((float)video_width / 100.0f * fLeftPercent);
			nTop  = (int)((float)video_height/ 100.0f * fTopPercent);
			nRight = (int)((float)video_width / 100.0f * fRightPercent);
			nBottom  = (int)((float)video_height/ 100.0f * fBottomPercent);

			pElectoricZoom->startVideoLeft = nLeft;
			pElectoricZoom->startVideoTop = nTop;
			pElectoricZoom->fVideoWidth = (float)(nRight - nLeft);
			pElectoricZoom->fVideoHeight = (float)(nBottom - nTop);

			SetRect(&pElectoricZoom->zoomParam[0].rect, nLeft, nTop, nRight, nBottom);
			pElectoricZoom->zoomParam[0].fVideoWidth = pElectoricZoom->fVideoWidth;
			pElectoricZoom->zoomParam[0].fVideoHeight = pElectoricZoom->fVideoHeight;
			pElectoricZoom->zoomParam[0].startVideoLeft = pElectoricZoom->startVideoLeft;
			pElectoricZoom->zoomParam[0].startVideoTop = pElectoricZoom->startVideoTop;
			pElectoricZoom->zoomIndex ++;
		}
	}
	else
	{
		if (pElectoricZoom->zoomIndex > 1)
		{
			int idx = pElectoricZoom->zoomIndex-2;

			nLeft = pElectoricZoom->zoomParam[idx].rect.left;
			nTop = pElectoricZoom->zoomParam[idx].rect.top;
			nRight = pElectoricZoom->zoomParam[idx].rect.right;
			nBottom = pElectoricZoom->zoomParam[idx].rect.bottom;

			pElectoricZoom->fVideoWidth = pElectoricZoom->zoomParam[idx].fVideoWidth;
			pElectoricZoom->fVideoHeight = pElectoricZoom->zoomParam[idx].fVideoHeight;
			pElectoricZoom->startVideoLeft = pElectoricZoom->zoomParam[idx].startVideoLeft;
			pElectoricZoom->startVideoTop = pElectoricZoom->zoomParam[idx].startVideoTop;

			pElectoricZoom->zoomIndex --;
		}
		else
		{
			pElectoricZoom->fVideoWidth = 0.0f;

			nLeft = 0;
			nTop = 0;
			nRight = frameInfo->width;
			nBottom = frameInfo->height;

			pElectoricZoom->zoomIndex = 0;
		}
	}


	RECT rcSrc;
	SetRect(&rcSrc, nLeft, nTop, nRight, nBottom);
	CopyRect(&pMediaChannel->mediaDisplay.rcSrcRender, &rcSrc);

	pElectoricZoom->zoomIn --;
}

return 0;
}

关于EasyPlayerPro

EasyPlayerPro是一款全功能的流媒体播放器,支持RTSP、RTMP、HTTP、HLS、UDP、RTP、File等多种流媒体协议播放、支持本地文件播放,支持本地抓拍、本地录像、播放旋转、多屏播放、倍数播放等多种功能特性,核心基于ffmpeg,稳定、高效、可靠、可控,支持Windows、Android、iOS三个平台,目前在多家教育、安防、行业型公司,都得到的应用,广受好评!

EasyPlayerPro:https://github.com/EasyDSS/EasyPlayerPro

点击链接加入群【EasyPlayer & EasyPlayerPro】:544917793

技术支持

EasyPlayerPro是一款非常稳定的全协议/全功能播放器组件,各平台版本需要经过授权才能商业使用,商业授权方案可以通过以上渠道进行更深入的技术与合作咨询;

获取更多信息

EasyDarwin开源流媒体服务器:www.EasyDarwin.org

EasyDSS商用流媒体解决方案:www.EasyDSS.com

EasyNVR无插件直播方案:www.EasyNVR.com

Copyright © EasyDarwin Team 2012-2017

EasyDarwin

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值