# Utiliser une webcam sur une distribution installée sur WSL 2

## Utiliser une webcam USB

On attache notre webcam USB aux distributions WSL 2 :

{% content-ref url="/pages/AE0V3SBnILPmFEAPxRKQ" %}
[Attacher un périphérique USB aux distributions installées sur WSL 2](/windows/windows-subsystem-for-linux/attacher-un-peripherique-usb-aux-distributions-installees-sur-wsl-2.md)
{% endcontent-ref %}

On ajoute notre utiliser au groupe **video** :

```bash
sudo usermod -aG video $USER
```

On ferme notre session WSL, on la réouvre, et on devrait pouvoir accéder à notre webcam.

## Utiliser une webcam intégrée

On ouvre l'**Invite de commandes** en tant qu'admnistrateur et l'on installe **ffmpeg** :

```batch
winget install ffmpeg
```

On le ferme et on l'ouvre de nouveau en tant qu'administrateur puis on liste les caméras disponibles :

```batch
ffmpeg -list_devices true -f dshow -i dummy
```

On récupère l'IP de la ligne terminant par eth0 sur notre distribution WSL 2 :

```bash
ip addr | grep inet
```

On capture et diffuse en streaming UDP notre caméra depuis l'**Invite de commandes Windows** :

```batch
ffmpeg -f dshow -i video="<NOM DE LA CAMÉRA>" -c:v libx264 -f mpegts udp://<IP DE LA DISTRIBUTION>:11795?pkt_size=1024
```

On peut lire notre flux à l'adresse `udp://@:11795`.

### Problèmes éventuels

Si l'on souhaite accéder au flux depuis un script Python, il pourrait être nécessaire d'installer les bibliothèques suivantes :

```bash
sudo apt install -y \
  libgl1-mesa-dri \
  libgl1-mesa-glx \
  libqt5core5a \
  libqt5gui5 \
  libqt5widgets5 \
  libqt5x11extras5 \
  libsm6 \
  libx11-6 \
  libx11-xcb-dev \
  libxext-dev \
  libxext6 \
  libxkbcommon-x11-0 \
  libxrender-dev \
  libxrender1 \
  libxcb-cursor0 \
  libxcb-icccm4 \
  libxcb-image0 \
  libxcb-keysyms1 \
  libxcb-randr0 \
  libxcb-render-util0 \
  libxcb-util1 \
  libxcb-xfixes0 \
  libxcb-xinerama0 \
  libxcb-xinerama0-dev \
  libxcb1
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledge.jonathan-about.com/windows/windows-subsystem-for-linux/utiliser-une-webcam-sur-une-distribution-installee-sur-wsl-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
