3.根据监控点或者视频的分辨率自适应调整播放画面的宽高比
视频的分辨率宽高比和播放窗口的宽高比例不一定相同,播放时如果填充整个播放窗口,会出现播放画面横向或纵向拉伸以填充整个窗口,这样会导致播放画面变形或者不协调,影响观看效果;为了保持视频的按照原来的宽高比,可以根据视频的分辨率的宽高比调整播放画面的宽高比,这样就保证画面不变形拉伸;
实现思路,用两个widget,外层widgetPlayContain,内层widgetPlay是播放画面,用widgetPlayContain的布局layout的边距去控制中间widgetPlay的宽高比和视频分辨率宽高比相同,这样可能是左右有边距,上下无边距,或者上下有边距,左右无边距
void PlayWnd::ResizePlayWndByResolution()
{if (m_pHandle == NULL || m_PlayState != PLAYING){ui.vLayoutPlayContain->setContentsMargins(0, 0, 0, 0);return;}if (CLocalSystemConfigManager::Instance().GetInformationDisplayConfig().image_display==OriginalResolution){playsdk::ResolutionParam reso;int ret = GetResoution(m_pHandle, reso);if (ret == 0){QSize widgetSize = ui.widgetPlayContain->size();//用窗口的高度按照分辨率的比例算出宽度int width = widgetSize.height()*reso.iWidth / reso.iHeight;if (width > widgetSize.width())//宽度不够,按照窗口最大宽度填充,缩小高度,上下有边距
{//根据宽度计算出播放窗口高度int height = widgetSize.width()*reso.iHeight / reso.iWidth;int updownmargin = (widgetSize.height() - height) / 2;ui.vLayoutPlayContain->setContentsMargins(0, updownmargin, 0, updownmargin);}else//宽度够,按照窗口最大高度填充,高度已知,宽度缩小,左右有边距
{int width = widgetSize.height()*reso.iWidth / reso.iHeight;int leftrightMargin = (widgetSize.width() - width) / 2;ui.vLayoutPlayContain->setContentsMargins(leftrightMargin, 0, leftrightMargin, 0);}}else{LOG_ERROR("GetResoution failed %d", ret);}}else{ui.vLayoutPlayContain->setContentsMargins(0, 0, 0, 0);}}