0

我想通过 SDK 将 .hik (Hikvision) 格式的视频提取为 MP4。我的代码是下一个:

#include <stdio.h>
#include <stdlib.h>
#include "../SDK/incEn/HCNetSDK.h"
#include "Windows.h"

using namespace std;


int saveRecordFile(int userId, char * srcfile, char * destfile) {
    HINSTANCE hGetProcIDDLL = LoadLibrary("D:\\ExtraccionYConversionArchivos\\c++\\Fuente\\SDK\\HCNetSDK.dll");
    int bRes = 1;
    int hPlayBack = 0;
    if ( (hPlayBack = NET_DVR_GetFileByName(userId, srcfile, destfile)) < 0)
    {
       printf("Error en GetFileByName. Error[$d]\n",NET_DVR_GetLastError());
       bRes = -1;
       return bRes;
    }

    if (!NET_DVR_PlayBackControl(hPlayBack, NET_DVR_PLAYSTART,0,NULL))
    {
       printf("Control de play back fallido [%d]\n", NET_DVR_GetLastError());
       bRes = -1;
       return bRes;
    }
    int nPos = 0;
    for (nPos = 0; nPos < 100 && nPos >= 0; nPos = NET_DVR_GetDownloadPos(hPlayBack))
    {
        Sleep(5000);
    }
    printf("Se obtuvo %d\n", nPos);

    if (!NET_DVR_StopGetFile(hPlayBack))
    {
       printf("Error al detener descarga de archivo [%d]\n",NET_DVR_GetLastError());
       bRes = -1;
       return bRes;
    }
    printf("%s\n",srcfile);

    if (nPos < 0 || nPos > 100)
    {
       printf("Error de descarga [%d]\n", NET_DVR_GetLastError());
       bRes = -1;
       return bRes;
    }
    else
    {
        return 0;
    }
}

int main()
{
    printf("Hello world!\n");
    return 0;
}

它使用 HCNetSDK.h 标头,这会在多行中向我抛出错误:字符串常量之前的语法错误。这个头文件有41K多行,大部分错误都在typedef之后:

typedef void (CALLBACK *MSGCallBack)(LONG lCommand, NET_DVR_ALARMER *pAlarmer, char *pAlarmInfo, DWORD dwBufLen, void* pUser); 
NET_DVR_API BOOL __stdcall NET_DVR_SetDVRMessageCallBack_V30(MSGCallBack fMessageCallBack, void* pUser);

可能是什么问题呢?在这行之前,有超过 6K 的 typedef 结构,如下所示:

typedef struct  tagNET_DVR_MATRIX_STATUS_V50
{
    DWORD dwSize;
    BYTE  byMainFrameType;
    BYTE  bySoltNum;
    BYTE  byBoardNum;
    BYTE  byLCDPanelStatus;
    NET_DVR_MATRIX_SUBBOARD_V50 struMatrixSubboard[MAX_MATRIX_SUBBOARD_NUM];
    DWORD dwFanSequence;
    DWORD dwFanConnectStatus;
    DWORD dwFanOperationStatus;
    BYTE  byDeviceModel[32];
    BYTE  byRes[32];
}NET_DVR_MATRIX_STATUS_V50, *LPNET_DVR_MATRIX_STATUS_V50;

即使我对每个 typedef 结构都进行了评论以发现错误,我也不知道怎么做。

4

1 回答 1

1

A few things to try: Look for another file that includes this header. Does it compile? What other headers does it use and which of those come before this header in the list?

Can you copy (duplicate and rename) this code into a C file with a simple hello world main function? It might force the compiler to tell you which line the actual problem is on.

Are you using an old compiler? I used to get problems with an old version of Visual Studio - it wasn’t up to date with C99 so it couldn’t compile certain data types (that were no problem for GNU compilers). C standards are sometimes updated and you need to use a suitable compiler (or code in an old style!).

Finally, is it possible to extract or convert the data with ffmpeg? If you can do it on a command line, there’s no need to compile any code.

于 2018-02-17T20:14:25.273 回答