Thursday, July 03, 2008

A simple mjpeg streamer for python

I've been working with networking stuffs lately, like XML, parsing and lately streaming. Originally, I wanted to do this for my Android project which is still slightly veiled in secrecy. It will be open sourced completely though, when it matures. So, I wrote this application in an effort to understand the networking behind it and get it to work on Android. Frankly, I am not so good with Java and working with networking stuffs with objects. Everyday I appreciate more of that power though and it's fun to learn new things. I tend to practice with python first and after the proof of concept works there, I do it in Java. It's slightly roundabout way of doing things but it works for me.
What this application does is that it takes snapshots of the jpeg files from the server fast enough for making it seem like it's video.. Well, that's what it is anyways. Let's just say I haven't understood streaming and multi part files properly enough to implement. So, basically, it just sends a GET to the server and pulls the file one by one in a loop. It's really that simple.
The tricky part was to get it to display properly. Tkinter took care of that with Python Image Library. It would be easier if the files aren't jpeg though. That might be for future implementations but for now it's fine for what I'm doing with my Android project.
Anyways, I decided to open source it entirely at

http://code.google.com/p/mjpeg-stream-client/

That might be useful to someone, if nothing but just to learn a new thing or two about python. It' s fairly unpolished even as a basic tool but I hope to improve it to some degree to learn about multimedia streaming and threading concepts in python.

If the application was any bit useful, do drop a comment.

Here are the sources, if you wanted to view them right away

http://code.google.com/p/mjpeg-stream-client/source/browse/trunk/StreamViewer.py

http://code.google.com/p/mjpeg-stream-client/source/browse/trunk/client.py

Here's my picture after I finally got video in Android.. hehe. That program did serve a purpose. Phew!


Cheers!

3 comments:

daniel niculescu said...

I was looking for a solution to integrate mjpeg streams from 20+ ip cameras. The application from the supplier sucks and its limited at the no. of simultaneous streams.
Starting from your code, I am working on an application which to display as many streams I want, and to run it on any platform I want. My office runs FreeBSD on workstations, clients offices on windows.
Thank you!

zahra said...

I need ye simple code for receive image of camera and save it in pc
please help me
just a simple code

nolim said...

Hi, you have some bugs in your code.
The video is blinking because when you are displaying images you need to hold the photoimage in 2 copies.
When you change image the garbage collector starts working and the image disappear and blinks. you can search for it in google.

Also you didn't use mjpeg streaming protocol - there is a simple client code using reactor and python twisted library (called: python-mjpeg-over-http-client).