日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

如何使用Windows Media Encoder抓取攝象頭視頻并且保存為視頻文件??

如何使用Windows Media Encoder抓取攝象頭視頻并且保存為視頻文件??[問題點(diǎn)數(shù):100,結(jié)帖人:luguanxiang]

  • luguanxiang
  • (黑虎)
  • 等 級(jí):
  • 結(jié)帖率:

樓主發(fā)表于:2005-08-07 22:34:32
如何使用Windows   Media   Encoder抓取攝象頭視頻并且保存為視頻文件??

想做一個(gè)可以錄制視頻到文件的程序。

我參考了Windows   Media   Encoder   9   Series   SDK,但目前還是沒有什么頭緒。請(qǐng)教各位了。


  • bitsbird用戶頭像
  • bitsbird
  • (一瓢 在路上...)
  • 等 級(jí):
  • 2

#1樓 得分:20回復(fù)于:2005-08-07 22:45:18
http://www./cs/media/ChangeVideoSigFormat.asp

#2樓 得分:80回復(fù)于:2005-08-08 08:12:38
可以不用Windows   Media   Encoder吧?
下面是cam.vb:
Imports   System
Imports   System.Runtime.InteropServices
Imports   System.Drawing
Imports   System.Drawing.Imaging

Public   Class   Cam

        Private   Const   WM_USER   As   Integer   =   &H400
        Private   Const   WS_CHILD   As   Integer   =   &H40000000
        Private   Const   WS_VISIBLE   As   Integer   =   &H10000000
        Private   Const   WM_CAP_START   As   Integer   =   WM_USER
        Private   Const   WM_CAP_STOP   As   Integer   =   WM_CAP_START   +   68
        Private   Const   WM_CAP_DRIVER_CONNECT   As   Integer   =   WM_CAP_START   +   10
        Private   Const   WM_CAP_DRIVER_DISCONNECT   As   Integer   =   WM_CAP_START   +   11
        Private   Const   WM_CAP_SAVEDIB   As   Integer   =   WM_CAP_START   +   25
        Private   Const   WM_CAP_GRAB_FRAME   As   Integer   =   WM_CAP_START   +   60
        Private   Const   WM_CAP_SEQUENCE   As   Integer   =   WM_CAP_START   +   62
        Private   Const   WM_CAP_FILE_SET_CAPTURE_FILEA   As   Integer   =   WM_CAP_START   +   20
        Private   Const   WM_CAP_SEQUENCE_NOFILE   As   Integer   =   WM_CAP_START   +   63
        Private   Const   WM_CAP_SET_OVERLAY   As   Integer   =   WM_CAP_START   +   51
        Private   Const   WM_CAP_SET_PREVIEW   As   Integer   =   WM_CAP_START   +   50
        Private   Const   WM_CAP_SET_CALLBACK_VIDEOSTREAM   As   Integer   =   WM_CAP_START   +   6
        Private   Const   WM_CAP_SET_CALLBACK_ERROR   As   Integer   =   WM_CAP_START   +   2
        Private   Const   WM_CAP_SET_CALLBACK_STATUSA   As   Integer   =   WM_CAP_START   +   3
        Private   Const   WM_CAP_SET_CALLBACK_FRAME   As   Integer   =   WM_CAP_START   +   5
        Private   Const   WM_CAP_SET_SCALE   As   Integer   =   WM_CAP_START   +   53
        Private   Const   WM_CAP_SET_PREVIEWRATE   As   Integer   =   WM_CAP_START   +   52

        Public   Const   WM_CAP_GET_CAPSTREAMPTR   =   WM_CAP_START   +   1

        Public   Const   WM_CAP_SET_CALLBACK_STATUS   =   WM_CAP_START   +   3
        Public   Const   WM_CAP_SET_CALLBACK_YIELD   =   WM_CAP_START   +   4
        Public   Const   WM_CAP_SET_CALLBACK_WAVESTREAM   =   WM_CAP_START   +   7
        Public   Const   WM_CAP_GET_USER_DATA   =   WM_CAP_START   +   8
        Public   Const   WM_CAP_SET_USER_DATA   =   WM_CAP_START   +   9

        Public   Const   WM_CAP_DRIVER_GET_NAME   =   WM_CAP_START   +   12
        Public   Const   WM_CAP_DRIVER_GET_VERSION   =   WM_CAP_START   +   13
        Public   Const   WM_CAP_DRIVER_GET_CAPS   =   WM_CAP_START   +   14

        Public   Const   WM_CAP_FILE_SET_CAPTURE_FILE   =   WM_CAP_START   +   20
        Public   Const   WM_CAP_FILE_GET_CAPTURE_FILE   =   WM_CAP_START   +   21
        Public   Const   WM_CAP_FILE_ALLOCATE   =   WM_CAP_START   +   22
        Public   Const   WM_CAP_FILE_SAVEAS   =   WM_CAP_START   +   23
        Public   Const   WM_CAP_FILE_SET_INFOCHUNK   =   WM_CAP_START   +   24
        Public   Const   WM_CAP_FILE_SAVEDIB   =   WM_CAP_START   +   25

        Public   Const   WM_CAP_EDIT_COPY   =   WM_CAP_START   +   30

        Public   Const   WM_CAP_SET_AUDIOFORMAT   =   WM_CAP_START   +   35
        Public   Const   WM_CAP_GET_AUDIOFORMAT   =   WM_CAP_START   +   36

        Public   Const   WM_CAP_DLG_VIDEOFORMAT   =   WM_CAP_START   +   41
        Public   Const   WM_CAP_DLG_VIDEOSOURCE   =   WM_CAP_START   +   42
        Public   Const   WM_CAP_DLG_VIDEODISPLAY   =   WM_CAP_START   +   43
        Public   Const   WM_CAP_GET_VIDEOFORMAT   =   WM_CAP_START   +   44
        Public   Const   WM_CAP_SET_VIDEOFORMAT   =   WM_CAP_START   +   45
        Public   Const   WM_CAP_DLG_VIDEOCOMPRESSION   =   WM_CAP_START   +   46

        Public   Const   WM_CAP_GET_STATUS   =   WM_CAP_START   +   54
        Public   Const   WM_CAP_SET_SCROLL   =   WM_CAP_START   +   55

        Public   Const   WM_CAP_GRAB_FRAME_NOSTOP   =   WM_CAP_START   +   61

        Public   Const   WM_CAP_SET_SEQUENCE_SETUP   =   WM_CAP_START   +   64
        Public   Const   WM_CAP_GET_SEQUENCE_SETUP   =   WM_CAP_START   +   65
        Public   Const   WM_CAP_SET_MCI_DEVICE   =   WM_CAP_START   +   66
        Public   Const   WM_CAP_GET_MCI_DEVICE   =   WM_CAP_START   +   67
        Public   Const   WM_CAP_ABORT   =   WM_CAP_START   +   69

        Public   Const   WM_CAP_SINGLE_FRAME_OPEN   =   WM_CAP_START   +   70
        Public   Const   WM_CAP_SINGLE_FRAME_CLOSE   =   WM_CAP_START   +   71
        Public   Const   WM_CAP_SINGLE_FRAME   =   WM_CAP_START   +   72

        Public   Const   WM_CAP_PAL_OPEN   =   WM_CAP_START   +   80
        Public   Const   WM_CAP_PAL_SAVE   =   WM_CAP_START   +   81
        Public   Const   WM_CAP_PAL_PASTE   =   WM_CAP_START   +   82
        Public   Const   WM_CAP_PAL_AUTOCREATE   =   WM_CAP_START   +   83
        Public   Const   WM_CAP_PAL_MANUALCREATE   =   WM_CAP_START   +   84

        '//   Following   added   post   VFW   1.1
        Public   Const   WM_CAP_SET_CALLBACK_CAPCONTROL   =   WM_CAP_START   +   85

        '//   Defines   end   of   the   message   range
        Public   Const   WM_CAP_END   =   WM_CAP_SET_CALLBACK_CAPCONTROL

        Private   hWndC   As   IntPtr
        Private   bStat   As   Boolean   =   False

        Private   mControlPtr   As   IntPtr
        Private   mWidth   As   Integer
        Private   mHeight   As   Integer
        Private   mLeft   As   Integer
        Private   mTop   As   Integer

        <DllImport( "avicap32.dll ")>   _
        Private   Shared   Function   capCreateCaptureWindowA(ByVal   lpszWindowName()   As   Byte,   ByVal   dwStyle   As   Integer,   ByVal   x   As   Integer,   ByVal   y   As   Integer,   ByVal   nWidth   As   Integer,   ByVal   nHeight   As   Integer,   ByVal   hWndParent   As   IntPtr,   ByVal   nID   As   Integer)   As   IntPtr
        End   Function

        <DllImport( "avicap32.dll ")>   _
        Private   Shared   Function   capGetVideoFormat(ByVal   hWnd   As   IntPtr,   ByVal   psVideoFormat   As   IntPtr,   ByVal   wSize   As   Integer)   As   Integer
        End   Function

        <DllImport( "User32.dll ")>   _
        Private   Shared   Function   SendMessage(ByVal   hWnd   As   IntPtr,   ByVal   wMsg   As   Integer,   ByVal   wParam   As   Integer,   ByVal   lParam   As   Long)   As   Boolean
        End   Function

        Function   capDlgVideoFormat()   As   Boolean
                capDlgVideoFormat   =   SendMessage(hWndC,   WM_CAP_DLG_VIDEOFORMAT,   0,   0)
        End   Function
        Function   capDlgVideoSource()   As   Boolean
                capDlgVideoSource   =   SendMessage(hWndC,   WM_CAP_DLG_VIDEOSOURCE,   0,   0)
        End   Function
        Function   capDlgVideoDisplay()   As   Boolean
                capDlgVideoDisplay   =   SendMessage(hWndC,   WM_CAP_DLG_VIDEODISPLAY,   0,   0)
        End   Function
        Function   capDlgVideoCompression()   As   Boolean
                capDlgVideoCompression   =   SendMessage(hWndC,   WM_CAP_DLG_VIDEOCOMPRESSION,   0,   0)
        End   Function

        '///   <summary>
        '///   初始化攝像頭
        '///   </summary>
        '///   <param   name= "handle "> 控件的句柄 </param>
        '///   <param   name= "left "> 開始顯示的左邊距 </param>
        '///   <param   name= "top "> 開始顯示的上邊距 </param>
        '///   <param   name= "width "> 要顯示的寬度 </param>
        '///   <param   name= "height "> 要顯示的長(zhǎng)度 </param>
        Public   Sub   New(ByVal   handle   As   IntPtr,   ByVal   left   As   Integer,   ByVal   top   As   Integer,   ByVal   width   As   Integer,   ByVal   height   As   Integer)
                mControlPtr   =   handle
                mWidth   =   width
                mHeight   =   height
                mLeft   =   left
                mTop   =   top
        End   Sub

