Click here to Skip to main content
13,199,026 members (40,575 online)
Click here to Skip to main content
Add your own
alternative version


126 bookmarked
Posted 23 Apr 2012

Motion JPEG Streaming Server

, 23 Apr 2012
Rate this:
Please Sign up or sign in to vote.
Implementing a MJPEG (or Motion JPEG) streaming server that can be used to steam screenshots or any other source of images over the HTTP protocol to any web browser client (MJPEG stream writer is included in the library).

For mobile clients:

Samsung Galaxy SII

Other clients (such as Firefox, Chrome and VLC player):

Streaming the desktop images to different remote clients


Motion JPEG is a stream of JPG images over HTTP protocol and it is commonly used for many multimedia applications specially in digital cameras (IP cameras). Although there are many ways to send images as a video to any remote computer  MJPEG is the preferred one since normally it does not need any client software to be installed in the remote computer!. that is because it is supported by most of the common web browsers like Firefox and Chrome but unfortunately, it is not yet supported by Internet Explorer directly (but there are some plug-ins that make it possible to work with IE).


In many I needed to stream a video of my desktop, camera, or whatever to a remote computer which has no client software to see my stream... In such a case, using Motion-JPEG streams is preferred because it needs no more than an internet browser. In this article I'm not going to describe the internal structure of an MJPEG stream (for more information, please visit Motion_JPEG) instead of that I'm going to describe how to use this library for MJPEG streaming.

How to use this library

The main class in our library is ImageSreamingSever() which contains the following methods and properties:


  • void Start(): Starts the server on a specified TCP port.
  • void Stop(): Stops the server and closes any open connections.


  • ImagesSource: The images collection (IEnumerable<Image>) to be streamed to any connected client.
  • Interval: The delay time (in milliseconds) between each sending image from the ImagesSource collection.
  • IsRunning: Is a read-only bool property indicating the status of the server.
  • Clients: Returns a read-only collection of the currently connected socket of each client.


In order to implement a streaming server that can send a video of your desktop screen to any connected client, you'll need only two lines of code using our ImageStreamingServer, as follow:

ImageStreamingServer server = new ImageStreamingServer(); 

That's it !!!.. 

Now if you open (for example) the chrome internet explorer and write the IP of the server followed by colon and then the port number, in our example it is something like this :

you will properly see a video of your computer screen in the explorer .. and same if you do this from another computer (with the correct IP of your server), you should see something like this :

Google Chrome

Implementing your own ImagesSource 

Actually I've chosen IEnumerable<Image> as a source of images because of the flexibility that this interface is providing, for example the default ImagesSource property of the class ImageStreamingServer is an IEnumerable<Image> of the desktop screen, but at the same time you are free to implement any other type of image source you like by changing the value of that property.

Suppose you want to make the images source from the camera or from the images file of any folder in your computer, then your code should be something like this:

IEnumerable<Image> CameraImagesSource() 
    // Your code must be here 

IEnumerable<Image> FolderImagesSource(string path) 
    // Your code must be here 

As a real example, let's implement a source of images that streams all "*.jpg" photos from a specified folder path as follows:

private IEnumerable<Image> FolderImagesSource(string path)
    var files = System.IO.Directory.GetFiles(path, "*.jpg");

    foreach (var file in files)
        yield return Image.FromFile(file);

    yield break;

private void Form1_Load(object sender, EventArgs e)
    var source = FolderImagesSource(@"C:\Pictures\");

    _Server = new ImageStreamingServer();
    _Server.ImagesSource = source;

Note: the above code can be shortened as follows (thanks for IEnumerable extensions and LINQ):

var source = System.IO.Directory.GetFiles(@"C:\Pictures\", "*.jpg").Select(s => Image.FromFile(s));

_Server = new ImageStreamingServer(source);

Supported client software

To see the streaming video of our server, you will need to use any software that supports Motion-JPEG streaming such as a Mozilla Firefox, Google's Chrome or VideoLAN Player (VLC) :

Free client software for Windows PC

And finally for your mobile (android) use FireFox or any other free app that can be found on Google's market such as tinyCamMonitor (that was used in the picture below):

Samsung Galaxy SII

Future versions 

In the future versions of the library I'm going to add a variety of images sources such as:

  • Images from a specific region of the screen.
  • Images from a specific window in the system.
  • Streaming images from a camera. 
  • All photos from any folder in a disk.
  • And any other suggested sources of images you may want !? ...

And till that time, fill free to enjoy this version ;-)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ragheed Al-Tayeb
Team Leader Hawk International for Finance & Construction Ltd.
Yemen Yemen
Bachelor degree of Computer Sciences, Software developer using .NET (Visual Basic & C#).
I like the development of an Artificial Intelligence Systems, GPS Applications, GDI+, APIs, N-Tier Applications, Distributed Systems and Network Monitoring Systems.
Mobile Development (Windows Mobile & Android).

You may also be interested in...


Comments and Discussions

BugDoes not works in IE Pin
vijayksingh24-Jul-13 18:56
professionalvijayksingh24-Jul-13 18:56 
GeneralRe: Does not works in IE Pin
Ragheed Al-Tayeb25-Jul-13 20:03
memberRagheed Al-Tayeb25-Jul-13 20:03 
Questionhi Pin
Jtmaroor26-Jun-13 22:48
memberJtmaroor26-Jun-13 22:48 
GeneralMy vote of 5 Pin
Jtmaroor26-Jun-13 22:45
memberJtmaroor26-Jun-13 22:45 
QuestionEmbedded Streaming Pin
Paul Philip Daniels21-Jun-13 8:07
memberPaul Philip Daniels21-Jun-13 8:07 
QuestionAbout MJPEG Streaming Server Pin
Member 998370612-Apr-13 6:02
memberMember 998370612-Apr-13 6:02 
QuestionVideo Streaming Pin
Fábio Pinho29-Mar-13 4:30
memberFábio Pinho29-Mar-13 4:30 
AnswerRe: Video Streaming Pin
joshua53679-Apr-13 20:44
memberjoshua53679-Apr-13 20:44 
GeneralRe: Video Streaming Pin
Fábio Pinho9-Apr-13 22:19
memberFábio Pinho9-Apr-13 22:19 
AnswerRe: Video Streaming Pin
Rahul Kumar12-Jun-14 1:16
memberRahul Kumar12-Jun-14 1:16 
BugError when Call Stop() Pin
Hong Thai8-Mar-13 5:41
memberHong Thai8-Mar-13 5:41 
AnswerRe: Error when Call Stop() Pin
Member 1010956114-Jun-13 11:47
memberMember 1010956114-Jun-13 11:47 
Questionhow to connect web camera as a source? Pin
Al-hassaan17-Feb-13 7:45
memberAl-hassaan17-Feb-13 7:45 
QuestionAny chance for Example? Pin
itayzoro9-Feb-13 22:07
memberitayzoro9-Feb-13 22:07 
10nx very nice
GeneralMy vote of 5 Pin
Karell Ste-Marie1-Feb-13 6:18
memberKarell Ste-Marie1-Feb-13 6:18 
QuestionThx! Pin
zuppaman15-Jan-13 6:02
memberzuppaman15-Jan-13 6:02 
QuestionWebcam Pin
mornej18-Dec-12 23:00
membermornej18-Dec-12 23:00 
QuestionConnect IP Camera Pin
thuongbinh3-Oct-12 22:35
memberthuongbinh3-Oct-12 22:35 
QuestionIP Camera Live stream image loading Pin
RAJESHkharvi12-Sep-12 19:34
memberRAJESHkharvi12-Sep-12 19:34 
QuestionVote of 5 Pin
yetanotheruser927-Sep-12 2:38
memberyetanotheruser927-Sep-12 2:38 
GeneralMy vote of 5 Pin
Mahdi Nejadsahebi18-Aug-12 4:31
memberMahdi Nejadsahebi18-Aug-12 4:31 
Questionconnect IP camera over the network Pin
Van Sereyboth30-Jul-12 23:34
memberVan Sereyboth30-Jul-12 23:34 
Question_Server.Stop() doesn´t work Pin
Paranosh30-Jul-12 6:36
memberParanosh30-Jul-12 6:36 
QuestionMumtiple jpeg files created on the fly... Pin
Patrick Antonioli Ferraro25-Jul-12 7:37
memberPatrick Antonioli Ferraro25-Jul-12 7:37 
GeneralMy vote of 5 Pin
easternC10-Jul-12 20:08
membereasternC10-Jul-12 20:08 
GeneralCool! Pin
y.konyshev21-Jun-12 10:06
membery.konyshev21-Jun-12 10:06 
Questionprotect the access by user and password Pin
Alberto Llaguno18-Jun-12 11:02
memberAlberto Llaguno18-Jun-12 11:02 
QuestionHow do you get all the tcp clients ? Pin
choneshcl7-Jun-12 5:09
memberchoneshcl7-Jun-12 5:09 
SuggestionAwesome Job, Looking forward to the update Pin
Lollaskates5-Jun-12 5:26
memberLollaskates5-Jun-12 5:26 
Questiongood job Pin
hbcykensou4-Jun-12 1:13
memberhbcykensou4-Jun-12 1:13 
QuestionHow can I re-stream from IP camera ? Pin
Member 20224223-Jun-12 19:08
memberMember 20224223-Jun-12 19:08 
QuestionUse this on a Windows Phone Pin
t.a berglund24-Apr-12 3:47
membert.a berglund24-Apr-12 3:47 
AnswerRe: Use this on a Windows Phone Pin
Ragheed Al-Tayeb24-Apr-12 5:03
memberRagheed Al-Tayeb24-Apr-12 5:03 
GeneralRe: Use this on a Windows Phone Pin
t.a berglund24-Apr-12 8:09
membert.a berglund24-Apr-12 8:09 
GeneralRe: Use this on a Windows Phone Pin
Ragheed Al-Tayeb24-Apr-12 11:00
memberRagheed Al-Tayeb24-Apr-12 11:00 
GeneralRe: Use this on a Windows Phone Pin
t.a berglund25-Apr-12 2:03
membert.a berglund25-Apr-12 2:03 
Questionnamespace rtaNetworking.Streaming Pin
Rohit Dubey from Hyderabad24-Apr-12 2:48
memberRohit Dubey from Hyderabad24-Apr-12 2:48 
AnswerRe: namespace rtaNetworking.Streaming Pin
Ragheed Al-Tayeb24-Apr-12 4:56
memberRagheed Al-Tayeb24-Apr-12 4:56 
GeneralRe: namespace rtaNetworking.Streaming Pin
Rohit Dubey from Hyderabad25-Apr-12 4:15
memberRohit Dubey from Hyderabad25-Apr-12 4:15 
Questiona bit more code explanation, would do the trick... Pin
Paw Jershauge23-Apr-12 21:34
memberPaw Jershauge23-Apr-12 21:34 
AnswerRe: a bit more code explanation, would do the trick... Pin
Ragheed Al-Tayeb24-Apr-12 4:58
memberRagheed Al-Tayeb24-Apr-12 4:58 
GeneralThis is Amazing. Pin
Gassan_omerawy23-Apr-12 19:09
memberGassan_omerawy23-Apr-12 19:09 
GeneralRe: This is Amazing. Pin
Ragheed Al-Tayeb24-Apr-12 4:59
memberRagheed Al-Tayeb24-Apr-12 4:59 
QuestionI'm confused... Pin
Dewey23-Apr-12 13:06
memberDewey23-Apr-12 13:06 
AnswerRe: I'm confused... Pin
Ragheed Al-Tayeb23-Apr-12 13:14
memberRagheed Al-Tayeb23-Apr-12 13:14 
GeneralNice +5 Pin
Shahin Khorshidnia23-Apr-12 11:34
memberShahin Khorshidnia23-Apr-12 11:34 
GeneralMy vote of 5 Pin
t.a berglund23-Apr-12 10:04
membert.a berglund23-Apr-12 10:04 
GeneralRe: My vote of 5 Pin
Ragheed Al-Tayeb23-Apr-12 11:27
memberRagheed Al-Tayeb23-Apr-12 11:27 
GeneralRe: My vote of 5 Pin
Wade Walker27-Mar-13 10:29
memberWade Walker27-Mar-13 10:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 23 Apr 2012
Article Copyright 2012 by Ragheed Al-Tayeb
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid