Thread: Low level program to save a mjpeg stream

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    2

    Low level program to save a mjpeg stream

    Hi all
    Well first I’ll just say I am a complete Linux beginner, but I have done vbs, js, php, html web type stuff so I’m not a complete beginner to programming.

    However I've been trying to learn C and python but it’s not making a huge amount of sense.

    I am wanting to make a simple low level program that copies an image from a mjpeg stream on 192.168.0.1/videostream.cgi for example to a variable then save that variable to a file on my system.

    I am aware that there are programs out there that would do this but I still want to make my own.

    Any help?
    Thanks Rufe0

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Low level...nah

    You can do this with a python script
    Code:
    #!/usr/bin/env python
    
    import urllib
    
    imageUrl = "http://www.cprogramming.com/cprog.gif"
    fileName = imageUrl[imageUrl.rfind("/")+1:]
    imageFile = urllib.urlopen(imageUrl)
    
    outFile = open(fileName,"wb")
    outFile.write(imageFile.read())
    outFile.close()
    imageFile.close()
    
    print("%s saved" % fileName)

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Get ready to say OUCH!!!

    This is how I've done it in C. It is more than ten times the amount of coding as it is in python...but all the low level stuff you were just dying to see is there

    ps. looks like this one uses my old header file: mine.h
    pps. I bet it is faster than the python version tho
    Last edited by MK27; 06-26-2009 at 01:41 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Quote Originally Posted by MK27 View Post
    Get ready to say OUCH!!!
    OUCH indeed! Good effort!

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Good work, with a few comments:
    1) Single byte recv() and read()s, ouch.
    2) You mix read and recv calls on a socket, why?
    3) If the first byte is \n, Recept will go out of bounds on that buffer.
    4 & 5 & 6) And you run that as root? (the hardcoded /root/test/... seems to say so!)
    7) Doesn't answer the OP's question?

    OP: You're going to need a lot of information to be able to do that. First, you have to understand HTTP. Once you get past that, you'll need to know what container format your data is going to come in (mjpeg is a video codec. Like MP3, it can be by itself, but I've never actually seen that. Usually it's packaged in something like an AVI.).

    Are you sure they're streaming mjpeg? mjpeg is a terrible codec - especially over a network... 30 jpeg files / sec consumes bandwidth way quicker than most other codecs.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  6. #6
    Registered User
    Join Date
    Jun 2009
    Posts
    2
    Thanks for the replys
    I am now trying to get into contact with the manufactuor who we deal with directly to see what he can do to help me. A firmware update of this device would make the program much easier to write.
    Last edited by Rufe0; 06-29-2009 at 05:52 AM.

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    1

    Looking for work?

    Are you looking for a gig with C\C++ video streaming?

    email: [email protected]

    Quote Originally Posted by Cactus_Hugger View Post
    Good work, with a few comments:
    1) Single byte recv() and read()s, ouch.
    2) You mix read and recv calls on a socket, why?
    3) If the first byte is \n, Recept will go out of bounds on that buffer.
    4 & 5 & 6) And you run that as root? (the hardcoded /root/test/... seems to say so!)
    7) Doesn't answer the OP's question?

    OP: You're going to need a lot of information to be able to do that. First, you have to understand HTTP. Once you get past that, you'll need to know what container format your data is going to come in (mjpeg is a video codec. Like MP3, it can be by itself, but I've never actually seen that. Usually it's packaged in something like an AVI.).

    Are you sure they're streaming mjpeg? mjpeg is a terrible codec - especially over a network... 30 jpeg files / sec consumes bandwidth way quicker than most other codecs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Low level access to parallel ports under win2k
    By Incubus in forum Windows Programming
    Replies: 1
    Last Post: 04-23-2002, 01:52 AM
  2. Low level debuggers
    By Korn1699 in forum C++ Programming
    Replies: 8
    Last Post: 03-27-2002, 01:39 PM
  3. A small problem with a small program
    By Wetling in forum C Programming
    Replies: 7
    Last Post: 03-25-2002, 09:45 PM
  4. willing to pay for University level C++ Program
    By need help in forum C++ Programming
    Replies: 6
    Last Post: 03-12-2002, 12:22 AM
  5. Looking low level tcp/ip tracker program
    By Hoxu in forum Windows Programming
    Replies: 3
    Last Post: 01-07-2002, 11:46 PM