[blue]Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Const SRCCOPY = &HCC0020
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Boundingbox As RECT
Private Sub Main_Click()
ThumbnailFrame 60, "c:\downloads\video1.avi", "C:\Downloads\test.bmp" [green]' By default MCI is working in frames rather than time[/green]
End Sub
Private Sub ThumbnailFrame(frame As Long, strVideoFile As String, strThumbname As String)
GetVideo strVideoFile
MoveToFrame frame [green]' actually, this will be nearest keyframe under default settings [/green]
ThumbNail strThumbname
End Sub
Private Sub GetVideo(strFilename As String)
mciSendString "close avi", 0, 0, 0
mciSendString "open " & strFilename & " type mpegvideo alias avi parent " & Picture1.hwnd & " style child", 0, 0, 0
mciSendString "put avi client at " & RECTtoStr(Boundingbox), 0, 0, 0 ' Scale it
End Sub
Private Sub MoveToFrame(frame As Long)
mciSendString "play avi from " & frame & " to " & frame, 0, 0, 0
End Sub
Private Sub ThumbNail(strFilename)
Dim framehwnd As Long
Dim result As String
Dim chars As Long
result = Space(255)
chars = 255
mciSendString "status avi window handle", result, chars, 0& [green]' get handle to window displaying frame buffer[/green]
framehwnd = Val(result)
If framehwnd Then
With Boundingbox
BitBlt Picture2.hdc, .Top, .Left, .Right, .Bottom, GetDC(framehwnd), 0, 0, SRCCOPY [green]' since we resized the input we do not need stretchblt[/green]
End With
End If
SavePicture Picture2.Image, strFilename
End Sub
Private Sub Form_Load()
' Some simple initialisation
'filename = "C:\Downloads\video1.avi"
With Boundingbox
.Left = 0
.Top = 0
.Right = 100
.Bottom = 100
End With
Picture2.BorderStyle = 0
Picture2.Move Picture1.Left + Picture1.Width, Picture1.Top, 100 * Screen.TwipsPerPixelX, 100 * Screen.TwipsPerPixelY
End Sub
Private Function RECTtoStr(srcRect As RECT) As String
RECTtoStr = srcRect.Left & " " & srcRect.Top & " " & srcRect.Right & " " & srcRect.Bottom
End Function[/blue]