[XviD-devel] Problem to use XVID core
A AP
snopa at freeuk.com
Wed Jul 4 18:34:00 CEST 2007
Hi,
I'm programming an application to capture a image from a camera web and
convert it in XVID format to save in file later.
When I compile my application and trying to EXECUTE a error window show to
me: "Application.exe has detected a problem and it must close it".
"The instruction in "0x1004b876" references to memory in "0x0000004. The
memory cannot 'written' "
If I debug step by step the next message ("Unhandled exception in
"application.exe (XVIDCORE.DLL): 0XC0000005: Access Violation") appear to me
when the execution point is in this line code:
-> "xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame, NULL):"
AN OVERVIEW OF MY CODE
----------------------
LANGUAGE: C++
S.O.: Windows XP
XVID core: 1.1.2
1. FIRST STEP:
CreateEncodeXVID(int iWidthFrame,int iHeightFrame){
{
//------------------------------------------------------------
//XVID core initialization
//------------------------------------------------------------
memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init));
xvid_gbl_init.version = XVID_VERSION;
xvid_gbl_init.debug = 0;
xvid_gbl_init.cpu_flags = 0; // No force cpu
/* Initialize XviD core -- Should be done once per __process__ */
xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
//------------------------------------------------------------
// XviD encoder initialization
// -----------------------------------------------------------
memset(&xvid_enc_create, 0, sizeof(xvid_enc_create));
xvid_enc_create.version = XVID_VERSION;
/* Width and Height of input frames */
xvid_enc_create.width = iWidthFrame; //640
xvid_enc_create.height = iHeightFrame; //480
xvid_enc_create.profile = XVID_PROFILE_AS_L4;
//...
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
/* Retrieve the encoder instance from the structure */
enc_handle = xvid_enc_create.handle;
}
_____________________________________________________
2. SECOND STEP
OnCapture()
{
capGrabFrame(capSTR.hWndC); // sample a single frame from the CAM
capEditCopy(capSTR.hWndC); // edit a copy of the frame.
OpenClipboard(); //like virtual memory.
//m_hwdBmp is a Handle to Bitmap.
m_hwdBmp = (HBITMAP)::GetClipboardData(CF_BITMAP);
CloseClipboard();
}
_____________________________________________________
3. THIRD STEP
RecoverBUFFERimage(HBITMAP hBMP, HDC hDC)
{
PBITMAPINFO pbi;
...
LPBYTE lpBits;
GetDIBits(hDC, hBMP, 0, (WORD) pbi->bmiHeader.biHeight, lpBits, pbi,
DIB_RGB_COLORS))
}
_____________________________________________________
4. FOURTH STEP
EncodeFrame(
unsigned char *image,
unsigned char *bitstream,
int bmpWidth,
int bmpHeight,
int *key)
{
memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame));
xvid_enc_frame.version = XVID_VERSION;
//ColorSpace 4:2:0 planar // XVID_CSP_RGBA
xvid_enc_frame.input.csp = XVID_CSP_YV12;
xvid_enc_frame.input.plane[0] = image; //Image to decoder
xvid_enc_frame.input.stride[0] = bmpWidth; //bytes per row (XDIM)
...
/* Bind output buffer */
xvid_enc_frame.bitstream = bitstream; //bitstream ptr (written to)
xvid_enc_frame.length = -1; //bitstream lenght (bytes)
...
ret = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame, NULL);
//&xvid_enc_stats -> NULL
}
_____________________________________________
I know that it must be difficult to ascertain where is the problem if you
don't have all code (initialize the XVID structs and so on), but if you have
some idea what I should change in my code it will be a great help.
THANKS IN ADVANCE.
Albert.
More information about the XviD-devel
mailing list