| @@ -18,9 +18,10 @@ int CALLBACK Test_MediaCallBack(XSDK_HANDLE hMedia, const unsigned char *pData, | |||
| if (pFrame->nType == XSDK_FRAME_TYPE_VIDEO) | |||
| { | |||
| string fmt("/media-file/origin/%04d-%02d-%02d-%02d.dat"); | |||
| int pos = getPos(hMedia); | |||
| string fmt("/media-file/origin/%s/%04d-%02d-%02d-%02d.dat"); | |||
| char file_name[1024]; | |||
| snprintf(file_name,sizeof(file_name),fmt.c_str(),pFrame->nYear,pFrame->nMonth,pFrame->nDay,pFrame->nHour) ; | |||
| snprintf(file_name,sizeof(file_name),fmt.c_str(),DeviceIdArr[pos],pFrame->nYear,pFrame->nMonth,pFrame->nDay,pFrame->nHour) ; | |||
| // ABFile("video_header.dat", pFrame->pHeader, pFrame->nLength); | |||
| ABFile(file_name, pFrame->pContent, pFrame->nFrameLength); | |||
| } | |||
| @@ -41,6 +42,16 @@ int CALLBACK Test_MediaCallBack(XSDK_HANDLE hMedia, const unsigned char *pData, | |||
| return 0; | |||
| } | |||
| int getPos(XSDK_HANDLE hMedia) { | |||
| int size = sizeof(hDeviceArr) / sizeof(hDeviceArr); | |||
| for (int i = 0; i < size; i++) { | |||
| if (hDeviceArr[i] == hMedia) { | |||
| return i; | |||
| } | |||
| } | |||
| return -1; | |||
| } | |||
| int TestMediaRealPlay() | |||
| { | |||
| printf("MediaRealPlay %s\r\n", __FUNCTION__); | |||
| @@ -61,15 +72,18 @@ int TestMediaRealPlay() | |||
| XSDK_MediaStop(hPlayer); | |||
| hPlayer = 0; | |||
| } | |||
| SXMediaRealPlayReq param = {0}; | |||
| param.nChannel = 0; | |||
| param.nStreamType = 0; | |||
| param.nRequestType = EXSDK_DATA_FORMATE_FRAME; | |||
| param.pMediaCallback = Test_MediaCallBack; | |||
| hPlayer = XSDK_MediaRealPlay(g_hDevice, ¶m); | |||
| bPause = false; | |||
| nSpeed = 0; | |||
| int size = sizeof(hDeviceArr) / sizeof(hDeviceArr); | |||
| for (int i = 0; i < size; i++) | |||
| { | |||
| SXMediaRealPlayReq param = { 0 }; | |||
| param.nChannel = 0; | |||
| param.nStreamType = 0; | |||
| param.nRequestType = EXSDK_DATA_FORMATE_FRAME; | |||
| param.pMediaCallback = Test_MediaCallBack; | |||
| hPlayer = XSDK_MediaRealPlay(hDeviceArr[i], ¶m); | |||
| bPause = false; | |||
| nSpeed = 0; | |||
| } | |||
| } | |||
| break; | |||
| case 't': | |||
| @@ -1,13 +1,14 @@ | |||
| #include "XNetSDKTest.h" | |||
| #include "XNetSDKSyn.h" | |||
| XSDK_HANDLE g_hDevice = 0; | |||
| XSDK_HANDLE g_hDevice ; | |||
| SXMediaRecordByFileReq info = {0}; | |||
| bool bFindFile = false; | |||
| #define TEST_DAS_SERVER 1 | |||
| int CALLBACK Main_MessageCallBack(XSDK_HANDLE hDevice, int nMsgId, int nParam1, int nParam2, int nParam3, const char *szString, void *pObject, int nSeq, void *pUserData) | |||
| { | |||
| int dPos = 0 ; | |||
| switch(nMsgId) | |||
| { | |||
| case ESXSDK_DEV_FIND_FILE: | |||
| @@ -66,10 +67,15 @@ int CALLBACK Main_MessageCallBack(XSDK_HANDLE hDevice, int nMsgId, int nParam1, | |||
| case ESXSDK_ON_DAS_DEVICE_REGIST: | |||
| { | |||
| #ifdef TEST_DAS_SERVER | |||
| g_hDevice = hDevice; | |||
| g_hDevice = hDevice; | |||
| #endif | |||
| OnDASDeviceReg(hDevice, (SXSDKDASDeviceInfo *)pObject); | |||
| { | |||
| OnDASDeviceReg(hDevice, (SXSDKDASDeviceInfo *)pObject); | |||
| hDeviceArr[dPos] = hDevice ; | |||
| DeviceIdArr[dPos] = ((SXSDKDASDeviceInfo*)pObject)->sDevId ; | |||
| dPos++ ; | |||
| } | |||
| } | |||
| break; | |||
| case ESXSDK_DEV_SNAP: | |||
| @@ -13,6 +13,8 @@ | |||
| using namespace std; | |||
| extern XSDK_HANDLE g_hDevice; | |||
| extern XSDK_HANDLE hDeviceArr[6]; | |||
| extern char* DeviceIdArr[6]; | |||
| extern SXMediaRecordByFileReq info; | |||
| extern bool bFindFile; | |||
| @@ -1,7 +1,9 @@ | |||
| | |||
| Microsoft Visual Studio Solution File, Format Version 10.00 | |||
| # Visual Studio 2008 | |||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XNetSDKTest", "XNetSDKTest.vcproj", "{F3AFE773-6A5A-4952-BEDA-A97CD94D636E}" | |||
| Microsoft Visual Studio Solution File, Format Version 12.00 | |||
| # Visual Studio Version 16 | |||
| VisualStudioVersion = 16.0.29613.14 | |||
| MinimumVisualStudioVersion = 10.0.40219.1 | |||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XNetSDKTest", "XNetSDKTest.vcxproj", "{F3AFE773-6A5A-4952-BEDA-A97CD94D636E}" | |||
| EndProject | |||
| Global | |||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
| @@ -14,4 +16,7 @@ Global | |||
| GlobalSection(SolutionProperties) = preSolution | |||
| HideSolutionNode = FALSE | |||
| EndGlobalSection | |||
| GlobalSection(ExtensibilityGlobals) = postSolution | |||
| SolutionGuid = {7FD0D994-15F1-4149-A033-B5427277A290} | |||
| EndGlobalSection | |||
| EndGlobal | |||
| @@ -1,39 +0,0 @@ | |||
| """ | |||
| video.py h265[h264] | |||
| """ | |||
| import sys | |||
| import subprocess | |||
| import time | |||
| import os | |||
| DAT_FOLDER = "/media-file/origin" | |||
| TARGET_FOLDER="/media-file/camera" | |||
| SUFFIX=".dat" | |||
| TARGET_SUFFIX=".mp4" | |||
| codec = "h265" | |||
| if(len(sys.argv)>1): | |||
| codec=sys.argv[1] | |||
| # timeout=sys.argv[2] | |||
| print("codec:: {0}".format(codec)) | |||
| current_time=time.strftime(time.strftime("%Y-%m-%d-%H"),time.localtime()) | |||
| file_list = os.listdir(DAT_FOLDER) | |||
| if file_list: | |||
| for dat in file_list: | |||
| if current_time+".dat" == dat: | |||
| print("{0} ignore".format(dat)) | |||
| continue | |||
| cmd = "ffmpeg -i " + os.path.join(DAT_FOLDER,dat) + " -c copy " + os.path.join(TARGET_FOLDER, codec, dat.split(".")[0], TARGET_SUFFIX) | |||
| print("cmd:: {0}".format(cmd)) | |||
| status, output = subprocess.getstatusoutput(cmd) | |||
| print("status:: {0}, output {1}".format(status,output)) | |||
| if status==0: | |||
| print("{0} convert sucessfull, origin dat will remove!".format(dat)) | |||
| os.remove(os.path.join(DAT_FOLDER, dat)) | |||
| else: | |||
| print("{0} convert fail".format(dat)) | |||
| else: | |||
| print("folder is empty") | |||
| @@ -0,0 +1,45 @@ | |||
| """ | |||
| video.py h265[h264] | |||
| """ | |||
| import sys | |||
| import subprocess | |||
| import time | |||
| import os | |||
| DAT_FOLDER = "./" | |||
| TARGET_FOLDER = "/media-file/camera" | |||
| SUFFIX = ".dat" | |||
| TARGET_SUFFIX = ".mp4" | |||
| def list_folder(org_folder, tar_folder, code): | |||
| current_time = time.strftime(time.strftime("%Y-%m-%d-%H"), time.localtime()) | |||
| for root, dirs, files in os.walk(org_folder): | |||
| for f in files: | |||
| if current_time + ".dat" == f: | |||
| print("{0} ignore".format(os.path.join(root, f))) | |||
| continue | |||
| convert(os.path.join(root, f), os.path.join(tar_folder, list(root.split("/"))[-1], f+TARGET_SUFFIX)) | |||
| def convert(origin, target): | |||
| print("origin: {0} ,target: {1}".format(origin,target)) | |||
| cmd = "ffmpeg -i " + origin + "-c copy " + target | |||
| print("cmd:: {0}".format(cmd)) | |||
| status, output = subprocess.getstatusoutput(cmd) | |||
| print("status:: {0}, output {1}".format(status, output)) | |||
| if status == 0: | |||
| print("{0} convert {1} Success, origin dat will remove!".format(origin, target)) | |||
| os.remove(origin) | |||
| else: | |||
| print("{0} convert fail".format(origin)) | |||
| if __name__ == "__main__": | |||
| codec = "h265" | |||
| if len(sys.argv) > 1: | |||
| codec = sys.argv[1] | |||
| # timeout=sys.argv[2] | |||
| print("codec:: {0}".format(codec)) | |||
| list_folder(DAT_FOLDER, TARGET_FOLDER, codec) | |||