Android Question FFMPEG - Not video playback

Discussion in 'Android Questions' started by canalrun, Jun 20, 2015.

  1. canalrun

    canalrun Well-Known Member Licensed User

    I have a situation where I need to capture video frames from an IP camera and save those frames to a sequence of files that I then convert to an AVI or MPEG or some other movie format.

    Using the IPcam library from alan1968:éo-mjpeg-librarie-for-ip-cam.15540/

    I am able to capture frames from the IP camera. I can store each frame to a sequentially numbered JPEG file, hopefully achieving a 2 fps rate – which is good enough.

    But, the place where I'm stuck is that I would like to convert the sequence of JPEG's to a movie from within my code.

    I have seen Internet posts that say FFMPEG has the functionality to do this. I have not found any libraries for Android that I think I can use – although it's more likely that I'm missing the obvious.

    Can anyone offer any suggestions or pointers?

  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    If you have hardware level access to the IP camera, chances are they are able to encode video on the fly.
    Alternative is to wrap an ffmpeg video encoder (I highly doubt its been ported for android), but software encode wont be fast.
  3. canalrun

    canalrun Well-Known Member Licensed User

    Thanks for your reply.

    Yes, I'm going about this in a very roundabout manner. The IP cam I bought is an AI-Ball (think cheap, cheap, cheap) that I found used on eBay. It will interface to a browser if you issue the URL http://IPADDRESS/?action=stream.

    I think it is already sending streaming data. I have tried some of the video view type libraries available for B4A, but they all complain that the streaming format is not supported.

    The ipcam library converts "snapshots" of this stream into canvas drawable's at a data rate specified by a timer then displays them on a panel.

    The best solution would be to record the stream, but it doesn't seem compatible with B4A solutions I've found.

    The "hopping on one leg with one eye shut" solution is to save JPEG's from the canvas bitmaps then convert those to a movie format.

    The quality of the solution is not important – I would be happy to get 2 fps.

    Any suggestions are very welcome.

  4. NJDude

    NJDude Expert Licensed User

    I know of a member who developed such library, as far as I know, is for his personal use, he might see this post and reply.
  5. thedesolatesoul

    thedesolatesoul Expert Licensed User

    1. I think MediaRecorder doesnt accept a stream as a source, so recording from an web stream will be difficult.
    2. If you have a sequence of JPEGs, its possible to encode them as MJPEG. (There is a thread about this somewhere).
    So what is the end game? Where will the recorded video be played back on?
  6. canalrun

    canalrun Well-Known Member Licensed User

    Actually what I'm doing is just playing …

    My neighbor's son has a toy quad-copter that he flies around the backyard. We thought it would be neat to mount a Wi-Fi camera on that so you could fly around and see the video on a tablet.

    The AI-Ball is a small Wi-Fi camera, about the size of a ping-pong ball, that weighs less than 1 ounce with battery. The quad-copter has enough power to fly around with this thing taped to the bottom. There is an Android app to use with this that costs three dollars, but the video size displayed is tiny and it only supports portrait mode.

    It would be nice to make something that is a little more usable – just to display video and be able to record to a file.

    Looking around the web, I am learning more about MJPEG. Apparently this is just a file containing multiple JPEG's one after another. The streaming from the IP camera is most likely just JPEG's sent periodically. It should be easy to concatenate several JPEG's to one file. One thing I haven't found is how one sets the frame rate. suppose my frame rate is 2 fps. How does the player know that?

  7. thedesolatesoul

    thedesolatesoul Expert Licensed User

  8. canalrun

    canalrun Well-Known Member Licensed User

    Thanks for replying again.

    Yes, it is very interesting how this streaming video apparently works. I'm learning a great deal working on this little project.

    To stream video the AI Ball apparently just sends JPEGs one after another. In streaming, the real-time frame rate is determined by the rate at which the AI ball sends the JPEG's. The receiving program, a web browser or something else, displays the JPEG's as it receives them. The correct frame rate is implied.

    If I save the JPEG's to a file, when the file is played back it will probably be able to play back much faster than the original JPEG's were received. Everything will appear in "fast motion". A frame rate needs to be specified to slow things down to the rate at which the original JPEGs were received from the AI Ball. There is some mention about RTP/MPEG and embedding timestamp frames, but I couldn't find anything about how to actually accomplish this.

    I took the easy way out. I found a binary distribution for FFMPEG for Windows. I can transfer my sequence of JPEG's from the laptop that received the AI Ball video stream and convert these to an MP4 using FFMPEG. The frame rate for the MP4 can be specified.

    For this little project that's good enough.

    The quad copter is cool and fun to fly. Flying is strictly very close-range and within sight. This thing is just toy – even the slightest puff of wind will send it careening into the bushes. The camera is just to capture the terrified expression on the dog's face when the quad copter gets close.

    Last edited: Jun 21, 2015
    thedesolatesoul likes this.
  9. canalrun

    canalrun Well-Known Member Licensed User

    I'm calling my application complete - although it's nowhere near perfect, it does what I need.

    Thanks to alan1968 for the library, and thedesolatesoul and others for their help.

    I've attached my application, with project source, as an example.

    I use the AI-Ball IP camera. It's about the size of a ping-pong ball and weighs less than 1 ounce with battery. It comes configured as a micro Access Point (tiny Wi-Fi hotspot) with the address The code should work with other IP cameras, but is preconfigured for this model.


    I use this program with a tablet. First, the tablet must be connected to the AI-Ball's Wi-Fi network.

    In the program I connect to the AI-Ball over Wi-Fi, send it a streaming command, and it sends back streaming video. The video above shows my super-clean office, but I will eventually tape the AI-Ball to the underside of a toy quad copter and chase the dog around the yard :D.

    The "video" is actually comprised of individual JPEG's. I capture the JPEG's at around a 3 frames per second rate. When the record button is pressed, I write each JPEG to a directory. You can then copy the directory to a PC and use FFMPEG to convert the sequence of JPEG's to an MP4.

    example FFMPEG command: C:\ffm\ffmpeg -r 3 -i im%04d.jpg -vcodec mpeg4 qcopt.mp4


    Attached Files:

    Last edited: Jun 22, 2015
    Mashiane and thedesolatesoul like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice