Skip to content

Commit

Permalink
add config file and modify default behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabing010102 committed Sep 4, 2020
1 parent 0e432cb commit 58fb30e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 3 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions inc/SampleGrabberCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
3 changes: 3 additions & 0 deletions inc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "qedit.h"
#include <strsafe.h>
#include <assert.h>
#include <string>
#include <fstream>
#pragma comment(lib,"Strmiids.lib")

//define release maco
Expand All @@ -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__
4 changes: 2 additions & 2 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
40 changes: 39 additions & 1 deletion src/SampleGrabberCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 58fb30e

Please sign in to comment.