From 58fb30ef039c2eb79044cdaa80e21faa5dd9c246 Mon Sep 17 00:00:00 2001 From: Tabing010102 <897309345@qq.com> Date: Fri, 4 Sep 2020 17:22:12 +0800 Subject: [PATCH] add config file and modify default behaviour --- README.md | 36 +++++++++++++++++++++++++++++++ inc/SampleGrabberCallback.h | 2 ++ inc/common.h | 3 +++ src/Main.cpp | 4 ++-- src/SampleGrabberCallback.cpp | 40 ++++++++++++++++++++++++++++++++++- src/common.cpp | 10 +++++++++ 6 files changed, 92 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fd51e6c..69c5c2d 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,42 @@ |[![Build status](https://ci.appveyor.com/api/projects/status/opebwjf0j8ssiq2j/branch/master?svg=true)](https://ci.appveyor.com/project/5455945/videocapture/branch/master)| +一点说明 +--- +默认点一下截图一张 + +粗暴实现配置文件以及输出到文件夹,请确保文件夹存在并可写 + +配置文件fstream读,输出暴力copy,在%temp%\CaptureBmp\的文件不动 + +vs2019 v142编译 + +release已经在64位win7以及win10 2004测试 + +cmake未测试 + + +配置文件 +--- +配置文件为程序目录下的config文件(没有扩展名) + +共4行 + +第一行为输出目录(不带\) + +第二到四行每行分别有一个整数1或0 + +分别表示是否输出bmp、jpg、png文件 + +示例(输出到D:\Temp目录下,仅输出jpg文件): +``` +D:\Temp +0 +1 +0 +``` + + 传统方式编译 --- Windows Video Audio Capture, Save BMP file diff --git a/inc/SampleGrabberCallback.h b/inc/SampleGrabberCallback.h index 0489d9e..6da548f 100644 --- a/inc/SampleGrabberCallback.h +++ b/inc/SampleGrabberCallback.h @@ -22,6 +22,8 @@ class SampleGrabberCallback : public ISampleGrabberCB TCHAR m_chTempPath[MAX_PATH]; TCHAR m_chSwapStr[MAX_PATH]; TCHAR m_chDirName[MAX_PATH]; + std::string m_fOriginPath; + std::string m_fNameBase; }; #endif //__SAMPLEGRABBERCALLBACK_H__ \ No newline at end of file diff --git a/inc/common.h b/inc/common.h index ef20973..53e5a06 100644 --- a/inc/common.h +++ b/inc/common.h @@ -5,6 +5,8 @@ #include "qedit.h" #include #include +#include +#include #pragma comment(lib,"Strmiids.lib") //define release maco @@ -19,5 +21,6 @@ void Msg(HWND hwnd,TCHAR *szFormat, ...); bool Bstr_Compare(BSTR bstrFilter,BSTR bstrDevice); +std::string TCHAR2STRING(TCHAR * STR); #endif// __COMMON_H__ \ No newline at end of file diff --git a/src/Main.cpp b/src/Main.cpp index b6e797e..da28010 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -128,8 +128,8 @@ INT_PTR CALLBACK WndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) break; case IDONESHOT: { - //g_CaptureVideo.GrabOneFrame(TRUE); - SetTimer(hDlg,ID_TIMER,150, TimerGetPicture); + g_CaptureVideo.GrabOneFrame(TRUE); + //SetTimer(hDlg,ID_TIMER,150, TimerGetPicture); } break; diff --git a/src/SampleGrabberCallback.cpp b/src/SampleGrabberCallback.cpp index 772728d..fa30b8b 100644 --- a/src/SampleGrabberCallback.cpp +++ b/src/SampleGrabberCallback.cpp @@ -57,12 +57,32 @@ HRESULT STDMETHODCALLTYPE SampleGrabberCallback::BufferCB(double Time, BYTE *pBu BOOL SampleGrabberCallback::SaveBitmap(BYTE * pBuffer, long lBufferSize ) { + std::string g_fPath = "."; + bool g_saveBmp = false; + bool g_saveJpg = false; + bool g_savePng = false; + std::fstream fs; + fs.open("config", std::ios::in); + std::string tmp; + getline(fs, tmp); + g_fPath = tmp; + int t; + fs >> t; if (t) g_saveBmp = true; + fs >> t; if (t) g_saveJpg = true; + fs >> t; if (t) g_savePng = true; + fs.close(); SYSTEMTIME sysTime; GetLocalTime(&sysTime); StringCchCopy(m_chSwapStr,MAX_PATH,m_chTempPath); - StringCchPrintf(m_chDirName,MAX_PATH,TEXT("\\%04i%02i%02i%02i%02i%02i%03ione.bmp"), + m_fOriginPath = TCHAR2STRING(m_chTempPath); + StringCchPrintf(m_chDirName,MAX_PATH,TEXT("\\%04i%02i%02i%02i%02i%02i%03i.bmp"), sysTime.wYear,sysTime.wMonth,sysTime.wDay,sysTime.wHour, sysTime.wMinute,sysTime.wSecond,sysTime.wMilliseconds); + TCHAR m_chTemp[MAX_PATH]; + StringCchPrintf(m_chTemp,MAX_PATH,TEXT("\\%04i%02i%02i%02i%02i%02i%03i"), + sysTime.wYear,sysTime.wMonth,sysTime.wDay,sysTime.wHour, + sysTime.wMinute,sysTime.wSecond,sysTime.wMilliseconds); + m_fNameBase = TCHAR2STRING(m_chTemp); StringCchCat(m_chSwapStr,MAX_PATH,m_chDirName); // %temp%/CaptureBmp/* //MessageBox(NULL,chTempPath,TEXT("Message"),MB_OK); @@ -125,5 +145,23 @@ BOOL SampleGrabberCallback::SaveBitmap(BYTE * pBuffer, long lBufferSize ) memcpy(szDstFileName + len - 3, "png", 3); bRet = ifc.ToPng(szSrcFileName, szDstFileName); + if (g_saveBmp == true) { + std::string cmd = "COPY \"" + m_fOriginPath + m_fNameBase + ".bmp\" \"" + + g_fPath + m_fNameBase + ".bmp\""; + system(cmd.c_str()); + } + + if (g_saveJpg == true) { + std::string cmd = "COPY \"" + m_fOriginPath + m_fNameBase + ".jpg\" \"" + + g_fPath + m_fNameBase + ".jpg\""; + system(cmd.c_str()); + } + + if (g_savePng == true) { + std::string cmd = "COPY \"" + m_fOriginPath + m_fNameBase + ".png\" \"" + + g_fPath + m_fNameBase + ".png\""; + system(cmd.c_str()); + } + return TRUE; } diff --git a/src/common.cpp b/src/common.cpp index 7d61356..36531ad 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -49,4 +49,14 @@ bool Bstr_Compare(BSTR bstrFilter,BSTR bstrDevice) flag = true; } return flag; +} + +std::string TCHAR2STRING(TCHAR* STR) +{ + int iLen = WideCharToMultiByte(CP_ACP, 0, STR, -1, NULL, 0, NULL, NULL); + char* chRtn = new char[iLen * sizeof(char)]; + WideCharToMultiByte(CP_ACP, 0, STR, -1, chRtn, iLen, NULL, NULL); + std::string str(chRtn); + delete chRtn; + return str; } \ No newline at end of file