#3樓 得分:0回復(fù)于:2005-08-08 08:12:51

        '///   <summary>
        '///   開始顯示圖像
        '///   </summary>
        Public   Sub   Start()
                If   bStat   Then
                        Return
                End   If
                bStat   =   True
                Dim   lpszName(99)   As   Byte

                hWndC   =   capCreateCaptureWindowA(lpszName,   WS_CHILD   Or   WS_VISIBLE,   mLeft,   mTop,   mWidth,   mHeight,   mControlPtr,   0)

                If   hWndC.ToInt32()   <>   0   Then
                        SendMessage(hWndC,   WM_CAP_SET_CALLBACK_VIDEOSTREAM,   0,   0)
                        SendMessage(hWndC,   WM_CAP_SET_CALLBACK_ERROR,   0,   0)
                        SendMessage(hWndC,   WM_CAP_SET_CALLBACK_STATUSA,   0,   0)
                        SendMessage(hWndC,   WM_CAP_DRIVER_CONNECT,   0,   0)
                        SendMessage(hWndC,   WM_CAP_SET_SCALE,   1,   0)
                        SendMessage(hWndC,   WM_CAP_SET_PREVIEWRATE,   66,   0)
                        SendMessage(hWndC,   WM_CAP_SET_OVERLAY,   1,   0)
                        SendMessage(hWndC,   WM_CAP_SET_PREVIEW,   1,   0)
                End   If

                Return
        End   Sub

        '///   <summary>
        '///   停止顯示
        '///   </summary>
        Public   Sub   [Stop]()
                SendMessage(hWndC,   WM_CAP_DRIVER_DISCONNECT,   0,   0)
                bStat   =   False
        End   Sub

        '///   <summary>
        '///   抓圖
        '///   </summary>
        '///   <param   name= "path "> 要保存bmp文件的路徑 </param>
        Public   Sub   GrabImage(ByVal   path   As   String)
                Dim   hBmp   As   IntPtr   =   Marshal.StringToHGlobalAnsi(path)
                SendMessage(hWndC,   WM_CAP_SAVEDIB,   0,   hBmp.ToInt64())
        End   Sub

        '///   <summary>
        '///   錄像
        '///   </summary>
        '///   <param   name= "path "> 要保存avi文件的路徑 </param>
        Public   Sub   Kinescope(ByVal   path   As   String)
                Dim   hBmp   As   IntPtr   =   Marshal.StringToHGlobalAnsi(path)
                SendMessage(hWndC,   WM_CAP_FILE_SET_CAPTURE_FILEA,   0,   hBmp.ToInt64())
                SendMessage(hWndC,   WM_CAP_SEQUENCE,   0,   0)
        End   Sub

        '///   <summary>
        '///   停止錄像
        '///   </summary>
        Public   Sub   StopKinescope()
                SendMessage(hWndC,   WM_CAP_STOP,   0,   0)
        End   Sub
