質問

My code has been working fine for a long time, but I recently got 2 new network cameras running high res MJPEG image streams over HTTP, and I'm seeing corrupt JPEGs as below from both cameras. So pretty sure its not hardware related. Older lower res cameras still work fine.

Approach that I have been using so far :

UIImage *image = [UIImage imageWithData:data]

This has been working fine, and I've been ensuring my JPEG starts with 0xff 0xd8 and ending with 0xff 0xd9.

With the larger images I now get:

<Error>: ImageIO: JPEG Corrupt JPEG data: bad Huffman code
<Error>: ImageIO: JPEG Corrupt JPEG data: premature end of data segment

So I decided to give libturbojpeg a try instead, and that is showing similar decode visual artifacts, but no error messages.

The stream seems to work fine via a browser... but if I save a single frame out from the simulator, and load into a browser the artifacts are there.

I'm using GCDAsyncSocket for the networking, which has also been working fine for a long time.

So I'm wondering if anyone can shed some light on where things might be getting corrupted please. If network data was getting lost, I doubt I'd be getting the full frames, or the expected 15fps, (although I dont know how loss sensitive JPEGs are...) but I can't think what else might cause this kind of issue.

1001 0x0D 0x0A--ThisString 0x0AContent-type:image/jpeg 0x0AContent-Length:17137 0x0A 0x0A 0xFF 0xD8 ...

... 0xFF 0xD9 0x0D 0x0A103f 0x0D 0x0A--ThisString 0x0AContent-type:image/jpeg 0x0AContent-Length:17894 0x0A 0x0A 0xFF 0xD8 ...

Update: I've since tried replacing the network layer, and see the same image corruption, running out of things to try. I also tried saving the image to disk, and it loads from disk into browser already corrupted. If I point the browser at the source stream, the images arrive no problem.

example jpeg

役に立ちましたか?

解決

Turns out the Transfer-Encoding was the issue.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top