视频黑屏画面检测 blackframe

ffmpeg的blackframe实现视频黑场画面检测

1 参数简介

  • amount:
    设置黑场的判断阈值,高于此阈值的认为此帧为黑场,该值为一个百分比。默认值98。
  • threshold, thresh:
    设置黑场像素的判断阈值,低于此阈值的像素认为是黑场像素点。默认值32。

2 测试命令

ffmpeg -loglevel info  -i ~/test.mp4  -vf blackframe=95:30 -f null -

3 测试效果

部分检测结果日志如下

[Parsed_blackframe_0 @ 0x7f9f608229c0] frame:1081 pblack:97 pts:693120 t:43.320000 type:P last_keyframe:934
[Parsed_blackframe_0 @ 0x7f9f608229c0] frame:1082 pblack:97 pts:693760 t:43.360000 type:P last_keyframe:934
[Parsed_blackframe_0 @ 0x7f9f608229c0] frame:1083 pblack:97 pts:694400 t:43.400000 type:P last_keyframe:934
[Parsed_blackframe_0 @ 0x7f9f608229c0] frame:1084 pblack:97 pts:695040 t:43.440000 type:I last_keyframe:1084
[Parsed_blackframe_0 @ 0x7f9f608229c0] frame:1085 pblack:97 pts:695680 t:43.480000 type:B last_keyframe:1084
[Parsed_blackframe_0 @ 0x7f9f608229c0] frame:1086 pblack:97 pts:696320 t:43.520000 type:B last_keyframe:1084
[Parsed_blackframe_0 @ 0x7f9f608229c0] frame:1087 pblack:97 pts:696960 t:43.560000 type:B last_keyframe:1084
[Parsed_blackframe_0 @ 0x7f9f608229c0] frame:1088 pblack:97 pts:697600 t:43.600000 type:B last_keyframe:1084

输出信息包含:帧id、画面黑屏程度、时间戳、帧类型、当前gop的idr帧的位置;

4 官方参考

http://ffmpeg.org/ffmpeg-all.html#blackframe

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,需要在对话框上添加一个静态控件(CStatic),用于绘制柱状图。 操作步骤: 1. 打开 MFC 应用程序项目,创建一个对话框应用程序。 2. 在对话框上添加一个静态控件,并设置控件属性为黑色背景和白色边框。 3. 在对话框类中添加一个成员函数 DrawGraph(),用于绘制柱状图。 4. 在 OnInitDialog() 函数中调用 DrawGraph() 函数,实现初始化时的绘制。 5. 在对话框类中添加一个成员变量,用于存储商品收入数据。 6. 在 OnInitDialog() 函数中初始化商品收入数据。 7. 在 DrawGraph() 函数中使用商品收入数据绘制柱状图。 以下是完整的代码示例: 在对话框类的头文件中添加以下代码: ```cpp #include <vector> using namespace std; class CMyDlg : public CDialogEx { public: CMyDlg(CWnd* pParent = nullptr); // 标准构造函数 virtual ~CMyDlg(); enum { IDD = IDD_MY_DIALOG }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 virtual BOOL OnInitDialog(); afx_msg void OnPaint(); DECLARE_MESSAGE_MAP() private: CStatic m_stcGraph; // 静态控件 vector<pair<CString, int>> m_vecData; // 商品收入数据 void DrawGraph(); // 绘制柱状图 }; ``` 在对话框类的源文件中添加以下代码: ```cpp #include "stdafx.h" #include "MyApp.h" #include "MyDlg.h" #include "afxdialogex.h" #include <algorithm> #ifdef _DEBUG #define new DEBUG_NEW #endif CMyDlg::CMyDlg(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_MY_DIALOG, pParent) { } CMyDlg::~CMyDlg() { } void CMyDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_STATIC_GRAPH, m_stcGraph); } BEGIN_MESSAGE_MAP(CMyDlg, CDialogEx) ON_WM_PAINT() END_MESSAGE_MAP() BOOL CMyDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // 初始化商品收入数据 m_vecData.push_back(make_pair(_T("苹果"), 20)); m_vecData.push_back(make_pair(_T("香蕉"), 23)); m_vecData.push_back(make_pair(_T("梨"), 13)); // 绘制柱状图 DrawGraph(); return TRUE; } void CMyDlg::OnPaint() { CPaintDC dc(this); // 用于绘制的设备上下文 // 绘制静态控件的边框 CRect rect; m_stcGraph.GetWindowRect(&rect); ScreenToClient(&rect); dc.DrawEdge(rect, EDGE_RAISED, BF_RECT); // 绘制柱状图 DrawGraph(); } void CMyDlg::DrawGraph() { // 获取静态控件的客户区大小 CRect rect; m_stcGraph.GetClientRect(&rect); // 计算柱状图的位置和大小 const int nMargin = 10; // 边距 const int nBarWidth = 20; // 柱状图宽度 const int nMaxValue = 30; // 最大值 int nBarHeight = 0; int nBarLeft = nMargin; int nBarTop = nMargin; int nBarRight = nBarLeft + nBarWidth; int nBarBottom = rect.Height() - nMargin; int nXAxisLeft = nBarRight + nMargin; int nXAxisTop = nBarBottom; int nXAxisRight = rect.Width() - nMargin; int nXAxisBottom = nBarBottom + nMargin; int nYAxisLeft = nBarLeft; int nYAxisTop = nBarTop; int nYAxisRight = nXAxisLeft; int nYAxisBottom = nBarBottom; int nYAxisInterval = nMaxValue / 5; // 绘制 Y 轴 CPen pen(PS_SOLID, 2, RGB(0, 0, 0)); CPen* pOldPen = dc.SelectObject(&pen); for (int i = 0; i <= nMaxValue; i += nYAxisInterval) { nBarHeight = (nBarBottom - nBarTop) * i / nMaxValue; dc.MoveTo(nYAxisRight, nBarBottom - nBarHeight); dc.LineTo(nYAxisLeft, nBarBottom - nBarHeight); } dc.SelectObject(pOldPen); // 绘制 X 轴 dc.MoveTo(nXAxisLeft, nXAxisTop); dc.LineTo(nXAxisRight, nXAxisTop); // 绘制柱状图 const int nTotalBars = static_cast<int>(m_vecData.size()); for (int i = 0; i < nTotalBars; ++i) { nBarHeight = (nBarBottom - nBarTop) * m_vecData[i].second / nMaxValue; dc.Rectangle(nBarLeft, nBarBottom - nBarHeight, nBarRight, nBarBottom); nBarLeft += nBarWidth + nMargin; nBarRight += nBarWidth + nMargin; } } ``` 在资源文件中添加以下代码: ```xml IDD_MY_DIALOG DIALOGEX 0, 0, 250, 150 STYLE WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME | DS_CENTER | DS_SHELLFONT CAPTION "MyApp" FONT 8, "MS Shell Dlg", 0, 0, 0x0 BEGIN LTEXT "商品收入柱状图", IDC_STATIC, 80, 10, 95, 14 CONTROL " ", IDC_STATIC_GRAPH, "Static", SS_BLACKFRAME | SS_NOTIFY, 10, 30, 230, 100 END ``` 编译并运行程序,即可看到如下的柱状图: ![柱状图](https://img-blog.csdnimg.cn/2022030217070375.png)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值