xuggle encoding for image as byte[]

317 views
Skip to first unread message

Georgi Dzhambazov

unread,
Aug 30, 2010, 5:29:16 PM8/30/10
to xuggler-users
Hi all.

I am using Xuggle to encode a video stream consisting of captured
screen frames. I am following the tutorial
http://wiki.xuggle.com/Encoding_Video_from_a_sequence_of_Images
using the recommended java awt method
This returns the result in the java.awt.image.BufferedImage format.

However capturing the whole monitor is extremely slow on some moderate
processors like mine. I found out the the swt screen capturing is
quite faster.

See http://www.java2s.com/Tutorial/Java/0280__SWT/ScreenshotscreencapturebyGC.htm
Still it returns an object of type org.eclipse.swt.graphics.Image;
This can be transformed into a byte array byte[].
My question is : Is there a way for the encoding method of xuggle to
work with byte array directly instead of BufferedImage.

If I have to convert to BufferedImage then I do not get any
performance gain. This conversion is slow.

Thank you,
regards Georgi

Art Clarke

unread,
Aug 30, 2010, 10:40:22 PM8/30/10
to xuggle...@googlegroups.com
See the IVideoPicture.make(...) methods, and explore using com.xuggle.ferry.IBuffer objects.  IBuffer objects can wrap just about anything (although they will copy to a Direct ByteBuffer.  If Swing has a Direct ByteBuffer (see java.nio documentation) then that will be the fastest as Xuggler does everything with native memory (not Java heap) at the end of the day.

- Art


--
You received this message because you are subscribed to the Google Groups "xuggler-users" group.
To post to this group, send email to xuggle...@googlegroups.com.
To unsubscribe from this group, send email to xuggler-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xuggler-users?hl=en.




--
http://www.xuggle.com/
xu‧ggle (zŭ' gl) v. To freely encode, decode, and experience audio and video.

Use Xuggle to get the power of FFmpeg in Java.

Georgi Dzhambazov

unread,
Aug 31, 2010, 1:51:32 PM8/31/10
to xuggler-users
HI, Art
Thank you!

I first capture the whole screen by the tools of the SWT library:

Display display = new Display();
GC gc = new GC(display);
Image image = new Image(display, this.screenWidth,
this.screenHeight);
gc.copyArea(image, 0, 0);
byte [] imageData = image.getImageData().data;


imageData is the byteArray. It has RGB format.

Now I create a new IBuffer and VideoPicture:

IBuffer iBuffer = IBuffer.make(null, imageDataArray,0,
imageDataArray.length );

IVideoPicture ivideoPicture;

ivideoPicture = IVideoPicture.make(iBuffer,
IPixelFormat.Type.YUV420P, this.screenWidth, this.screenWidth);

The encoding works. Viva Xuggler.
BUT
I get wrong image format, e.g. the output has not correct colors.
I guess I am not using.

I am not an expert on color spaces, but I think I should indicate the
color type before calling IVideoPictureMake. e.g. before converting
to YUV420P.
for example, can it be done with RefCounted as an argument of the
IBuffer.make() method. I set it now as null. Maybe set it as
PixelFomat ?

Thank you!
Georgi

On Aug 31, 2:40 am, Art Clarke <acla...@xuggle.com> wrote:
> See the IVideoPicture.make(...) methods, and explore using
> com.xuggle.ferry.IBuffer objects.  IBuffer objects can wrap just about
> anything (although they will copy to a Direct ByteBuffer.  If Swing has a
> Direct ByteBuffer (see java.nio documentation) then that will be the fastest
> as Xuggler does everything with native memory (not Java heap) at the end of
> the day.
>
> - Art
>
> On Mon, Aug 30, 2010 at 2:29 PM, Georgi Dzhambazov <
>
>
>
> joro.dzhamba...@gmail.com> wrote:
> > Hi all.
>
> > I am using Xuggle to encode a video stream consisting of captured
> > screen frames. I am following the tutorial
> >http://wiki.xuggle.com/Encoding_Video_from_a_sequence_of_Images
> > using the recommended java awt method
> > This returns the result in the java.awt.image.BufferedImage format.
>
> > However capturing the whole monitor is extremely slow on some moderate
> > processors like mine. I found out the the swt screen capturing is
> > quite faster.
>
> > See
> >http://www.java2s.com/Tutorial/Java/0280__SWT/Screenshotscreencapture...
> > Still it returns an object of type  org.eclipse.swt.graphics.Image;
> > This can be transformed into a byte array byte[].
> > My question is : Is there a way for the encoding method of xuggle to
> > work with byte array directly instead of BufferedImage.
>
> > If I have to convert to BufferedImage then I do not get any
> > performance gain. This conversion is slow.
>
> > Thank you,
> > regards Georgi
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "xuggler-users" group.
> > To post to this group, send email to xuggle...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > xuggler-user...@googlegroups.com<xuggler-users%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/xuggler-users?hl=en.
>
> --http://www.xuggle.com/

Daniel

unread,
Aug 31, 2010, 4:38:01 PM8/31/10
to xuggler-users
If you look in the recent rtmp thread here I posted some sample code
for this. I believe you can just do something like this to get a
TYPE_3BYTE_BGR.

//convert it for Xuggler
BufferedImage currentScreenshot = new
BufferedImage(image.getWidth(), image.getHeight(),
BufferedImage.TYPE_3BYTE_BGR);
currentScreenshot.getGraphics().drawImage(image, 0, 0,
null);


On Aug 31, 1:51 pm, Georgi Dzhambazov <joro.dzhamba...@gmail.com>
wrote:

Art Clarke

unread,
Sep 1, 2010, 12:51:43 AM9/1/10
to xuggle...@googlegroups.com
Try a different IPixelFormat specifier when creating your IVideoPicture.  The names of the IPixelFormat.PixelType enum are somewhat explanatory.

- Art

To unsubscribe from this group, send email to xuggler-user...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/xuggler-users?hl=en.

Reply all
Reply to author
Forward
0 new messages