how to create an AVI stream in memory?
-
Is there any way to create an AVIStream in memory? without having to write to disk? I’ve tried using the AVIStreamCreate function from avifil32.dll, but it keeps returning an error. I need to capture video from a webcam, to a compressed avistream. And then send the compressed stream over an LAN. This is the code:
AVISTREAMINFOW aviStreamInfo = new AVISTREAMINFOW(); aviStreamInfo.fccType = _fccType; aviStreamInfo.fccHandler = _fccHandler; aviStreamInfo.dwScale = 1; aviStreamInfo.dwRate = _frameRate; aviStreamInfo.dwSuggestedBufferSize = _height * _stride; aviStreamInfo.dwQuality = 0xffffffff; aviStreamInfo.rect_bottom = _height; aviStreamInfo.rect_right = _width; //_result = AviFile.AVIFileCreateStream(_aviFile, out _aviStream, ref aviStreamInfo); _result = AviFile.AVIStreamCreate(out _aviStream, 0, 0, ref aviStreamInfo);
_result returns -2147221164 -
Is there any way to create an AVIStream in memory? without having to write to disk? I’ve tried using the AVIStreamCreate function from avifil32.dll, but it keeps returning an error. I need to capture video from a webcam, to a compressed avistream. And then send the compressed stream over an LAN. This is the code:
AVISTREAMINFOW aviStreamInfo = new AVISTREAMINFOW(); aviStreamInfo.fccType = _fccType; aviStreamInfo.fccHandler = _fccHandler; aviStreamInfo.dwScale = 1; aviStreamInfo.dwRate = _frameRate; aviStreamInfo.dwSuggestedBufferSize = _height * _stride; aviStreamInfo.dwQuality = 0xffffffff; aviStreamInfo.rect_bottom = _height; aviStreamInfo.rect_right = _width; //_result = AviFile.AVIFileCreateStream(_aviFile, out _aviStream, ref aviStreamInfo); _result = AviFile.AVIStreamCreate(out _aviStream, 0, 0, ref aviStreamInfo);
_result returns -2147221164Most likely you're not properly marshalling these types, or are using incorrect types during the AVIStreamCreate method. 2 questions I would ask, is are you sure that _aviStream should be an out parameter instead of a ref (i.e. do you need to create it first?). Second question, what type is _aviStream? Windows Media SDK specifies it should be a pointer to a PAVISTREAM. Make sure you've marshalled this type correctly, it should be the address of a pointer to an IAVIStream interface. After looking further at the MSDN documentation, I see Microsoft recommends "you should not need to call this function. Some functions, such as CreateEditableStream and AVIMakeCompressedStream, use it internally." You ought to use one of those methods instead.
Tech, life, family, faith: Give me a visit. Judah Himango
-
Most likely you're not properly marshalling these types, or are using incorrect types during the AVIStreamCreate method. 2 questions I would ask, is are you sure that _aviStream should be an out parameter instead of a ref (i.e. do you need to create it first?). Second question, what type is _aviStream? Windows Media SDK specifies it should be a pointer to a PAVISTREAM. Make sure you've marshalled this type correctly, it should be the address of a pointer to an IAVIStream interface. After looking further at the MSDN documentation, I see Microsoft recommends "you should not need to call this function. Some functions, such as CreateEditableStream and AVIMakeCompressedStream, use it internally." You ought to use one of those methods instead.
Tech, life, family, faith: Give me a visit. Judah Himango
Question 1. I've tryed this
[DllImport("avifil32.dll")] public static extern int CreateEditableStream(out IntPtr ppsEditable, int psSource); private IntPtr _aviEditable; private IntPtr _aviEditableCompressed; _result = AviFile.CreateEditableStream(out _aviEditable, 0); if(_result != 0) { throw new AviException("Failed to create editable AVI stream.", _result); }
And it returns an address (eg. no error) So i don't think i need to create it first. BUT! it wont doAVICOMPRESSOPTIONS EditablecompressionOptions = new AVICOMPRESSOPTIONS(); EditablecompressionOptions.fccType = _fccType; EditablecompressionOptions.fccHandler = _fccHandler; EditablecompressionOptions.lpFormat = new IntPtr(0); EditablecompressionOptions.lpParms = new IntPtr(0); _result = AviFile.AVIMakeCompressedStream(out _aviEditableCompressed, _aviEditable, ref EditablecompressionOptions, 0); if(_result != 0) { throw new AviException("Failed to create editable compressed AVI stream.", _result); }
But, if it is a file based avistream it works :confused: Question 2. The _aviStream is IntPtr -
Question 1. I've tryed this
[DllImport("avifil32.dll")] public static extern int CreateEditableStream(out IntPtr ppsEditable, int psSource); private IntPtr _aviEditable; private IntPtr _aviEditableCompressed; _result = AviFile.CreateEditableStream(out _aviEditable, 0); if(_result != 0) { throw new AviException("Failed to create editable AVI stream.", _result); }
And it returns an address (eg. no error) So i don't think i need to create it first. BUT! it wont doAVICOMPRESSOPTIONS EditablecompressionOptions = new AVICOMPRESSOPTIONS(); EditablecompressionOptions.fccType = _fccType; EditablecompressionOptions.fccHandler = _fccHandler; EditablecompressionOptions.lpFormat = new IntPtr(0); EditablecompressionOptions.lpParms = new IntPtr(0); _result = AviFile.AVIMakeCompressedStream(out _aviEditableCompressed, _aviEditable, ref EditablecompressionOptions, 0); if(_result != 0) { throw new AviException("Failed to create editable compressed AVI stream.", _result); }
But, if it is a file based avistream it works :confused: Question 2. The _aviStream is IntPtrHave you looked at this page? I see that it uses some of the functions we're talking about, maybe you can gain some understanding from it.
Tech, life, family, faith: Give me a visit. Judah Himango
-
Have you looked at this page? I see that it uses some of the functions we're talking about, maybe you can gain some understanding from it.
Tech, life, family, faith: Give me a visit. Judah Himango
Yep....I know it.....It's the lib i use.