using static Vanara.PInvoke.WinMm; namespace Vanara.PInvoke; /// Items from the AviFil32.dll public static partial class AviFil32 { static AviFil32() => StaticFieldValueHash.AddFields(Lib_Avifil32); /// public static readonly uint ckidAVIMAINHDR = MAKEFOURCC('a', 'v', 'i', 'h'); /// public static readonly uint ckidAVINEWINDEX = MAKEFOURCC('i', 'd', 'x', '1'); /// public static readonly uint ckidAVIPADDING = MAKEFOURCC('J', 'U', 'N', 'K'); /// public static readonly uint ckidSTREAMFORMAT = MAKEFOURCC('s', 't', 'r', 'f'); /// public static readonly uint ckidSTREAMHANDLERDATA = MAKEFOURCC('s', 't', 'r', 'd'); /// public static readonly uint ckidSTREAMHEADER = MAKEFOURCC('s', 't', 'r', 'h'); /// public static readonly uint ckidSTREAMNAME = MAKEFOURCC('s', 't', 'r', 'n'); /// public static readonly ushort cktypeDIBbits = aviTWOCC('d', 'b'); /// public static readonly ushort cktypeDIBcompressed = aviTWOCC('d', 'c'); /// public static readonly ushort cktypePALchange = aviTWOCC('p', 'c'); /// public static readonly ushort cktypeWAVEbytes = aviTWOCC('w', 'b'); /// public static readonly uint formtypeAVI = MAKEFOURCC('A', 'V', 'I', ' '); /// public static readonly uint listtypeAVIHEADER = MAKEFOURCC('h', 'd', 'r', 'l'); /// public static readonly uint listtypeAVIMOVIE = MAKEFOURCC('m', 'o', 'v', 'i'); /// public static readonly uint listtypeAVIRECORD = MAKEFOURCC('r', 'e', 'c', ' '); /// public static readonly uint listtypeSTREAMHEADER = MAKEFOURCC('s', 't', 'r', 'l'); /// public static readonly uint streamtypeAUDIO = MAKEFOURCC('a', 'u', 'd', 's'); /// public static readonly uint streamtypeMIDI = MAKEFOURCC('m', 'i', 'd', 's'); /// public static readonly uint streamtypeTEXT = MAKEFOURCC('t', 'x', 't', 's'); /// public static readonly uint streamtypeVIDEO = MAKEFOURCC('v', 'i', 'd', 's'); /// Errors for AVI functions [PInvokeData("vfw.h")] public enum AVIERR { /// Compression is not supported for this type of data. This error might be returned if you try to compress data that is not audio or video. AVIERR_UNSUPPORTED = unchecked((int)0x80044000 + 101), /// The file couldn't be read, indicating a corrupt file or an unrecognized format. AVIERR_BADFORMAT = unchecked((int)0x80044000 + 102), /// There is not enough memory to complete the operation. AVIERR_MEMORY = unchecked((int)0x80044000 + 103), /// AVIERR_INTERNAL = unchecked((int)0x80044000 + 104), /// AVIERR_BADFLAGS = unchecked((int)0x80044000 + 105), /// AVIERR_BADPARAM = unchecked((int)0x80044000 + 106), /// AVIERR_BADSIZE = unchecked((int)0x80044000 + 107), /// AVIERR_BADHANDLE = unchecked((int)0x80044000 + 108), /// A disk error occurred while reading the file. AVIERR_FILEREAD = unchecked((int)0x80044000 + 109), /// AVIERR_FILEWRITE = unchecked((int)0x80044000 + 110), /// A disk error occurred while opening the file. AVIERR_FILEOPEN = unchecked((int)0x80044000 + 111), /// AVIERR_COMPRESSOR = unchecked((int)0x80044000 + 112), /// A suitable compressor cannot be found. AVIERR_NOCOMPRESSOR = unchecked((int)0x80044000 + 113), /// The file was opened without write access. AVIERR_READONLY = unchecked((int)0x80044000 + 114), /// The file does not contain a stream corresponding to the values of fccType and lParam. AVIERR_NODATA = unchecked((int)0x80044000 + 115), /// The buffer size cbBuffer was smaller than a single sample of data. AVIERR_BUFFERTOOSMALL = unchecked((int)0x80044000 + 116), /// AVIERR_CANTCOMPRESS = unchecked((int)0x80044000 + 117), /// The user wishes to abort the operation. AVIERR_USERABORT = unchecked((int)0x80044000 + 198), /// AVIERR_ERROR = unchecked((int)0x80044000 + 199), } /// Flags for VIDEOHDR [PInvokeData("vfw.h", MSDNShortId = "NS:vfw.videohdr_tag")] [Flags] public enum VHDR : uint { /// Done bit VHDR_DONE = 0x00000001, /// Set if this header has been prepared VHDR_PREPARED = 0x00000002, /// Reserved for driver VHDR_INQUEUE = 0x00000004, /// Key Frame VHDR_KEYFRAME = 0x00000008, } /// /// The CAPDRIVERCAPS structure defines the capabilities of the capture driver. /// /// An application should use the WM_CAP_DRIVER_GET_CAPS message or capDriverGetCaps macro to place a copy of the driver /// capabilities in a CAPDRIVERCAPS structure whenever the application connects a capture window to a capture driver. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/ns-vfw-capdrivercaps typedef struct tagCapDriverCaps { UINT wDeviceIndex; // BOOL fHasOverlay; BOOL fHasDlgVideoSource; BOOL fHasDlgVideoFormat; BOOL fHasDlgVideoDisplay; BOOL fCaptureInitialized; BOOL // fDriverSuppliesPalettes; HANDLE hVideoIn; HANDLE hVideoOut; HANDLE hVideoExtIn; HANDLE hVideoExtOut; } CAPDRIVERCAPS, // *PCAPDRIVERCAPS, *LPCAPDRIVERCAPS; [PInvokeData("vfw.h", MSDNShortId = "NS:vfw.tagCapDriverCaps")] [StructLayout(LayoutKind.Sequential)] public struct CAPDRIVERCAPS { /// Index of the capture driver. An index value can range from 0 to 9. public uint wDeviceIndex; /// Video-overlay flag. The value of this member is TRUE if the device supports video overlay. [MarshalAs(UnmanagedType.Bool)] public bool fHasOverlay; /// /// Video source dialog flag. The value of this member is TRUE if the device supports a dialog box for selecting and /// controlling the video source. /// [MarshalAs(UnmanagedType.Bool)] public bool fHasDlgVideoSource; /// /// Video format dialog flag. The value of this member is TRUE if the device supports a dialog box for selecting the /// video format. /// [MarshalAs(UnmanagedType.Bool)] public bool fHasDlgVideoFormat; /// /// Video display dialog flag. The value of this member is TRUE if the device supports a dialog box for controlling the /// redisplay of video from the capture frame buffer. /// [MarshalAs(UnmanagedType.Bool)] public bool fHasDlgVideoDisplay; /// /// Capture initialization flag. The value of this member is TRUE if a capture device has been successfully connected. /// [MarshalAs(UnmanagedType.Bool)] public bool fCaptureInitialized; /// Driver palette flag. The value of this member is TRUE if the driver can create palettes. [MarshalAs(UnmanagedType.Bool)] public bool fDriverSuppliesPalettes; /// Not used in Win32 applications. public HANDLE hVideoIn; /// Not used in Win32 applications. public HANDLE hVideoOut; /// Not used in Win32 applications. public HANDLE hVideoExtIn; /// Not used in Win32 applications. public HANDLE hVideoExtOut; } /// /// The CAPINFOCHUNK structure contains parameters that can be used to define an information chunk within an AVI capture /// file. The WM_CAP_FILE_SET_INFOCHUNK message or capSetInfoChunk macro is used to send a CAPINFOCHUNK structure to a /// capture window. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/ns-vfw-capinfochunk typedef struct tagCapInfoChunk { FOURCC fccInfoID; // LPVOID lpData; LONG cbData; } CAPINFOCHUNK, *PCAPINFOCHUNK, *LPCAPINFOCHUNK; [PInvokeData("vfw.h", MSDNShortId = "NS:vfw.tagCapInfoChunk")] [StructLayout(LayoutKind.Sequential)] public struct CAPINFOCHUNK { /// /// Four-character code that identifies the representation of the chunk data. If this value is NULL and lpData is /// NULL, all accumulated information chunks are deleted. /// public uint fccInfoID; /// Pointer to the data. If this value is NULL, all fccInfoID information chunks are deleted. public IntPtr lpData; /// /// Size, in bytes, of the data pointed to by lpData. If lpData specifies a null-terminated string, use the string /// length incremented by one to save the NULL with the string. /// public int cbData; } /// The CAPSTATUS structure defines the current state of the capture window. /// /// Because the state of a capture window changes in response to various messages, an application should update the information in /// this structure whenever it needs to enable menu items, determine the actual state of the capture window, or call the video /// format dialog box. If the application yields during streaming capture, this structure returns the progress of the capture in the /// dwCurrentVideoFrame, dwCurrentVideoFramesDropped, dwCurre ntWaveSamples, and dwCurrentTimeElapsedMS /// members. Use the WM_CAP_GET_STATUS message or capGetStatus macro to update the contents of this structure. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/ns-vfw-capstatus typedef struct tagCapStatus { UINT uiImageWidth; UINT // uiImageHeight; BOOL fLiveWindow; BOOL fOverlayWindow; BOOL fScale; POINT ptScroll; BOOL fUsingDefaultPalette; BOOL // fAudioHardware; BOOL fCapFileExists; DWORD dwCurrentVideoFrame; DWORD dwCurrentVideoFramesDropped; DWORD dwCurrentWaveSamples; // DWORD dwCurrentTimeElapsedMS; HPALETTE hPalCurrent; BOOL fCapturingNow; DWORD dwReturn; UINT wNumVideoAllocated; UINT // wNumAudioAllocated; } CAPSTATUS, *PCAPSTATUS, *LPCAPSTATUS; [PInvokeData("vfw.h", MSDNShortId = "NS:vfw.tagCapStatus")] [StructLayout(LayoutKind.Sequential)] public struct CAPSTATUS { /// Image width, in pixels. public uint uiImageWidth; /// Image height, in pixels public uint uiImageHeight; /// /// Live window flag. The value of this member is TRUE if the window is displaying video using the preview method. /// [MarshalAs(UnmanagedType.Bool)] public bool fLiveWindow; /// /// Overlay window flag. The value of this member is TRUE if the window is displaying video using hardware overlay. /// [MarshalAs(UnmanagedType.Bool)] public bool fOverlayWindow; /// /// Input scaling flag. The value of this member is TRUE if the window is scaling the input video to the client area when /// displaying video using preview. This parameter has no effect when displaying video using overlay. /// [MarshalAs(UnmanagedType.Bool)] public bool fScale; /// The x- and y-offset of the pixel displayed in the upper left corner of the client area of the window. public POINT ptScroll; /// Default palette flag. The value of this member is TRUE if the capture driver is using its default palette. [MarshalAs(UnmanagedType.Bool)] public bool fUsingDefaultPalette; /// Audio hardware flag. The value of this member is TRUE if the system has waveform-audio hardware installed. [MarshalAs(UnmanagedType.Bool)] public bool fAudioHardware; /// Capture file flag. The value of this member is TRUE if a valid capture file has been generated. [MarshalAs(UnmanagedType.Bool)] public bool fCapFileExists; /// /// Number of frames processed during the current (or most recent) streaming capture. This count includes dropped frames. /// public uint dwCurrentVideoFrame; /// /// Number of frames dropped during the current (or most recent) streaming capture. Dropped frames occur when the capture rate /// exceeds the rate at which frames can be saved to file. In this case, the capture driver has no buffers available for storing /// data. Dropping frames does not affect synchronization because the previous frame is displayed in place of the dropped frame. /// public uint dwCurrentVideoFramesDropped; /// Number of waveform-audio samples processed during the current (or most recent) streaming capture. public uint dwCurrentWaveSamples; /// Time, in milliseconds, since the start of the current (or most recent) streaming capture. public uint dwCurrentTimeElapsedMS; /// Handle to current palette. public HPALETTE hPalCurrent; /// Capturing flag. The value of this member is TRUE when capturing is in progress. [MarshalAs(UnmanagedType.Bool)] public bool fCapturingNow; /// Error return values. Use this member if your application does not support an error callback function. public uint dwReturn; /// /// Number of video buffers allocated. This value might be less than the number specified in the wNumVideoRequested /// member of the CAPTUREPARMS structure. /// public uint wNumVideoAllocated; /// /// Number of audio buffers allocated. This value might be less than the number specified in the wNumAudioRequested /// member of the CAPTUREPARMS structure. /// public uint wNumAudioAllocated; } /// /// The CAPTUREPARMS structure contains parameters that control the streaming video capture process. This structure is used /// to get and set parameters that affect the capture rate, the number of buffers to use while capturing, and how capture is terminated. /// /// /// /// The WM_CAP_GET_SEQUENCE_SETUP message or capCaptureGetSetup macro is used to retrieve the current capture parameters. The /// WM_CAP_SET_SEQUENCE_SETUP message or capCaptureSetSetup macro is used to set the capture parameters. /// /// /// The WM_CAP_GET_SEQUENCE_SETUP message or capCaptureGetSetup macro is used to retrieve the current capture parameters. The /// WM_CAP_SET_SEQUENCE_SETUP message or capCaptureSetSetup macro is used to set the capture parameters. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/ns-vfw-captureparms typedef struct tagCaptureParms { DWORD // dwRequestMicroSecPerFrame; BOOL fMakeUserHitOKToCapture; UINT wPercentDropForError; BOOL fYield; DWORD dwIndexSize; UINT // wChunkGranularity; BOOL fUsingDOSMemory; UINT wNumVideoRequested; BOOL fCaptureAudio; UINT wNumAudioRequested; UINT vKeyAbort; // BOOL fAbortLeftMouse; BOOL fAbortRightMouse; BOOL fLimitEnabled; UINT wTimeLimit; BOOL fMCIControl; BOOL fStepMCIDevice; DWORD // dwMCIStartTime; DWORD dwMCIStopTime; BOOL fStepCaptureAt2x; UINT wStepCaptureAverageFrames; DWORD dwAudioBufferSize; BOOL // fDisableWriteCache; UINT AVStreamMaster; } CAPTUREPARMS, *PCAPTUREPARMS, *LPCAPTUREPARMS; [PInvokeData("vfw.h", MSDNShortId = "NS:vfw.tagCaptureParms")] [StructLayout(LayoutKind.Sequential)] public struct CAPTUREPARMS { /// Requested frame rate, in microseconds. The default value is 66667, which corresponds to 15 frames per second. public uint dwRequestMicroSecPerFrame; /// /// User-initiated capture flag. If this member is TRUE, AVICap displays a dialog box prompting the user to initiate /// capture. The default value is FALSE. /// [MarshalAs(UnmanagedType.Bool)] public bool fMakeUserHitOKToCapture; /// /// Maximum allowable percentage of dropped frames during capture. Values range from 0 to 100. The default value is 10. /// public uint wPercentDropForError; /// /// /// Yield flag. If this member is TRUE, the capture window spawns a separate background thread to perform step and /// streaming capture. The default value is FALSE. /// /// /// Applications that set this flag must handle potential reentry issues because the controls in the application are not /// disabled while capture is in progress. /// /// [MarshalAs(UnmanagedType.Bool)] public bool fYield; /// /// /// Maximum number of index entries in an AVI file. Values range from 1800 to 324,000. If set to 0, a default value of 34,952 /// (32K frames plus a proportional number of audio buffers) is used. /// /// /// Each video frame or buffer of waveform-audio data uses one index entry. The value of this entry establishes a limit for the /// number of frames or audio buffers that can be captured. /// /// public uint dwIndexSize; /// Logical block size, in bytes, of an AVI file. The value 0 indicates the current sector size is used as the granularity. public uint wChunkGranularity; /// Not used in Win32 applications. [MarshalAs(UnmanagedType.Bool)] public bool fUsingDOSMemory; /// /// Maximum number of video buffers to allocate. The memory area to place the buffers is specified with fUsingDOSMemory. /// The actual number of buffers allocated might be lower if memory is unavailable. /// public uint wNumVideoRequested; /// /// Capture audio flag. If this member is TRUE, audio is captured during streaming capture. This is the default value if /// audio hardware is installed. /// [MarshalAs(UnmanagedType.Bool)] public bool fCaptureAudio; /// Maximum number of audio buffers to allocate. The maximum number of buffers is 10. public uint wNumAudioRequested; /// /// /// Virtual keycode used to terminate streaming capture. The default value is VK_ESCAPE. You must call the RegisterHotKey /// function before specifying a keystroke that can abort a capture session. /// /// /// You can combine keycodes that include CTRL and SHIFT keystrokes by using the logical OR operator with the keycodes for CTRL /// (0x8000) and SHIFT (0x4000). /// /// public uint vKeyAbort; /// /// Abort flag for left mouse button. If this member is TRUE, streaming capture stops if the left mouse button is /// pressed. The default value is TRUE. /// [MarshalAs(UnmanagedType.Bool)] public bool fAbortLeftMouse; /// /// Abort flag for right mouse button. If this member is TRUE, streaming capture stops if the right mouse button is /// pressed. The default value is TRUE. /// [MarshalAs(UnmanagedType.Bool)] public bool fAbortRightMouse; /// /// Time limit enabled flag. If this member is TRUE, streaming capture stops after the number of seconds in /// wTimeLimit has elapsed. The default value is FALSE. /// [MarshalAs(UnmanagedType.Bool)] public bool fLimitEnabled; /// Time limit for capture, in seconds. This parameter is used only if fLimitEnabled is TRUE. public uint wTimeLimit; /// /// MCI device capture flag. If this member is TRUE, AVICap controls an MCI-compatible video source during streaming /// capture. MCI-compatible video sources include VCRs and laserdiscs. /// [MarshalAs(UnmanagedType.Bool)] public bool fMCIControl; /// /// MCI device step capture flag. If this member is TRUE, step capture using an MCI device as a video source is enabled. /// If it is FALSE, real-time capture using an MCI device is enabled. (If fMCIControl is FALSE, this member /// is ignored.) /// [MarshalAs(UnmanagedType.Bool)] public bool fStepMCIDevice; /// /// Starting position, in milliseconds, of the MCI device for the capture sequence. (If fMCIControl is FALSE, this /// member is ignored.) /// public uint dwMCIStartTime; /// /// Stopping position, in milliseconds, of the MCI device for the capture sequence. When this position in the content is /// reached, capture ends and the MCI device stops. (If fMCIControl is FALSE, this member is ignored.) /// public uint dwMCIStopTime; /// /// /// Double-resolution step capture flag. If this member is TRUE, the capture hardware captures at twice the specified /// resolution. (The resolution for the height and width is doubled.) /// /// Enable this option if the hardware does not support hardware-based decimation and you are capturing in the RGB format. /// [MarshalAs(UnmanagedType.Bool)] public bool fStepCaptureAt2x; /// /// Number of times a frame is sampled when creating a frame based on the average sample. A typical value for the number of /// averages is 5. /// public uint wStepCaptureAverageFrames; /// /// Audio buffer size. If the default value of zero is used, the size of each buffer will be the maximum of 0.5 seconds of audio /// or 10K bytes. /// public uint dwAudioBufferSize; /// Not used in Win32 applications. [MarshalAs(UnmanagedType.Bool)] public bool fDisableWriteCache; /// /// Indicates whether the audio stream controls the clock when writing an AVI file. If this member is set to /// AVSTREAMMASTER_AUDIO, the audio stream is considered the master stream and the video stream duration is forced to match the /// audio duration. If this member is set to AVSTREAMMASTER_NONE, the durations of audio and video streams can differ. /// public AVSTREAMMASTER AVStreamMaster; } /// /// The DRAWDIBTIME structure contains elapsed timing information for performing a set of DrawDib operations. The DrawDibTime /// function resets the count and the elapsed time value for each operation each time it is called. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/ns-vfw-drawdibtime typedef struct { LONG timeCount; LONG timeDraw; LONG // timeDecompress; LONG timeDither; LONG timeStretch; LONG timeBlt; LONG timeSetDIBits; } DRAWDIBTIME, *LPDRAWDIBTIME; [PInvokeData("vfw.h", MSDNShortId = "NS:vfw.__unnamed_struct_12")] [StructLayout(LayoutKind.Sequential)] public struct DRAWDIBTIME { /// /// Number of times the following operations have been performed since DrawDibTime was last called: /// /// /// Draw a bitmap on the screen. /// /// /// Decompress a bitmap. /// /// /// Dither a bitmap. /// /// /// Stretch a bitmap. /// /// /// Transfer bitmap data by using the BitBlt function. /// /// /// Transfer bitmap data by using the SetDIBits function. /// /// /// public int timeCount; /// Time to draw bitmaps. public int timeDraw; /// Time to decompress bitmaps. public int timeDecompress; /// Time to dither bitmaps. public int timeDither; /// Time to stretch bitmaps. public int timeStretch; /// Time to transfer bitmaps by using the BitBlt function. public int timeBlt; /// Time to transfer bitmaps by using the SetDIBits function. public int timeSetDIBits; } /// The VIDEOHDR structure is used by the capVideoStreamCallback function. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/ns-vfw-videohdr typedef struct videohdr_tag { LPBYTE lpData; DWORD // dwBufferLength; DWORD dwBytesUsed; DWORD dwTimeCaptured; DWORD_PTR dwUser; DWORD dwFlags; DWORD_PTR dwReserved[4]; } VIDEOHDR, // *PVIDEOHDR, *LPVIDEOHDR; [PInvokeData("vfw.h", MSDNShortId = "NS:vfw.videohdr_tag")] [StructLayout(LayoutKind.Sequential)] public struct VIDEOHDR { /// Pointer to locked data buffer. public IntPtr lpData; /// Length of data buffer. public uint dwBufferLength; /// Bytes actually used. public uint dwBytesUsed; /// Milliseconds from start of stream. public uint dwTimeCaptured; /// User-defined data. public IntPtr dwUser; /// /// The flags are defined as follows. /// /// /// Flag /// Meaning /// /// /// VHDR_DONE /// Done bit /// /// /// VHDR_PREPARED /// Set if this header has been prepared /// /// /// VHDR_INQUEUE /// Reserved for driver /// /// /// VHDR_KEYFRAME /// Key Frame /// /// /// public VHDR dwFlags; /// Reserved for driver. private readonly IntPtr dwReserved1; private readonly IntPtr dwReserved2; private readonly IntPtr dwReserved3; private readonly IntPtr dwReserved4; } }