Delta2
20th April 2006, 15:42
Hi
How can I get the compression codec for video and audio using VB.NET ou C# ?
i.e., I want to know if a MOVIE.AVI uses XviD ou DivX video codec, and if the audio is AC3 or MP3...
how can I get this info ?
Inc
20th April 2006, 23:32
You can do that via API ....
Look for Avistreaminfo and its structure in MSDN. And for shure in here by using "search".
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_avistreaminfo.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_avistreaminfo_str.asp
typedef struct {
DWORD fccType;
DWORD fccHandler; <---------------- 'XVID', 'MJPG', 'DIVX' etc
DWORD dwFlags;
DWORD dwCaps;
WORD wPriority;
WORD wLanguage;
DWORD dwScale;
DWORD dwRate;
DWORD dwStart;
DWORD dwLength;
DWORD dwInitialFrames;
DWORD dwSuggestedBufferSize;
DWORD dwQuality;
DWORD dwSampleSize;
RECT rcFrame;
DWORD dwEditCount;
DWORD dwFormatChangeCount;
char szName[64];
} AVISTREAMINFO;
Delta2
21st April 2006, 11:16
thanks your reply
I managed to make it to work, but I don't know why the fccHandler for Audio allways returns me zero (0)
although the sample rato for audio returns 48000Hz, which indicates that the code is well formed
here is my code :
Imports System.Runtime.InteropServices
Module AviInfo
Private Const OF_SHARE_DENY_WRITE As Integer = &H20
'Stream types for use in VB (translated from C macros)
Private Const streamtypeVIDEO As Integer = 1935960438 '= mmioStringToFOURCC("vids", 0&)
Private Const streamtypeAUDIO As Integer = 1935963489 '= mmioStringToFOURCC("auds", 0&)
Private Const streamtypeMIDI As Integer = 1935960429 '= mmioStringToFOURCC("mids", 0&)
Private Const streamtypeTEXT As Integer = 1937012852 '= mmioStringToFOURCC("txts", 0&)
Private STREAM As Integer
Private Structure AVIInfo
Dim dwMaxBytesPerSec As Integer
Dim dwFlags As Integer
Dim dwCaps As Integer
Dim dwStreams As Integer
Dim dwSuggestedBufferSize As Integer
Dim dwWidth As Integer
Dim dwHeight As Integer
Dim dwScale As Integer
Dim dwRate As Integer
Dim dwLength As Integer
Dim dwEditCount As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Dim szFileType As String
End Structure
Private Structure STREAMInfo
Dim fccType As Integer
Dim fccHandler As Integer
Dim dwFlags As Integer
Dim dwCaps As Integer
Dim wPriority As Short
Dim wLanguage As Short
Dim dwScale As Integer
Dim dwRate As Integer
Dim dwStart As Integer
Dim dwLength As Integer
Dim dwInitialFrames As Integer
Dim dwSuggestedBufferSize As Integer
Dim dwQuality As Integer
Dim dwSampleSize As Integer
Dim rcFrame As Rectangle
Dim dwEditCount As Integer
Dim dwFormatChangeCount As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Dim szNamee As String
End Structure
Private Declare Function AVIFileOpen Lib "avifil32" Alias "AVIFileOpenA" (ByRef ppfile As Integer, ByVal szFile As String, ByVal mode As Integer, ByVal pclsidHandler As Integer) As Integer
Private Declare Function AVIStreamInfo Lib "avifil32" Alias "AVIStreamInfo" (ByVal pAVIStream As Integer, ByRef pfi As STREAMInfo, ByVal lSize As Integer) As Integer
Private Declare Function AVIFileRelease Lib "avifil32" (ByVal pfile As Integer) As Integer
Private Declare Function AVIFileGetStream Lib "avifil32" Alias "AVIFileGetStream" (ByVal pfile As Integer, ByRef pStream As Integer, ByVal fccType As Integer, ByVal lParam As Integer) As Integer
Private Declare Function AVIFileInfo Lib "avifil32" Alias "AVIFileInfoA" (ByVal pfile As Integer, ByRef pfi As AVIInfo, ByRef lSize As Integer) As Integer
Private Declare Sub AVIFileInit Lib "avifil32" ()
Private Declare Sub AVIFileExit Lib "avifil32" ()
Public movieHeight As Integer
Public movieWidth As Integer
Public frameRate As Decimal
Public Function getFrames(ByVal aviFile As String) As String
Dim hFile As Integer, AviInfo As AviInfo, streamInfo As STREAMInfo
Dim tmp As Integer = 0
AviInfo = Nothing
AVIFileInit()
'create a handle to the AVI file
If AVIFileOpen(hFile, aviFile, OF_SHARE_DENY_WRITE, tmp) = 0 Then
'retrieve the AVI information
If AVIFileInfo(hFile, AviInfo, Len(AviInfo)) = 0 Then
getFrames = CStr(AviInfo.dwLength)
movieHeight = AviInfo.dwHeight
movieWidth = AviInfo.dwWidth
frameRate = Math.Round(AviInfo.dwRate / AviInfo.dwScale, 3)
Else
getFrames = "#Error#"
End If
If AVIFileGetStream(hFile, STREAM, streamtypeAUDIO, 0) = 0 Then
If AVIStreamInfo(STREAM, streamInfo, Marshal.SizeOf(streamInfo)) = 0 Then
MsgBox("->" & streamInfo.fccHandler)
MsgBox("->" & streamInfo.dwRate)
End If
End If
'release the file handle
AVIFileRelease(hFile)
Else
getFrames = "#Error#"
End If
'exit the AVIFile library and decrement the reference count for the
AVIFileExit()
End Function
End Module
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.