End   Class

#4樓 得分:0回復(fù)于:2005-08-08 08:13:15
下面是   Form1.vb

Public   Class   Form1
        Inherits   System.Windows.Forms.Form

        Private   cccap   As   Cam
#Region   "   Windows   窗體設(shè)計(jì)器生成的代碼   "

        Public   Sub   New()
                MyBase.New()

                '該調(diào)用是   Windows   窗體設(shè)計(jì)器所必需的。
                InitializeComponent()

                '在   InitializeComponent()   調(diào)用之后添加任何初始化

        End   Sub

        '窗體重寫   dispose   以清理組件列表。
        Protected   Overloads   Overrides   Sub   Dispose(ByVal   disposing   As   Boolean)
                If   disposing   Then
                        If   Not   (components   Is   Nothing)   Then
                                components.Dispose()
                        End   If
                End   If
                MyBase.Dispose(disposing)
        End   Sub

        'Windows   窗體設(shè)計(jì)器所必需的
        Private   components   As   System.ComponentModel.IContainer

        '注意:   以下過程是   Windows   窗體設(shè)計(jì)器所必需的
        '可以使用   Windows   窗體設(shè)計(jì)器修改此過程。
        '不要使用代碼編輯器修改它。
        Friend   WithEvents   Button1   As   System.Windows.Forms.Button
        Friend   WithEvents   picView   As   System.Windows.Forms.PictureBox
        Friend   WithEvents   Button2   As   System.Windows.Forms.Button
        Friend   WithEvents   Button3   As   System.Windows.Forms.Button
        Friend   WithEvents   Button4   As   System.Windows.Forms.Button
        Friend   WithEvents   Button5   As   System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()>   Private   Sub   InitializeComponent()
                Me.picView   =   New   System.Windows.Forms.PictureBox
                Me.Button1   =   New   System.Windows.Forms.Button
                Me.Button2   =   New   System.Windows.Forms.Button
                Me.Button3   =   New   System.Windows.Forms.Button
                Me.Button4   =   New   System.Windows.Forms.Button
                Me.Button5   =   New   System.Windows.Forms.Button
                Me.SuspendLayout()
                '
                'picView
                '
                Me.picView.Anchor   =   CType((((System.Windows.Forms.AnchorStyles.Top   Or   System.Windows.Forms.AnchorStyles.Bottom)   _
                                        Or   System.Windows.Forms.AnchorStyles.Left)   _
                                        Or   System.Windows.Forms.AnchorStyles.Right),   System.Windows.Forms.AnchorStyles)
                Me.picView.Location   =   New   System.Drawing.Point(16,   16)
                Me.picView.Name   =   "picView "
                Me.picView.Size   =   New   System.Drawing.Size(640,   480)
                Me.picView.TabIndex   =   0
                Me.picView.TabStop   =   False
                '
                'Button1
                '
                Me.Button1.Anchor   =   CType((System.Windows.Forms.AnchorStyles.Bottom   Or   System.Windows.Forms.AnchorStyles.Left),   System.Windows.Forms.AnchorStyles)
                Me.Button1.Location   =   New   System.Drawing.Point(244,   540)
                Me.Button1.Name   =   "Button1 "
                Me.Button1.Size   =   New   System.Drawing.Size(56,   24)
                Me.Button1.TabIndex   =   1
                Me.Button1.Text   =   "start "
                '
                'Button2
                '
                Me.Button2.Anchor   =   CType((System.Windows.Forms.AnchorStyles.Bottom   Or   System.Windows.Forms.AnchorStyles.Left),   System.Windows.Forms.AnchorStyles)
                Me.Button2.Location   =   New   System.Drawing.Point(304,   540)
                Me.Button2.Name   =   "Button2 "
                Me.Button2.Size   =   New   System.Drawing.Size(56,   24)
                Me.Button2.TabIndex   =   1
                Me.Button2.Text   =   "stop "
                '
                'Button3
                '
                Me.Button3.Anchor   =   CType((System.Windows.Forms.AnchorStyles.Bottom   Or   System.Windows.Forms.AnchorStyles.Left),   System.Windows.Forms.AnchorStyles)
                Me.Button3.Location   =   New   System.Drawing.Point(380,   540)
                Me.Button3.Name   =   "Button3 "
                Me.Button3.Size   =   New   System.Drawing.Size(56,   24)
                Me.Button3.TabIndex   =   1
                Me.Button3.Text   =   "cap "
                '
                'Button4
                '
                Me.Button4.Anchor   =   CType((System.Windows.Forms.AnchorStyles.Bottom   Or   System.Windows.Forms.AnchorStyles.Left),   System.Windows.Forms.AnchorStyles)
                Me.Button4.Location   =   New   System.Drawing.Point(352,   508)
                Me.Button4.Name   =   "Button4 "
                Me.Button4.Size   =   New   System.Drawing.Size(124,   24)
                Me.Button4.TabIndex   =   1
                Me.Button4.Text   =   "色彩校正 "
                '
                'Button5
                '
                Me.Button5.Anchor   =   CType((System.Windows.Forms.AnchorStyles.Bottom   Or   System.Windows.Forms.AnchorStyles.Left),   System.Windows.Forms.AnchorStyles)
                Me.Button5.Location   =   New   System.Drawing.Point(164,   512)
                Me.Button5.Name   =   "Button5 "
                Me.Button5.Size   =   New   System.Drawing.Size(124,   24)
                Me.Button5.TabIndex   =   1
                Me.Button5.Text   =   "畫面大小 "
                '
                'Form1
                '
                Me.AutoScaleBaseSize   =   New   System.Drawing.Size(6,   14)
                Me.ClientSize   =   New   System.Drawing.Size(792,   573)
                Me.Controls.Add(Me.Button1)
                Me.Controls.Add(Me.picView)
                Me.Controls.Add(Me.Button2)
                Me.Controls.Add(Me.Button3)
                Me.Controls.Add(Me.Button4)
                Me.Controls.Add(Me.Button5)
                Me.Name   =   "Form1 "
                Me.Text   =   "Form1 "
                Me.ResumeLayout(False)

        End   Sub

#End   Region

        Private   Sub   Form1_Load(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   MyBase.Load
                cccap   =   New   Cam(picView.Handle,   0,   0,   picView.Width,   picView.Height)
        End   Sub

        Private   Sub   Button1_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button1.Click
                cccap.Start()
        End   Sub

        Private   Sub   Button2_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button2.Click
                cccap.Stop()
        End   Sub

        Private   Sub   Button3_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button3.Click
                cccap.GrabImage( "c:\test.bmp ")
        End   Sub

        Private   Sub   Form1_Closed(ByVal   sender   As   Object,   ByVal   e   As   System.EventArgs)   Handles   MyBase.Closed
                cccap   =   Nothing
        End   Sub

        Private   Sub   Button4_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button4.Click
                cccap.capDlgVideoSource()
        End   Sub

        Private   Sub   Button5_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button5.Click
                cccap.capDlgVideoFormat()
        End   Sub
End   Class

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多