# AMB82-mini http jepg streaming though browser example and optimize suggestions

**URL:** <https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223>\
**Category:** Multimedia\
**Tags:** evb-amb82, rtl8735b\
**Created:** [July 8, 2025, 3:47am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223 "2025-07-08T03:47:09Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmiedave](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jimmiedave](https://forum.amebaiot.com/u/jimmiedave)\
**Post date:** [July 8, 2025, 3:47am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/1 "2025-07-08T03:47:09Z")

</div>

I’ve written a multi-client video-JPEG stream web server (a little one) for the AMB82-MINI. It works pretty well, but the video feed gets pretty jerky.

`client.write(buf, len);` where `client` is of type WiFiClient seems to randomly insert 1 to 4 second pauses in the stream where it should be writing JPEG frames.

I’ve found this by profiling my code, and traced it down to `client.write(buf,len)`, but I don’t have visibility into this code to further diagnose.

I’m seeing errors of type:  
`[Driver]: skb_unavailable=6 in last 2 seconds`  
but they don’t appear closely correlated to these pauses. The errors occasionally show up after the pauses.

Can anyone tell me what would make the stream choke like this? All the frames before and after seem to be delivered rapidly and correctly.

---

<div class="post-metadata">

**Author:** ![jimmiedave](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jimmiedave](https://forum.amebaiot.com/u/jimmiedave)\
**Post date:** [July 9, 2025, 8:03pm UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/2 "2025-07-09T20:03:07Z")

</div>

Further investigation shows that these pauses only occur when what’s being written is the image from the camera (not the IMG\_HEADER or the STREAM\_BOUNDARY text items).

When these pauses occur, I’m sending ` sendChunk(client, (uint8_t*)img_addr, img_len);` from the camera, where img\_addr is the address of the frame to send, and img\_len is the length of the frame. The paused frames are not notably long. The pauses don’t corrolate with the skb\_unavailable errors.

```auto
void CameraView::sendChunk(WiFiClient& client, uint8_t* buf, uint32_t len) {
    uint8_t ch_buf[64] = {0};
    uint8_t ch_len = snprintf((char*)ch_buf, 64, "%lX\r\n", len);
    client.write(ch_buf, ch_len);
    client.write(buf, len);
    client.print("\r\n");
}

```

I’ve removed a _lot_ of junk data from the serial stream below - the frames that go right, the endless "`ERROR] get_available Accept connection failed`"messages that come when the server is not set to blocking mode - and an example log of the long pauses is below.

`prof_b` is the time in milliseconds it took `client.write(buf, len); to execute, and

`prof_c` is the size of the JPEG frame in bytes.

typically (in “working” frames without an extra pause), `prof_b` takes 4 milliseconds, in rare cases up to 10. Unless it’s in an extra pause, shown below. The pauses can reach into the 4,000 milliseconds. During these extra pauses, there’s a noticeable hiccup in the video stream.

I’ve forced the AMB82-MINI to 5GHz WiFi (by filtering the MAC address off my 2.4GHz - verified by looking at the device connections in my router). Still seeing pauses upon frame write.

```auto
prof_b: 1299, prof_c: 39807
[Driver]: skb_unavailable=2 in last 2 seconds
[Driver]: skb_unavailable=24 in last 2 seconds
[Driver]: skb_unavailable=28 in last 2 seconds
[Driver]: skb_unavailable=29 in last 2 seconds
[Driver]: skb_unavailable=30 in last 2 seconds
[Driver]: skb_unavailable=24 in last 2 seconds
[Driver]: skb_unavailable=21 in last 2 seconds
[Driver]: skb_unavailable=9 in last 2 seconds
prof_b: 931, prof_c: 34075
[Driver]: skb_unavailable=21 in last 2 seconds
[Driver]: skb_unavailable=26 in last 2 seconds
[Driver]: skb_unavailable=23 in last 2 seconds
prof_b: 1104, prof_c: 39920
[Driver]: skb_unavailable=5 in last 2 seconds
[Driver]: skb_unavailable=3 in last 2 seconds
[Driver]: skb_unavailable=6 in last 2 seconds
prof_b: 1277, prof_c: 31087
[Driver]: skb_unavailable=1 in last 2 seconds
[Driver]: skb_unavailable=21 in last 2 seconds
[Driver]: skb_unavailable=17 in last 2 seconds
[Driver]: skb_unavailable=12 in last 2 seconds
[Driver]: skb_unavailable=12 in last 2 seconds
prof_b: 1122, prof_c: 31790
[Driver]: skb_unavailable=8 in last 2 seconds
[Driver]: skb_unavailable=14 in last 2 seconds
prof_b: 996, prof_c: 43989

```

---

<div class="post-metadata">

**Author:** ![jimmiedave](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jimmiedave](https://forum.amebaiot.com/u/jimmiedave)\
**Post date:** [July 13, 2025, 7:44pm UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/3 "2025-07-13T19:44:20Z")

</div>

Tried yesterday on a different network: a 5GHz phone hotspot. Same result: random pauses, potentially more than on the local wifi network.

The web service looks tied to the WiFi client - were there a way to use the OTG port as a wired bridge to network, I suppose I still couldn’t eliminate WiFi as a culprit. Am I thinking straight there?

---

<div class="post-metadata">

**Author:** ![Pammy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/pammy/32/936_2.png) [@Pammy](https://forum.amebaiot.com/u/Pammy)\
**Post date:** [September 9, 2025, 8:39am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/4 "2025-09-09T08:39:34Z")

</div>

Hi @jimmiedave ,

Can I check whether your video streams have random pauses when running [ameba-arduino-pro2/Arduino\_package/hardware/libraries/Multimedia/examples/CaptureJPEG/HTTPDisplayJPEGContinuous at dev · Ameba-AIoT/ameba-arduino-pro2 · GitHub](https://github.com/Ameba-AIoT/ameba-arduino-pro2/tree/dev/Arduino_package/hardware/libraries/Multimedia/examples/CaptureJPEG/HTTPDisplayJPEGContinuous) or any examples in [ameba-arduino-pro2/Arduino\_package/hardware/libraries/Multimedia/examples/StreamRTSP at dev · Ameba-AIoT/ameba-arduino-pro2 · GitHub](https://github.com/Ameba-AIoT/ameba-arduino-pro2/tree/dev/Arduino_package/hardware/libraries/Multimedia/examples/StreamRTSP) ?

WiFi could be one of the factors that is causing this issue. Consider reducing the resolution of the video if FHD is not needed.

---

<div class="post-metadata">

**Author:** ![Pammy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/pammy/32/936_2.png) [@Pammy](https://forum.amebaiot.com/u/Pammy)\
**Post date:** [September 10, 2025, 7:57am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/5 "2025-09-10T07:57:13Z")

</div>

May I check if you are using UDP?

---

<div class="post-metadata">

**Author:** ![jimmiedave](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jimmiedave](https://forum.amebaiot.com/u/jimmiedave)\
**Post date:** [September 10, 2025, 11:54am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/6 "2025-09-10T11:54:11Z")

</div>

I can try and re-flash the camera/processor with the demos in a few days, but it’s currently in regular use, dropped-frames and all.

I’m assuming the demos on github will be the same as the latest Arduino update for the AMB82-mini. If not, please let me know what difference I’d be able to expect.

I’m not intentionally using UDP - the code is pseudo-streaming motion JPEG over http, in a manner similar to the example HTTPDisplyJPEGContinuous, though not the same: my application can serve multiple http endpoints simultaneously (though I see these pauses with only a single endpoint connected, as well as with multiple endpoints).

If UDP is in use, it’s nothing I’ve set up; I expect that the http service is using TCP/IP. The internals of the WiFiServer are opaque to me.

_very_ pseudocode:

```auto
  // pick up WiFi Credentials
  getWiFiCreds(path, ssid, wifipw);

  // Connect to WiFi
  WiFi.begin(ssid, wifipw);

```

```auto
  // Start the server
  server.setNonBlockingMode();
  server.begin();

```

```auto
  // parse http request

```

```auto
  // serve http camera image HEAD

```

```auto
 void CameraView::serveChunk(WiFiClient& client) {  
  // get the location and length of this frame data
  myCamera.getImage(CHANNEL, &img_addr, &img_len);
  // clear the buffer
  memset(CameraView::chunk_buf,0,sizeof(CameraView::chunk_buf));
  chunk_len = snprintf((char*)CameraView::chunk_buf, 64, IMG_HEADER, img_len);
  sendChunk(client, CameraView::chunk_buf, chunk_len); // Content-Type: image/jpeg\r\nContent-len: 123456\r\n\r\n, 49
  sendChunk(client, (uint8_t*)img_addr, img_len); // {image data (a frame)}, 123456
  sendChunk(client, (uint8_t*)STREAM_BOUNDARY, strlen(STREAM_BOUNDARY)); // \r\n--123456789000000000000987654321\r\n, 36
  delay(2);
}

void CameraView::sendChunk(WiFiClient& client, uint8_t* buf, uint32_t len) {
    uint8_t ch_buf[64] = {0};
    uint8_t ch_len = snprintf((char*)ch_buf, 64, "%lX\r\n", len);
    client.write(ch_buf, ch_len);
    client.write(buf, len);
    client.print("\r\n");
}

```

It’s been a couple months, but recalling how I cobbled things together, some of the code would’ve been cribbed directly from the JPEG over HTTP example code.

---

<div class="post-metadata">

**Author:** ![jimmiedave](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jimmiedave](https://forum.amebaiot.com/u/jimmiedave)\
**Post date:** [September 13, 2025, 7:31pm UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/7 "2025-09-13T19:31:52Z")

</div>

OK, I’ve spent hours on this today, running the HTTPDisplayJPEGContinuous example (same results, same pauses with smaller frame size, though fewer in number) and optimizing, testing, optimizing some more. Using the 4.10 SDK, updated today in the Arduino IDE

Result: Only a very small improvement. I’ve tested on 2.4GHz and 5GHz wifi, have reduced JPEG quality, have reduced frame rate, have tried a variety of frame sizes (Ideally, I’d like to do FHD, and not go below 720p HD) and cannot get this to go away, and do not see an error message in the serial stream that indicates that it’s happening.

If this is either a WiFi interface capacity or a CPU capacity issue on the AMB82-MINI, I have to ask: what good is a (pretty nice) camera that can do FHD if I can’t get the video off the device?

I’m not using RTSP because I am looking for a solution that can stream directly to a browser, without an intermediate streaming or transcoding server.

Now that Firefox is going to start supporting MKV, it’d be nice to just send an HTML5 video, but doing so as an open-ended stream isn’t something I see documented here; only continuous JPEG.

Is there an OTG interface that can make a wired Ethernet connection to the AMB82-Mini? It seems like there ought to be some way to get video out of it without all the choking.

---

<div class="post-metadata">

**Author:** ![M-ichae-l](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/m-ichae-l/32/33_2.png) [@M-ichae-l](https://forum.amebaiot.com/u/M-ichae-l)\
**Post date:** [September 16, 2025, 9:02am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/8 "2025-09-16T09:02:41Z")

</div>

I tried HTTPDisplayJPEGContinuous with “WiFiServer server(80, TCP\_MODE, NON\_BLOCKING\_MODE);“

error disappeared `[Driver]: skb_unavailable=6 in last 2 seconds`

left the chock/lag issue. let me do more search about this issue. It seems not related with wifi env

---

<div class="post-metadata">

**Author:** ![M-ichae-l](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/m-ichae-l/32/33_2.png) [@M-ichae-l](https://forum.amebaiot.com/u/M-ichae-l)\
**Post date:** [September 17, 2025, 10:08am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/9 "2025-09-17T10:08:36Z")

</div>

> [@jimmiedave](#):
>
> I’ve found this by profiling my code, and traced it down to `client.write(buf,len)`, but I don’t have visibility into this code to further diagnose.

For this further investigate, lets following files

- [WiFiClient.cpp#L203](https://github.com/Ameba-AIoT/ameba-arduino-pro2/blob/0777b25238ab70264617a2d117c0d45cac945acf/Arduino_package/hardware/libraries/WiFi/src/WiFiClient.cpp#L203)
- [server\_drv.cpp#L174](https://github.com/Ameba-AIoT/ameba-arduino-pro2/blob/0777b25238ab70264617a2d117c0d45cac945acf/Arduino_package/hardware/cores/ambpro2/server_drv.cpp#L174)
- [ard\_socket.c#L432](https://github.com/Ameba-AIoT/ameba-arduino-pro2/blob/0777b25238ab70264617a2d117c0d45cac945acf/Arduino_package/hardware/cores/ambpro2/ard_socket.c#L432)

---

<div class="post-metadata">

**Author:** ![jimmiedave](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jimmiedave](https://forum.amebaiot.com/u/jimmiedave)\
**Post date:** [September 18, 2025, 1:40am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/10 "2025-09-18T01:40:30Z")

</div>

I don’t have deep knowledge of the Arduino ecosystem - are these files I can instrument and compile and put on my dev machine, or are you proposing that you’ll look at them?

If I’m to put them on my machine, I’ll need a starting point for getting them from the github repo (I know how to use git clone, etc…) into Arduino and compiled and part of the build code.

---

<div class="post-metadata">

**Author:** ![M-ichae-l](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/m-ichae-l/32/33_2.png) [@M-ichae-l](https://forum.amebaiot.com/u/M-ichae-l)\
**Post date:** [September 18, 2025, 10:24am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/11 "2025-09-18T10:24:22Z")

</div>

Hi @jimmiedave what is your stalls frequency (eg, once every 1min)?  
I have some optimizations update for api tested under demo HTTPDisplayJPEGContinuous

---

<div class="post-metadata">

**Author:** ![jimmiedave](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jimmiedave](https://forum.amebaiot.com/u/jimmiedave)\
**Post date:** [September 19, 2025, 8:44pm UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/12 "2025-09-19T20:44:48Z")

</div>

Testing a few minutes ago: 1 to 4 seconds or so. Makes for very choppy video. This is with my code, which is on the board right now (as I said, it’s in regular use). I can try and put the HTTPDisplayJPEGContinuous example back on sometime soon (seemed to act about the same before).

---

<div class="post-metadata">

**Author:** ![M-ichae-l](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/m-ichae-l/32/33_2.png) [@M-ichae-l](https://forum.amebaiot.com/u/M-ichae-l)\
**Post date:** [September 22, 2025, 11:33am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/13 "2025-09-22T11:33:32Z")

</div>

I have PR some optimize here [github PR](https://github.com/Ameba-AIoT/ameba-arduino-pro2/pull/334).

In my experience, for http jpag some stalls may not 100% avoidable.

---

<div class="post-metadata">

**Author:** ![M-ichae-l](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/m-ichae-l/32/33_2.png) [@M-ichae-l](https://forum.amebaiot.com/u/M-ichae-l)\
**Post date:** [September 25, 2025, 3:29am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/14 "2025-09-25T03:29:15Z")

</div>

There is a new early release, you may want to try this example [HTTPDisplayJPEGContinuousMultitask](https://github.com/Ameba-AIoT/ameba-arduino-pro2/tree/dev/Arduino_package/hardware/libraries/Multimedia/examples/CaptureJPEG/HTTPDisplayJPEGContinuousMultitask)

For standard setup of HTTP JEPG as following, then depends the internet can increase the resolution and fps.

VideoSetting config(640, 480, 15, VIDEO\_JPEG, 1);  
#define FRAME\_INTERVAL (1000 / 15/ portTICK\_PERIOD\_MS)

Small tips of testing internet. Can start both browser and VLC to test. If VLC is ok, it most likely, browser cause this stall issue.

---

<div class="post-metadata">

**Author:** ![M-ichae-l](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/m-ichae-l/32/33_2.png) [@M-ichae-l](https://forum.amebaiot.com/u/M-ichae-l)\
**Post date:** [September 25, 2025, 8:47am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/15 "2025-09-25T08:47:01Z")

</div>

Some more information

- [WiFi api](https://ameba-doc-arduino-sdk.readthedocs-hosted.com/en/latest/ameba_pro2/amb82-mini/API_Documents/WiFi/index.html)
- [example guide, with some optimization suggests](https://ameba-doc-arduino-sdk.readthedocs-hosted.com/en/latest/ameba_pro2/amb82-mini/Example_Guides/Multimedia/CaptureJPEG/Capture%20JPEG%20display%20over%20HTTP%20Continuous.html)
  - Resolution
  - FPS
  - Block vs Non-Block Mode
  - Stack Size

---

<div class="post-metadata">

**Author:** ![jimmiedave](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jimmiedave](https://forum.amebaiot.com/u/jimmiedave)\
**Post date:** [September 25, 2025, 10:27am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/16 "2025-09-25T10:27:13Z")

</div>

Thanks very much for digging in to this. I’ll try the new version shortly!

---

<div class="post-metadata">

**Author:** ![M-ichae-l](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/m-ichae-l/32/33_2.png) [@M-ichae-l](https://forum.amebaiot.com/u/M-ichae-l)\
**Post date:** [October 3, 2025, 6:01am UTC](https://forum.amebaiot.com/t/amb82-mini-http-jepg-streaming-though-browser-example-and-optimize-suggestions/4223/17 "2025-10-03T06:01:48Z")

</div>

Let me adjust the title to make it more relevant, so that more people can see it and learn from it.
