Voici une petite source geniale extra lissime !
Je l'ai recupérée sur The Code Project et l'ai modifié de maniere a la rendre plus accessible et a ce kelle accepte le son dans le .avi
Cette source utilise DirextX et DirectShow.
ATTENTION: fonctionne avec DX9 et DX8.1.
Les 2 DLL fournit possedent leur source en C# si besoin IM moi.
Source / Exemple :
Imports DirectX.Capture
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
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
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ComboBox2 As System.Windows.Forms.ComboBox
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.ComboBox2 = New System.Windows.Forms.ComboBox()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Location = New System.Drawing.Point(60, 16)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(368, 21)
Me.ComboBox1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(60, 60)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(368, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Valider la configuration"
'
'ComboBox2
'
Me.ComboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox2.Location = New System.Drawing.Point(60, 36)
Me.ComboBox2.Name = "ComboBox2"
Me.ComboBox2.Size = New System.Drawing.Size(368, 21)
Me.ComboBox2.TabIndex = 2
'
'Panel1
'
Me.Panel1.BackColor = System.Drawing.Color.Black
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Panel1.Location = New System.Drawing.Point(84, 128)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(320, 240)
Me.Panel1.TabIndex = 3
Me.Panel1.Visible = False
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(84, 376)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 4
Me.Button2.Text = "Start"
'
'Button3
'
Me.Button3.Enabled = False
Me.Button3.Location = New System.Drawing.Point(328, 376)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 5
Me.Button3.Text = "Stop"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.ForeColor = System.Drawing.Color.Red
Me.Label1.Location = New System.Drawing.Point(80, 224)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(328, 23)
Me.Label1.TabIndex = 6
Me.Label1.Text = "Enregistrement en cours ..."
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.Label1.Visible = False
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(492, 429)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.Button3, Me.Button2, Me.Panel1, Me.ComboBox2, Me.Button1, Me.ComboBox1})
Me.Name = "Form1"
Me.Text = "Choisir la caméra"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim j As Short
Dim f As Filter
'listage des peripheriques video installés sur la machine
ComboBox1.Items.Clear()
For j = 0 To Dispositivos.VideoInputDevices.Count - 1
f = Dispositivos.VideoInputDevices(j)
ComboBox1.Items.Add(f.Name)
Next
If j > 0 Then ComboBox1.SelectedIndex = 0
'listage des peripheriques audio installés sur la machine
ComboBox2.Items.Clear()
For j = 0 To Dispositivos.AudioInputDevices.Count - 1
f = Dispositivos.AudioInputDevices(j)
ComboBox2.Items.Add(f.Name)
Next
If j > 0 Then ComboBox2.SelectedIndex = 0
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'pre configuration du capturing
'definission de la camera
CaptureInformation.Camera = Dispositivos.VideoInputDevices(ComboBox1.SelectedIndex)
'mise en place du stream video et audio
CaptureInformation.CaptureInfo = New Capture(CaptureInformation.Camera, Dispositivos.AudioInputDevices(ComboBox2.SelectedIndex))
'renseignement du panneau d'affichage de la video
CaptureInformation.CaptureInfo.PreviewWindow = Panel1
'compteur pour les capture d'image (frame video)
CaptureInformation.Counter = 1
CaptureInformation.CounterFrames = 1
'configurations avancées
Configurer()
'pour faire plus joli
Button1.Enabled = False
Panel1.Visible = True
End Sub
Private Sub Configurer()
'configurations avancées
'configuration du systeme de compression video et audio
CaptureInformation.CaptureInfo.VideoCompressor = Dispositivos.VideoCompressors(0) 'compression video
'taille de la video
CaptureInformation.CaptureInfo.FrameSize = New Size(320, 240) 'taille de la video
'FPS de la video
CaptureInformation.CaptureInfo.FrameRate = 15 'FPS
'fichier .avi
CaptureInformation.CaptureInfo.Filename = Application.StartupPath + "\\essai.avi"
'lancement du streaming d'affichage
CaptureInformation.CaptureInfo.RenderPreview()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'demarage du streaming avec enregistrement dans le .avi
CaptureInformation.CaptureInfo.Start()
'pour faire plus joli
Button2.Enabled = False
Button3.Enabled = True
Panel1.Visible = False
Label1.Visible = True
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'arret du streaming
CaptureInformation.CaptureInfo.Stop()
'relancement de la configuration et de laffichage video
Configurer()
'encore pour faire plus jolie
Panel1.Visible = True
Button2.Enabled = True
Button3.Enabled = False
Panel1.Visible = True
Label1.Visible = False
End Sub
End Class
Conclusion :
Zip In The Mix
PS: pour plus de detail sur le fonctionnement, ou pour voir comment lancer la configuration de la camera allez voir sur The Code Project
PS2: EDITEZ LA SOURCE AVANT DE LA LANCER POUR LA CONFIGURER
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.