};
~Tdll()
{
if (hdll)
FreeLibrary(hdll);
}
void loadFunction(void **fnc,const char *name)
{
*fnc=GetProcAddress(hdll,name);
ok&=(*fnc!=NULL);
};
};
#endif
main.cpp:
[cpp]
#include "stdafx.h"
#include "h264dec.h"
#include "postprocess.h"
#define INBUF_SIZE 100 * 1024;
static int FindStartCode (unsigned char *Buf, int zeros_in_startcode)
{
int info;
int i;
info = 1;
for (i = 0; i < zeros_in_startcode; i++)
{
if(Buf[i] != 0)
info = 0;
}
if(Buf[i] != 1)
info = 0;
return info;
}
static bool Check_StartCode(unsigned char *Buf, int pos)
{
int info3 = 0;
info3 = FindStartCode(&Buf[pos-4], 3);
return info3 == 1;
}
static int getNextNal(FILE* inpf, unsigned char* Buf)
{
int pos = 0;
int StartCodeFound = 0;
int info2 = 0;
int info3 = 0;
int nCount = 0;
while(!feof(inpf) && ++nCount <= 4)
{
Buf[pos++]=fgetc(inpf);
}
if(!Check_StartCode(Buf, pos))
{
return 0;
}
while(!feof(inpf) && (Buf[pos++]=fgetc(inpf))==0);
while (!StartCodeFound)
{
{
// return -1;
return pos-1;
}
Buf[pos++] = fgetc (inpf);
StartCodeFound = Check_StartCode(Buf, pos);
}
fseek (inpf, -4, SEEK_CUR);
return pos - 4;
}
int main(int argc, char* argv[])
{
if (argc != 5)
{
printf("please input: PP_Demo.exe filename1[input] Width Height filename2[output]\n");
}
//params set
unsigned short usWidth = atoi(argv[2]);
unsigned short usHeight = atoi(argv[3]);
//create dec&pp
h264dec *pdec = new h264dec;
if(!pdec->InitH264Deocder(usWidth, usHeight))
{
return false;
}
unsigned char *p_In_Frame = new unsigned char[usWidth * usHeight * 3/2];
unsigned char *p_Out_Frame = new unsigned char[usWidth * usHeight * 3/2];
FILE* ifp = fopen(argv[1],"rb");
FILE* ofp = fopen(argv[4],"wb");
bool b_continue = true;
int nReadUnit = usWidth * usHeight * 3/2;
while(!feof(ifp))
{
int nCount = getNextNal(ifp, p_In_Frame);
if(nCount == 0)
{
continue;
}
unsigned char *ptr = p_In_Frame;
int n_Outlen = 0;
pdec->H264Decode(ptr, nCount, p_Out_Frame, n_Outlen);
if(n_Outlen > 0)
{
fwrite(p_Out_Frame, 1, n_Outlen, ofp);
}
}
//realse
delete []p_In_Frame;
delete []p_Out_Frame;
pdec->StopH264Decoder();
pdec->ReleaseConnection();
fclose(ifp);
fclose(ofp);
return 0; 作者:wchm_seu