---
title: "Camera MJPEG Stream"
description: "Capture, JPEG-encode, and serve a live MJPEG stream from the board over a plain Zephyr BSD TCP socket — ` →  → HTTP multipart/x-mixed-replace`. No host tool is needed: open the URL in a browser."
source: https://docs.alplab.ai/sdk/examples/camera-mjpeg-stream
---

# `camera-mjpeg-stream`

Capture, JPEG-encode, and serve a live MJPEG stream from the board over a plain Zephyr BSD TCP socket — [`<alp/camera.h>`](https://docs.alplab.ai/sdk/api/camera) → [`<alp/jpeg.h>`](https://docs.alplab.ai/sdk/api/jpeg) → HTTP `multipart/x-mixed-replace`. No host tool is needed: open the URL in a browser.

Source: [`examples/connectivity/camera-mjpeg-stream/`](https://github.com/alplabai/alp-sdk/tree/main/examples/connectivity/camera-mjpeg-stream). New in alp-sdk v0.17.0.

:::info[Bench status]
On the E1M-AEN803 the capture → ISP → JPEG → HTTP **pipeline is bench-proven**: 640×480 at the requested 30 fps was delivered end to end (30.03 fps, bright daylight), with 0 CSI/IPI errors; the 1280×960 variants were benched with the OV5647, IMX296 and IMX335 sensors. **Image quality is not** — colour (AWB/CCM) is calibrated only for the OV5647, and the IMX296 / IMX335 variants show the stock colour cast.
:::

## What it does

1. Opens the camera through `<alp/camera.h>` — on the E1M-AEN family that is the VeriSilicon ISP-Pico camera pipeline — and requests 640×480 at 30 fps by default (`CONFIG_CAMERA_MJPEG_STREAM_FPS`).
2. Encodes each frame through `<alp/jpeg.h>`. The app asks the winning JPEG backend at runtime which pixel layouts it accepts (`alp_jpeg_caps_t::pixfmt_mask`), so the same source drives the Alif **Hantro VC9000E** hardware encoder on AEN and the portable software encoder everywhere else.
3. If an encode fails with `ALP_ERR_NOMEM` (the frame came out larger than the output buffer), it retries once at a lower JPEG quality instead of dropping the frame.
4. Serves `GET /stream` (multipart MJPEG) and `GET /snapshot.jpg` on **port 8080**, from its own server thread, with a zero-copy ping-pong hand-off between two SRAM0 buffers.
5. Prints the DHCP lease and both URLs, plus a once-a-second stats line (fps, encoded / failed / retried counts, JPEG size, encode + send time).

**Capability-gated, not SoM-gated.** Any target without a working camera — including `native_sim` — streams a synthetic test-pattern frame through the software JPEG encoder instead, so the same binary always has something to serve.

## `board.yaml`

```yaml
som:
  sku: E1M-AEN803          # Alif Ensemble E8 -- VeriSilicon ISP-Pico +
                            # Hantro VC9000E JPEG hardware encoder.  A SoM
                            # swap to a family with no camera/JPEG backend
                            # still builds and runs: alp_has() steers this
                            # app onto the synthetic-frame fallback path.

preset: e1m-evk

cores:
  a32_cluster:
    os: "off"
  m55_he:
    app: ./src

diagnostics:
  log_level: info
```

There is no `chips:` list: the app reaches the camera and the encoder only through `<alp/camera.h>` + `<alp/jpeg.h>`, gated on `alp_has()`, and the network only through the Zephyr socket API. The capture loop owns the M55-HE on its own because a blocked capture thread starves the ISP's auto-exposure loop.

## Build (E1M-AEN803 + OV5647)

```bash
# A bare west build reads a pre-generated per-core Kconfig fragment (alp-sdk v0.17.0+).
python3 scripts/gen_example_alp_conf.py examples/connectivity/camera-mjpeg-stream
west build -b alp_e1m_aen803_m55_he/ae822fa0e5597ls0/rtss_he \
    examples/connectivity/camera-mjpeg-stream -- -DEXTRA_CONF_FILE=generated/alp.conf \
    "-DEXTRA_ZEPHYR_MODULES=<path-to-alp-sdk>;<path-to-hal_alif>" \
    "-DSHIELD=e1m_evk_rpi_csi raspberry_pi_camera_module_1"
```

Build variants:

| Variant | How | Notes |
|---|---|---|
| 1280×960 | add `boards/overlay-1280x960.conf` to `EXTRA_CONF_FILE` (sets `CONFIG_CAMERA_MJPEG_STREAM_1280X960`) | 15 fps capture/encode request; the HTTP send path, not the encoder, bounds the delivered rate; the synthetic-frame fallback is compiled out to fit SRAM0 |
| IMX296 | 1280×960 overlay + `SHIELD=e1m_evk_rpi_csi raspberry_pi_global_shutter_camera` | No IMX296 colour calibration yet |
| IMX335 | 1280×960 overlay + `SHIELD=e1m_evk_rpi_csi innomaker_cam_imx335` + `-DCONFIG_CAMERA_MJPEG_STREAM_FPS=30` | Must run at 30 fps, the rate its AE envelope was calibrated at; no colour calibration |

With an E1M-AEN hw_rev r2 (2626-R2) on the E1M-EVK, the three MIPI CSI-2 differential pairs arrive with P and N swapped, so these modules need a short P/N-crossing adapter on the 15-pin camera connector — without one the sensor answers its I²C probe but no frame ever arrives.

## Watch it

```bash
# Any modern browser renders the stream URL directly.
vlc http://<ip>:8080/stream
ffmpeg -i http://<ip>:8080/stream -frames:v 300 -f null -   # measure fps over 300 frames
curl -o snapshot.jpg http://<ip>:8080/snapshot.jpg
```

## Expected output

On the board, once the DHCP lease is bound (the address below is from the RFC 5737 documentation range):

```
[camera-mjpeg-stream] DHCP lease = 192.0.2.10
[camera-mjpeg-stream]   stream:   http://192.0.2.10:8080/stream
[camera-mjpeg-stream]   snapshot: http://192.0.2.10:8080/snapshot.jpg
```

On `native_sim` there is no camera and no Ethernet: the app streams the synthetic frame over `CONFIG_NET_LOOPBACK`, and a built-in self-test connects to its own server on `127.0.0.1:8080`, checks the JPEG SOI/EOI markers of `/snapshot.jpg` and the multipart framing of `/stream`, and prints:

```
[camera-mjpeg-stream] selftest ok
```

## Limits

This is a teaching example, not a production camera server:

- **One client at a time** — a second client is queued (or refused once the one-deep backlog is full), not served in parallel.
- **No authentication and no TLS** — plain HTTP; anyone who can reach port 8080 on the LAN sees the stream. It is LAN-only by design.
- **fps is bounded by encode + send time**, not just camera fps: a newly encoded frame is dropped if a `/stream` client is still receiving the previous one.
- **The Ethernet MAC address changes every boot** on AEN — the SoC devicetree default is a random locally-administered address. A fixed MAC needs a per-unit `local-mac-address`, which a shared example cannot carry.

## See also

- [`<alp/camera.h>`](https://docs.alplab.ai/sdk/api/camera) · [`<alp/jpeg.h>`](https://docs.alplab.ai/sdk/api/jpeg)
- [IoT Connected Camera](https://docs.alplab.ai/sdk/examples/iot-connected-camera) — camera → inference → MQTT/TLS
- [AEN bench + bring-up tools](https://docs.alplab.ai/sdk/examples/aen/aen-bench-tools#camera-isp--display) — the raw camera and ISP bench apps underneath this pipeline
- [Examples overview](https://docs.alplab.ai/sdk/examples/overview)
