MJPEG Decoder

Sign in to queue

The Discussion

  • User profile image
    LukePuplett

    Without recommending any manufacturer in particular, can you recommend a particular manufacturer of camera we should use for this? Wink

    ...ideally I'd need it to be waterproof and almost invisible when placed behind bathroom tiles.

    Luke

  • User profile image
    BrianPeek

    @LukePuplett:For your scenario, I'd recommend any of the cameras manufactured by Pervsys.  Big Smile

  • User profile image
    LukePuplett

    Thanks Brian, sounds like my kind of brand.

  • User profile image
    stuat

    can you do this using MediaStreamSource and the raw av pipeline in silverlight ??

  • User profile image
    _ivan

    @BrianPeek: can you say which camera(s) use used in this project? Or can you recommend standard(not for LukePuplett use case) cameras which have MJPEG streaming easily accessible?

  • User profile image
    _ivan

    By the way thanks for the library, it is very timely, I hope it will be a good replacement for what I currently use.

  • User profile image
    BrianPeek

    @stuat: I started to write a MediaStreamSource implementation but didn't bother to finish.  You should be able to shove this into a MediaStreamSource without too much issue, though.

  • User profile image
    BrianPeek

    @_ivan: I have tested with the Cisco WVC210, TRENDnet IP110W, and a very old no-name brand camera.  Practically any IP/network camera (i.e. not a USB webcam) should output MJPEG and work with this.  I don't think I've seen an IP cam without some kind of MJPEG support, but that doesn't mean they don't exist.

  • User profile image
    barrkel

    Why not just use TcpClient instead of HttpWebRequest to get around the limitation on the IE User-Agent header? It's not like it's difficult to write a HTTP 1.0 client, especially if it only needs to GET a single resource.

    But then I see TcpClient isn't supported in Silverlight. That really sucks.

  • User profile image
    LukePuplett

    So, do out-of-browser apps have that HTTP header limitation?

  • User profile image
    BrianPeek

    @LukePuplett: You can only run this OOB becuase of the crossdomain.xml policy goodness in Silverlight.  The cameras don't have this file on their internal webserver, so browser-based Silverlight won't work at all.  That said, even OOB apps can't modify the User-Agent header either via the Headers collection or the UserAgent property.

  • User profile image
    Nils

    @barrkel: I'm note quite sure but Silverlight 4 should be able to use System.Net.Sockets.Socket to connect to any resource when running with Elevated Trust as described at https://blogs.msdn.com/b/ncl/archive/2010/04/15/silverlight-4-socket-policy-changes.aspx

    But this looks like a very low-level support of sockets and I think it requires some work to implement a full-featured TCP Client on top of the Socket class.

    Besides that, nice work, Brian.

    (Just my 2 cents...)

  • User profile image
    _ivan

    @BrianPeek: oh good, I used TRENDNet IP cameras in the past for these kind of tasks, and was very pleased with their simplicity.
    Thanks!

  • User profile image
    BrianPeek
    @nils: Definitely an option worth exploring. Anybody want to give it a try? I'm swamped for the the next few weeks on some other projects. Smiley. I'd be happy to add it in if anyone manages to make it work...
  • User profile image
    Magdur

    nice work, Brian

     

    .

  • User profile image
    Bert Vissers

    Very nice article Brian, keep up the good work!

  • User profile image
    Bojan

    Hello,
    I am using your MJPEG Decoder for display JPEG from our server. Owner of the server is sayng that we have produce heavy load on the server. Is this possible?
     
    I am 99% soure that my question is stupid, but I must ask: is it possible that while loop which read bytes from BinaryReader, causes too much load on the server?!
     
    Thanks!
     

  • User profile image
    BrianPeek

    @Bojan: what kind of load are you seeing and what version of the decoder are you using? (wpf, xna, etc.)  In my testing here, my test apps are cranking away at a 640x480 stream at 30fps and I'm only seeing 5-6% CPU at most, typically less.

  • User profile image
    Bojan

    I don't know how much is loading(CPU) exactly, I don't have access to the server. I am using decoder (for WinForms) for display streams from 20 cameras. I made my own server wich send multipart response with jpegs, so i wil test on him.

  • User profile image
    Bojan

    I forgot, jpeg dimension is 266x150 and framerate is 1000 (1 fps). According to your parameters, my parameters shouldn't cause problems on server?

  • User profile image
    BrianPeek

    @Bojan: Well, if you're constantly reading the stream of 20 cameras simultaneously, there's a chance it could be putting undue load on the server.  It has never been tested in that kind of environment.  I wouldn't think you'd crush the server, but if each stream is taking 2-3% of CPU to read/decode, make it times 20 and you're taking a decent toll on the server.

  • User profile image
    Reza Jafari

    it sounds fun

  • User profile image
    zipswich

    Thanks a lot, Brian, for this very informative article. I used WebClient instead of HttpWebRequest to make an SL app after reading your article.  I found it to be a little bit easier.  It works well.

    The SL x-domain access limitation almost defeats the purpose of the app which I made because of being tired of dealing with obsolete ActiveX controls one would have to install on every computer used to view an IP camera. I do not understand why SL does not allow in-browser X-domain access if it is allowed explicitly by the user for a specific uri.

    I am not sure what benefits one would get by using System.Net.Sockets as suggested by Nils.

    Hong

  • User profile image
    Alex

    Do you know the AForge lib?
    (AForge.Video.dll)

  • User profile image
    Misha

    hello! ssory, where it is possible to find the reference on MjpegProcessor.dll?

  • User profile image
    JimBeam

    Great library, great examples. However, when switching between two cameras (programatically, of course), the image object wants to show both streams at the same time. I have used the stopstream method but that doesn't seem to do anything and I can see both live feeds interlaced within each other. Help

  • User profile image
    Rene Tuchscherer

    Hi Brian,

    i use your great library in a windows phone 7 app.
    One question, how can i stop the stream when i leave the page there is a error (StopStream() don't work).

    Thx for René

  • User profile image
    Joseph Piron

    Hi Brian, thanks for this ! Really helpfull.
    But I have a small weird issue: I can't start more than two decoder in an application (I'm trying to get on stream from the same camera, can it be the problem ?) and if I stop the stream, it can't restart it ? Could it be related to a keep-alive or not closed connection ?

    Thanks !

  • User profile image
    jj jo

    why is it it will lag if i will simultaneously run 8 camera streams

  • User profile image
    KHerron

    Can this be used in an asp website to display the video?

  • User profile image
    Arno

    A modified code version with some fixes like frame drops,... can be found here:
    https://github.com/arndre/MjpegDecoder

  • User profile image
    Michael

    Great explaination.

    I'm currently using this method for my project, but at 10fps on the raspberry due to processing, i'm having to drop some frames to keep up. Any idea's on this?

Add Your 2 Cents