473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Download .jpg from web

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.

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)


Jul 18 '05 #1
3 5955
GMane Python wrote:
Using a network camera with built-in webserver


The first thing that might be worth investigating
is this webserver. What kind of throughput is it
capable of? How does it handle repeated
requests etc.

Your program won't be faster than the server
that provides it with the data.

Istvan.
Jul 18 '05 #2
You could try using: urlllib.urlretrieve ...it may be faster.

Jul 18 '05 #3
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.

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)

What your doing, downloading images one at a time, is not the most
efficient method. What you want to do is to enable the mjpeg (motion
jpeg) mode of the camera. I am using a Trendnet camera. To get the mjpeg
stream out of this camera, I use: "camera-url/VIDEO.CGI". If you put
this address into the Firefox address bar, and then press refresh (for
some reason it doesn't start unless you press refresh) it will start.
The camera will hold the connection open and send jpeg images as a
multipart mime message.

The camera will respond with the header:
--------------------------------
Server: Camera Web Server/1.0
Auther: Steven Wu
MIME-version: 1.0
Cache-Control: no-cache
Content-Type:multipart/x-mixed-replace;boundary=--video boundary--
--------------------------------

Then it will repeatedly send send:

-------------------------------
--video boundary--
Content-length: 27577
Content-type: image/jpeg

<jpeg data>

--video boundary--
-------------------------------

I had a url with a good explanation of this but I can't find it now. If
I find it I will post it.

Here is a simplified version of my current thinking.
I took out the error handeling stuff to make the logic
clear.

--------------------------------------------
Thread that reads from the camera
--------------------------------------------
h=httplib.HTTP(camera url)
h.putrequest('GET','VIDEO.CGI')
h.putheader('Accept','text/html')
h.putheader('Accept','image/jpeg') # Trendnet camera works without this
h.endheaders()
errcode,errmsg,headers=h.getreply()
f=h.getfile()
<if errcode is 200 go on the the next part>

while 1:
data=f.readline()
if data[0:15]=='Content-length:':
count=int(data[16:])
n=f.readline() # skip over Content-type: image/jpeg\n'
n=f.readline() # skip over \n'
s = f.read(count)
p=file(tempfile,'wb')
p.write(s)
p.close()
<trigger main thread to display image from tempfile>
--------------------------------------------
The first part sets it up and the while loop gets the jpeg data
as fast is the camera will send it.

Mark Rainess
Jun 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: chon | last post by:
I have an ASP page that is sent a file location as a parameter. It opens this file, loads the ADODB.Stream object and does a binary write to the page forcing the download dialog to appear. This...
0
by: jmd | last post by:
Hello. I want to write a C# program that does completely automatically what, until now, I do manually, witch is describe below : 1. I launch IE (6) 2. I browse to my desired download page, say...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
3
by: Nathan Sokalski | last post by:
I have a webform that contains a button which I want to do three things: 1. Delete a record from a database 2. Let the user download a text file that is generated 3. Refresh the page to show...
18
by: jmd | last post by:
Hello, I posted the following in the C# forum but without one answer. But perhaps now in vb.net someone has some guidelines ! This is my question : I want to write a vb.net program that does...
1
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
1
by: JayLembeck | last post by:
Over 50,000 Free Ringtone. Get the Latest Ringtone. Download now- Fast, Free and Easy. Get your FREE surprise RINGTONE now! http://seekoutfast.info/free-ringtone/ free ringtone free ringtone new...
5
by: Khafancoder | last post by:
Hi guys, i am building a FileSharing website, i wanna allow users to be able using download managers such as DAP to download files from webserver but don't allow them to retrive files url......
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.