IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

[C#] capture video


Sujet :

C#

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut [C#] capture audio
    Bonjour à tous,
    J'aimerais savoir si le framework .net propose des classes permettant de capturer un flux vidéo.
    Comment s'y prendre pour par exemple capturer le contenu d'un rectangle défini sur l'écran.

    Merci pour votre aide !!

  2. #2
    Membre chevronné Avatar de bouvda
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    252
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2005
    Messages : 252
    Par défaut
    Bonjour,

    il y a des sources qui pourrait t'aider sur developpez :
    http://dotnet.developpez.com/sources...#CaptureScreen

    Les fonctions utilisées ne sont pas forcément issues du framework.
    Avec le framework, il est possible de faire une capture d'écran en passant par la méthode CopyFromScreen d'une instance de Graphics obtenue à partir d'une instance de Bitmap.
    Il y a un exemple ici : http://www.geekpedia.com/tutorial181...ng-Csharp.html

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut
    Merci pour ta réponse bouvda, mais au lieu d'une capture d'écran, je voudrais faire du streaming.
    Dois-je passer par directX ?

  4. #4
    Membre chevronné Avatar de bouvda
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    252
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2005
    Messages : 252
    Par défaut
    Citation Envoyé par LE NEINDRE
    Merci pour ta réponse bouvda, mais au lieu d'une capture d'écran, je voudrais faire du streaming.
    Dois-je passer par directX ?
    En effet je pense qu'avec DirectShow cela doit être possible.
    Essaies de regarder sur www.codeproject.com il doit y avoir des projets qui portent sur ce sujet.

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut
    ok, merci !!! Je vais me renseigner sur ça alors !!

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut
    Alors voilà, j'ai trouvé une dll pas mal sur codeProject.
    Mais j'ai un gros souci, il ne me reconnais aucun device audio ou vidéo.
    L'erreur procient à cet endroit

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
     
            private void Form1_Load(object sender, EventArgs e)
            {
                try
                {
                    Filters f = new Filters();
                }
                catch (Exception e0)
                {
                    MessageBox.Show(e0.Message);
                }
     
            }
    et j'ai comme erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    no devices of the category
    Quelq'un a t'il déjà utliser cette dll ? quel peut êtr ele problème ???

    Merci pour vos réponses !!!

  7. #7
    Membre chevronné Avatar de bouvda
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    252
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2005
    Messages : 252
    Par défaut
    Bonjour,

    cela ressemble à DirectX.Capture. Si c'est ce que tu utilises, il me semble que ça ne permet de capturer des flux vidéos que sur des périphériques d'entrée comme une webcam par exemple. Tu as donc ce message s'il n'y a aucun périphérique de la sorte connecté à l'ordinateur.

    Si tu ne trouves pas de quoi faire ton bonheur pour capturer ce qu'il se passe à l'écran, tu peux toujours faire des captures d'écran à une certaine fréquence et recomposer la vidéo.

  8. #8
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut
    Oui c'est cette dll que j'utilise.
    Et j'ai bien l'impression qu'il faut lui mettre une webcam ou autre pour qu'il trouve.

    Pour l'instant je pars uniquement sur la capture du son.
    Je zappe pour le moment l'utilisation de la ddl DirectX.Capture et je suis en train de regarder du côté de Microsoft.DirectX.DirectSound et Microsoft.DirectX.DirectInput

    Reste à savoir comment on fait pour capturer un son sur une carte.

    Voilà où j'en suis pour le moment, ça va pas bien loin mais je récupére au moins les infos des cartes de mon PC.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
     
    ...
    using Microsoft.DirectX.DirectSound;
    using Microsoft.DirectX.DirectInput;
    namespace testAudio
    {
        public partial class Form1 : Form
        {
            private AudioList<DeviceInformation> _audioList;
     
            public AudioList<DeviceInformation> audioList
            {
                get { return _audioList; }
                set { _audioList = value; }
            }
     
            public Form1()
            {
                InitializeComponent();
                audioList = new AudioList<DeviceInformation>();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                try
                {
                    comboBox1.Items.Clear();
                    DevicesCollection devList = new DevicesCollection();
                    foreach (Microsoft.DirectX.DirectSound.DeviceInformation d in devList)
                    {
                         audioList.Add(d);
                         comboBox1.Items.Add(d.Description);
                    }
                }
                catch (Exception e0)
                {
                    MessageBox.Show(e0.Message);
                }
     
            }
     
            private void B_CAPTURE_Click(object sender, EventArgs e)
            {
                //MessageBox.Show(audioList[comboBox1.SelectedIndex]);
                Microsoft.DirectX.DirectSound.Device d = new Microsoft.DirectX.DirectSound.Device(audioList[comboBox1.SelectedIndex].DriverGuid);
                //Microsoft.DirectX.DirectInput.Device input_d = new Microsoft.DirectX.DirectInput.Device(audioList[comboBox1.SelectedIndex].DriverGuid);
     
            }
        }
     
     
        public class AudioList<T> : List<T>
        {
            public AudioList()
            {
     
            }
        }
    }
    une idée pour capturer ce qu'il passe pour une carte ????

  9. #9
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Par défaut
    J'ai trouvé ceci sur le net :
    http://msdn2.microsoft.com/fr-fr/lib...84(vs.80).aspx

    En espereant que cela puisse t'aider

  10. #10
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut
    Bon,
    j'ai trouvé quelques sources, dont une ci-dessous.
    le tableau de bytes capturé est mis dans un fichier wav.
    malheuresement, lle fichier wav ne semble pas valide mais il comporte bien des données.
    Ci-dessous, le code est le fichier wav obtenu
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
     
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using DShowNET;
    using Microsoft.DirectX.DirectSound;
    using Microsoft.DirectX.DirectInput;
    using System.IO;
     
     
     
     
     
    namespace testAudio
    {
        public partial class Form1 : Form
        {
            private AudioList<DeviceInformation> _audioList;
     
            private Microsoft.DirectX.DirectSound.Device device;
            private Microsoft.DirectX.DirectSound.Capture capture;
            private Microsoft.DirectX.DirectSound.Buffer buffer;
            private BufferDescription bufferDescription;
            private CaptureBuffer captureBuffer;
            private WaveFormat waveFormat;
            private CaptureBufferDescription captureBufferDescription;
     
            private MemoryStream stream;
            private byte[] streamBuffer;
            private FileStream fs;
            private BinaryWriter stw;
     
     
     
            public AudioList<DeviceInformation> audioList
            {
                get { return _audioList; }
                set { _audioList = value; }
            }
     
            public Form1()
            {
                InitializeComponent();
                audioList = new AudioList<DeviceInformation>();
     
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                try
                {
                    comboBox1.Items.Clear();
                    DevicesCollection devList = new DevicesCollection();
                    foreach (Microsoft.DirectX.DirectSound.DeviceInformation d in devList)
                    {
                         audioList.Add(d);
                         comboBox1.Items.Add(d.Description);
                    }
     
     
                }
                catch (Exception e0)
                {
                    MessageBox.Show(e0.Message);
                }
     
            }
     
     
     
            private void createDevice()
            {
                device = new Microsoft.DirectX.DirectSound.Device(audioList[comboBox1.SelectedIndex].DriverGuid);
            }
            private void createWaveFormat()
            {
                waveFormat = new WaveFormat();
                waveFormat.BitsPerSample = 8;
                waveFormat.BlockAlign = 1;
                waveFormat.Channels = 1;
                waveFormat.AverageBytesPerSecond = 20500;
                waveFormat.SamplesPerSecond = 20500;
                waveFormat.FormatTag = WaveFormatTag.Pcm; 
     
            }
            private void createbufferDescription()
            {
                bufferDescription = new BufferDescription();
                bufferDescription.Format = waveFormat;
                bufferDescription.BufferBytes = 10000;
                bufferDescription.ControlPositionNotify = true;
                bufferDescription.ControlFrequency = true;
                bufferDescription.ControlPan = true;
                bufferDescription.ControlVolume = true; 
     
            }
            private void createBuffer()
            {
                buffer = new Microsoft.DirectX.DirectSound.Buffer(bufferDescription, this.device);
            }
            private void setCooperativeLevel()
            {
                this.device.SetCooperativeLevel(this, CooperativeLevel.Priority);
            }
            private void createCapture()
            {
                capture = new Microsoft.DirectX.DirectSound.Capture();
            }
            private void createCaptureDescription()
            {
                captureBufferDescription = new CaptureBufferDescription();
                captureBufferDescription.BufferBytes = 100000;
                captureBufferDescription.Format = this.waveFormat;
            }
            private void createCaptureBuffer()
            {
                captureBuffer = new CaptureBuffer(captureBufferDescription, capture); 
            }
            private void createStream()
            {
                stream = new MemoryStream(streamBuffer);
            }
            private void createStreamBuffer()
            {
                streamBuffer = new byte[100000];
                for (int i = 0; i < 100000; i++)
                {
                    streamBuffer[i] = 0;
                }
            }
     
     
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                try
                {
     
                    Stream str = new MemoryStream();
                    createDevice();
                    setCooperativeLevel();
                    createWaveFormat();
                    createCapture();
                    createbufferDescription();
                    createBuffer();
                    createCaptureDescription();
                    createCaptureBuffer();
     
                    createStreamBuffer();
                    createStream();
     
                    fs = new FileStream(@"c:\son.wav", FileMode.Create);
                    stw = new BinaryWriter(fs);
                    byte[] strBuffer = new byte[100000];
     
                }
                catch (Exception e0)
                {
                    MessageBox.Show(e0.Message);
                }
     
            }
     
     
            private void B_PLAY_Click(object sender, EventArgs e)
            {
                try
                {
     
                    this.captureBuffer.Read(0, this.stream, 100000, LockFlag.None);
                    buffer.Write(0, this.stream, (int)this.stream.Length, LockFlag.EntireBuffer);
                    buffer.Play(0, BufferPlayFlags.Looping);
                    this.stream.Read(streamBuffer,0,(int)stream.Length);
                    stw.Write(streamBuffer);
                    MessageBox.Show("Start play");
                }
                catch (Exception e0)
                {
                    MessageBox.Show(e0.Message);
                }
            }
     
            private void B_STOP_PLAY_Click(object sender, EventArgs e)
            {
                buffer.Stop();
                stw.Close();
                fs.Close();
                MessageBox.Show("Stop play");
     
            }
     
            private void B_START_RECORD_Click(object sender, EventArgs e)
            {
                captureBuffer.Start(true);
                MessageBox.Show("Start record");
            }
     
            private void B_STOP_RECORD_Click(object sender, EventArgs e)
            {
                captureBuffer.Stop();
                MessageBox.Show("Stop record");
            }
     
        }
     
     
        public class AudioList<T> : List<T>
        {
            public AudioList()
            {
     
            }
        }
    }
    Et voici un bout du fichier wav obtenu
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    3KVk|€‹“—š™§µ½ÐÖÞÝÝÔÚÚÚÖÏØÕÖËÊÓÑÒÈÎÎÏÊÅÌÌÉŵwI!
     
    
     
    
    &<lÊÙÖÑÐ×ÓÑËÔÏÒÈËÏÍË¿ÉÊľ¨}H2
     
     
     
    
    
    !T€«ÁÉÌË¿*›—‘ˆ‰ŒŽŽ›*ƒ|_I>
    
    
     
    )J\fz†ŠŒ‹Ž‘”š¨¾ÆÇÜàáÚØÞÜÚÓÛØÙÑÐÖÓÓÆÌÐÐÌÅÌÊ̯•E 2r¾ÓÓÔËËÒÑÒÈÎÏÏÉÉÌÊÊÃÈÀ»¡jE07o“*»ÈÀÅÇ»Š}y}~ŠŽ‹}wgMB1(1Cclu„…„ƒƒ‚‚…š´»Ç×ââáÚÕÞÝßÔØÛÚÕÒÙÕ×ÌÑÔÒÎÄÎÏ®‰i1!*AÐÏ×ÚÛÒÒÙÕÖÉÍÓÓÐÇÌÍÐñ*ƒG 
    5Bb›®»ËÌ˾À²—‹yvvux{…„w]S8

    une idée ???????

  11. #11
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Par défaut
    Et voici un bout du fichier wav obtenu

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    3KVk|€‹“—š™§µ½ÐÖÞÝÝÔÚÚÚÖÏØÕÖËÊÓÑÒÈÎÎÏÊÅÌÌÉŵwI!
     
    
     
    
    &<lÊÙÖÑÐ×ÓÑËÔÏÒÈËÏÍË¿ÉÊľ¨}H2
     
     
     
    
    
    !T€«ÁÉÌË¿*›—‘ˆ‰ŒŽŽ›*ƒ|_I>
    
    
     
    )J\fz†ŠŒ‹Ž‘”š¨¾ÆÇÜàáÚØÞÜÚÓÛØÙÑÐÖÓÓÆÌÐÐÌÅÌÊ̯•E 2r¾ÓÓÔËËÒÑÒÈÎÏÏÉÉÌÊÊÃÈÀ»¡jE07o“*»ÈÀÅÇ»Š}y}~ŠŽ‹}wgMB1(1Cclu„…„ƒƒ‚‚…š´»Ç×ââáÚÕÞÝßÔØÛÚÕÒÙÕ×ÌÑÔÒÎÄÎÏ®‰i1!*AÐÏ×ÚÛÒÒÙÕÖÉÍÓÓÐÇÌÍÐñ*ƒG 
    5Bb›®»ËÌ˾À²—‹yvvux{…„w]S8
    une idée ???????
    Heu.... Tu as ouvert le fichier wav avec notepad pour obtenir cela ??? Je ne pense pas que se soit la bonne façon de faire . En général un wav cela s'écoute .

    Est il invalide à la lecture ? Si non, le son capturer est il correct ?

  12. #12
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Par défaut
    Salut ced600 !

    Oui je l'ai ouvert car le fichier était invalide à la lecture.
    Mais en fait maitenant, ça fonctionne.
    En fait, j'écrivais dans le fichiers les données reçu dans mon buffer, mais je ne mettais pas l'entête du fichier wav en début de fichier, je ne mettais que la data.

    Maintenant, je peux enregistrer environ 20 sec de son par le micro pour environ 400 Ko. En revanche, le volume lorsque j'écoute le fichier wav produit est vraiment très très bas bien que mon micron soit en amplification sonore maximum. Je ne sais pas comment règler ça ?
    Si tu veux, je posterais le code ce soir, si ça t'interesse.

    Prochaine étape, réussir à capter le son "en boucle", une fois que mon memorystream est complétement rempli, le vider et le reremplir avec les nouvelles données. tu crois que c'est faisable ?

  13. #13
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Par défaut
    Avec de la patience et de la volonté tout est possible .
    Je n'ai jamais fait ce genre de chose donc je ne peut pas te donner de piste.
    Le code m'interesse, ce genre de sujet est rare sur le forum, alors ce genre de code aussi .

Discussions similaires

  1. Driver de capture video virtuel en Directx
    Par Lio590 dans le forum DirectX
    Réponses: 2
    Dernier message: 22/01/2005, 12h14
  2. capture video directX9
    Par Tsunamis dans le forum DirectX
    Réponses: 8
    Dernier message: 23/11/2004, 11h49
  3. Capture vidéo d'une application OPENGL
    Par Mathieu.J dans le forum Applications et environnements graphiques
    Réponses: 2
    Dernier message: 10/06/2004, 21h29
  4. Capture video depuis une carte DC30+
    Par Ertai dans le forum MFC
    Réponses: 2
    Dernier message: 19/02/2004, 15h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo