user846400
user846400

Reputation: 1101

Receiving JPEG images via http GET request

I want to receive images from an IP camera over HTTP via GET request. I have written a program that creates TCP socket connection with the camera and sends the following GET request to the camera:

GET /mjpeg?res=full HTTP/1.1\r\nHost: 143.205.116.14\r\n\r\n

After that, I receive images with the following function in a while loop:

while((tmpres = recv(sock,(void *) buf, SIZE, 0)) > 0 && check<10)

.....

where SIZE represents the size of the buffer. I, infact, don't know what size to define here. I am receiving a color image of size 2940x1920. So I define SIZE=2940x1920x3. After receiving the MJPEG image, I decode it with ffmpeg. But I observe that ffmpeg just partially/uncorrectly decodes the image and I just see a half (or even less) of the image. I assume it could be a size problem. Any help in this regard would be highly appreciated.

Regards,

Khan

Upvotes: 0

Views: 3867

Answers (2)

Kerrek SB
Kerrek SB

Reputation: 477228

Why reinvent the wheel (for the umpteenth time)? Use a ready-made HTTP client library, such as libcurl.

For that matter, perhaps you can even just write your entire solution as a shell script using the curl command line program:

#!/bin/sh

curl -O "http://143.205.116.14/mjpeg?res=full" || echo "Error."
curl -o myfile.jpg "http://143.205.116.14/mjpeg?res=full" || echo "Error."

# ffmpeg ...

Upvotes: 2

cprogrammer
cprogrammer

Reputation: 5675

Save bytes received as binary file and analyze. May be an incomplete image (image can be encoded as progressive JPEG - is interlaced in fact - that means if you truncate the file you'll see horizontal lines.) or can be a ffmpeg decoding issue. Or something different. What is check < 10 condition ?

Upvotes: 0

Related Questions