Download .jpg from web
Adam DePrince
adam at cognitcorp.com
Thu Jan 6 17:58:03 EST 2005
On Thu, 2005-01-06 at 13:49, GMane Python wrote:
> Hello All.
> Using a network camera with built-in webserver, I'd like to have a python
> program download .jpg files on a local lan. the location is
> http://<ip-address>/jpg/image.jpg.
>
> Currently, I'm importing urllib and using urlopen to the address, then
> read()-ing it, saving it to a binary file. All that is working great, but
> maybe a bit slowly. I'm getting ~2.3 frames per second, and would like
> between 5-10 frames per second.
I don't think that connection persistance is the problem you are
facing. Perhaps the camera's TCP stack is really slow, but I just don't
see the overhead of reconnecting being anywhere near high enough to
account for the difference between what you have and what you think you
should have.
* What kind of camera are you using ... is it capable of handling more
frames per second? I sounds like what you really want is a camera that
can stream an avi or mpeg.
* What is the bandwidth between the camera cluster and your server and
what is the average size of an image? Lets be sure you are not
bandwidth constrained.
* Are you doing any post processing on these images?
If all you are doing is:
open( "somefilename.jpg").write( urllib.open( ... ).read() )
then what you are looking to do is a premature optimization.
Also, you may want to consider saving the images in a format other than
a stream or jpegs. The Ogg Vorbis Theora codec is pretty mature right
now and, assuming that consequtive images are similar, will compress way
better than just saving jpegs.
- Adam
>
> Am I approaching this incorrectly? I have to do a urlopen, then .read()
> for each image. Is there any way to 'persist' the urlopen so I just have to
> keep read()-ing or maybe is there a type of streaming read? I have many
> cameras, so there are many threads simultaneously reading and dropping them
> in a central Queue for saving later.
>
> I appreciate it!
> -Dave
>
> WebImage = urllib.urlopen("http://<ip-address>/jpg/image.jpg").read()
> QueuePacket = []
> QueuePacket.append(WebImage)
>
Adam DePrince
More information about the Python-list
mailing list