Store, convert to video an stream Android screen
Asked Answered
C

1

7

I use DDMS to get screenshots from my Android phone and I need an efficient way for converting them in video and streaming the video over the network.

I have a RawImage which is filled with the data of the screenshot:

RawImage mRawImage;

Until know I use SWT to create the image and save it:

PaletteData paletteData = new PaletteData(
    mRawImage.getRedMask(),
    mRawImage.getGreenMask(),
    mRawImage.getBlueMask());

ImageData imageData = new ImageData(
    mRawImage.width,
    mRawImage.height,
    mRawImage.bpp,
    paletteData,
    1,
    mRawImage.data);

ImageLoader s = new ImageLoader();
s.data = new ImageData[] {imageData};
s.save("temp.jpg",SWT.IMAGE_JPEG);
  • Can you propose a way to convert those images sequence to video and then stream the video?

I found NanoHTTPD which can be used for streaming but how can I convert and compress the images to video?

  • Do you believe that I can do that using ffmpeg?

I found a good Tutorial for streaming your webcam using FFMPEG and video4linux2.

Is it possible to send the bytes from the RawImage to the FFMPEG to be converted to a live video stream?

Actual code:

$ffmpeg -f video4linux2 -i /dev/video0 http://78.47.18.19:8090/cam1.ffm

Replace it with something similar to:

$ffmpeg -f video4linux2 -i **<add here java stream>** http://78.47.18.19:8090/cam1.ffm

Any suggestions?

Thanks

PS: I expect a solution which will help me convert the images to a compressed video and then stream the video over the network in order to play it with either HTML5 or a Flash Player

Countercurrent answered 14/12, 2011 at 13:44 Comment(3)
Hi Salamis, what is the rate at which you will capture the static image?Electrotherapeutics
5-10 frames per second would be sufficient enough.Countercurrent
Hi Salamis, I believe my answer below answers your questions above. You would need to ensure that the capture on the device gives you enough frames per second to encode into a video (see -r parameter in ffmpeg).Electrotherapeutics
E
5

There are two ways to approach this:

1) Capture, Encode and Stream on and from the device itself

or

2) Capture on the device, Encode and Stream from a server

I don't know all of your requirements but I would presume that option 2 is the route to go. You will have better performance and a wider array of tools to use in order to accomplish your end goal.

Capture Capture the JPEG images almost exactly the way you describe. Except add an index to each one such that you have FILE1.JPG FILE2.JPG FILE3.JPG FILE4.jpg etc.

Now, at some interval, depending on your requirements, upload these images to a server.

Encode Use mencode to set the rate of lossy compression like so:

mencoder "./*.jpg" -mf fps=5 -o yourvideo.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800

Once that is done, then you can use ffmpeg to create the MP4 like so:

ffmpeg -r 5 -b 1800 -i %01d.jpg yourvideo.mp4

Streaming Now in order to stream the mp4 over a network, i would setup a web page like:

http://myserver/androidStream

Which loads up a M3U playlist that is written dynamically such that it's always pointing to the most up to date video to stream. Depending on the player your using, you may be able to point the M3U playlist to the 'next' M3U playlist that will load up the next video. You may also want to look at alternative playlist formats like ASX or PLS depending upon your requirements.

See: http://en.wikipedia.org/wiki/Advanced_Stream_Redirector and http://en.wikipedia.org/wiki/PLS_(file_format) as examples of other non-M3U playlist formats.

Using the general steps above, you will have a system where the device is capturing images at a rate of n images per minute and then uploading those images to a server for encoding. Once those images are encoded, you can either stream the movie directly by referencing the file or you can setup an M3U type playlist which will allow the player to move from the 'current' video to the 'next' video when it's available.

Electrotherapeutics answered 31/1, 2012 at 23:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.