|
說明
Windows有提供一個結構 AVIFILEINFO,宣告如下
Private Type AVIFILEINFO dwMaxBytesPerSec As Long dwFlags As Long dwCaps As Long dwStreams As Long dwSuggestedBufferSize As Long dwWidth As Long dwHeight As Long
dwScale As Long dwRate As Long dwLength As Long dwEditCount As Long szFileType As String * 64 End Type
dwMaxBytesPerSec: Approximate maximum data rate of the AVI file. dwFlags: Applicable flags. The following flags are defined: AVIFILEINFO_HASINDEX
: The AVI file has an index at the end of the file. For good performance, all AVI files should contain an index.
AVIFILEINFO_MUSTUSEINDEX : The file index contains the playback order for the chunks in the file.
Use the index rather than the physical ordering of the chunks when playing
back the data. This could be used for creating a list of frames for editing. AVIFILEINFO_ISINTERLEAVED :
The AVI file is interleaved. AVIFILEINFO_WASCAPTUREFILE :
The AVI file is a specially allocated file used for capturing real-time video.
Applications should warn the user before writing over a file with this flag set because the user probably defragmented this file.
AVIFILEINFO_COPYRIGHTED: The AVI file contains copyrighted data and software.
When this flag is used, software should not permit the data to be duplicated. dwCaps : Capability flags. The following flags are defined:
AVIFILECAPS_CANREAD: An application can open the AVI file with with the read privilege. AVIFILECAPS_CANWRITE:
An application can open the AVI file with the write privilege. AVIFILECAPS_ALLKEYFRAMES :
Every frame in the AVI file is a key frame. AVIFILECAPS_NOCOMPRESSION:
The AVI file does not use a compression method. dwStreams: Number of streams in the file. For example, a file with audio and video has
at least two streams. dwSuggestedBufferSize : Suggested buffer size, in bytes, for reading the file. Generally, this size should
be large enough to contain the largest chunk in the file. For an interleaved file, this size should be large enough to read an entire record, not just a chunk.
If the buffer size is too small or is set to zero, the playback software will have to reallocate memory during playback, reducing performance. dwWidth
Width, in pixels, of the AVI file. dwHeight Height, in pixels, of the AVI file. dwScale Time scale applicable for the entire file. Dividing dwRate by dwScale
gives the number of samples per second. Any stream can define its own time scale to supersede the file time scale. dwRate
Rate in an integer format. To obtain the rate in samples per second, divide this value by the value in dwScale. dwLength
Length of the AVI file. The units are defined by dwRate and dwScale. dwEditCount Number of streams that have been added to or deleted from the AVI file. szFileType
Null-terminated string containing descriptive information for the file type. 藉由這個結構 很容易的就可以得到AVI檔的資訊 現在只要將檔案資訊填到這個結構就行了
程式
Private Const ERROR_SUCCESS As Long = 0
Private Const AVIFILEINFO_HASINDEX As Long = &H10 Private Const AVIFILEINFO_MUSTUSEINDEX As Long = &H20 Private Const AVIFILEINFO_ISINTERLEAVED As Long = &H100
Private Const AVIFILEINFO_WASCAPTUREFILE As Long = &H10000 Private Const AVIFILEINFO_COPYRIGHTED As Long = &H20000
Private Const AVIFILECAPS_CANREAD As Long = &H1 Private Const AVIFILECAPS_CANWRITE As Long = &H2
Private Const AVIFILECAPS_ALLKEYFRAMES As Long = &H10 Private Const AVIFILECAPS_NOCOMPRESSION As Long = &H20
Private Type AVIFILEINFO dwMaxBytesPerSec As Long dwFlags As Long dwCaps As Long
dwStreams As Long dwSuggestedBufferSize As Long dwWidth As Long dwHeight As Long dwScale As Long dwRate As Long dwLength As Long dwEditCount As Long
szFileType As String * 64 End Type
Private Declare Function AVIFileOpen Lib "avifil32" _ Alias "AVIFileOpenA" _ (ppfile As Long, _ ByVal szFile As String, _
ByVal mode As Long, _ pclsidHandler As Any) As Long
Private Declare Function AVIFileRelease Lib "avifil32" _ (ByVal pfile As Long) As Long
Private Declare Function AVIGetFileInfo Lib "avifil32" _ Alias "AVIFileInfoA" _ (ByVal pfile As Long, _ pfi As AVIFILEINFO, _ ByVal lSize As Long) As Long
Private Declare Sub AVIFileInit Lib "avifil32" () Private Declare Sub AVIFileExit Lib "avifil32" ()
Private Function GetAVIFileInfo(sAVIFile As String) As AVIFILEINFO
Dim hAvi As Long Dim AviInfo As AVIFILEINFO
AVIFileInit
If AVIFileOpen(hAvi, sAVIFile, OF_SHARE_DENY_WRITE, ByVal 0&) = ERROR_SUCCESS Then
If AVIGetFileInfo(hAvi, AviInfo, Len(AviInfo)) = ERROR_SUCCESS Then GetAVIFileInfo = AviInfo End If
AVIFileRelease hAvi
End If AVIFileExit
End Function
之後 只要呼叫
就可以由藉由oo結構取得相關資訊
文件出處
整理時間
|