YUV420P BgrConverter BufferedImage TYPE_3BYTE_BGR (conversion color issue)

537 views
Skip to first unread message

je...@jungletech.com

unread,
Nov 13, 2009, 6:20:45 PM11/13/09
to xuggler-users
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;

import com.xuggle.xuggler.IVideoPicture;
import com.xuggle.xuggler.video.BgrConverter;
import com.xuggle.xuggler.IPixelFormat.Type;

public class Main
{
public static void main(String args[]) throws AWTException,
IOException
{
// capture the whole screen
BufferedImage image = new Robot().createScreenCapture( new Rectangle
(Toolkit.getDefaultToolkit().getScreenSize()) );

BufferedImage screencapture = new BufferedImage(image.getWidth(),
image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
screencapture.getGraphics().drawImage(image, 0, 0, null);

File beforeConvert = new File("BeforeConverter.jpg");
javax.imageio.ImageIO.write(screencapture, "jpg", beforeConvert);
BgrConverter _converter = new BgrConverter(Type.YUV420P,
screencapture.getWidth(), screencapture.getHeight() ,
screencapture.getWidth(), screencapture.getHeight());

IVideoPicture videoPicture = IVideoPicture.make
(Type.YUV420P,screencapture.getWidth(), screencapture.getHeight());
videoPicture = _converter.toPicture(screencapture, 0);

// Save as JPEG
File afterConvert = new File("AfterConverter.jpg");
ImageIO.write(_converter.toImage(videoPicture), "jpg",
afterConvert);
}
}


Captured images are "off-color"; on my system its a red/pinkish tint.
Could the converter be dropping something* when it's doing the
conversion?

Robert Harris

unread,
Nov 13, 2009, 6:46:44 PM11/13/09
to xuggle...@googlegroups.com
On Fri, Nov 13, 2009 at 3:20 PM, je...@jungletech.com
<je...@jungletech.com> wrote:

> Captured images are "off-color"; on my system its a red/pinkish tint.

your code looks right. i assume the before image BeforeConverter.jpg
looks ok, and the AfterConverter.jpg looks broken?

> Could the converter be dropping something* when it's doing the
> conversion?

the BGR -> YUV -> BGR could be lossy. did you had produced video with
the pink color and then wrote up this (very nice) little code block to
demonstrate the problem?

-trebor

je...@jungletech.com

unread,
Nov 16, 2009, 11:47:22 AM11/16/09
to xuggler-users
Correct, was* capturing video and was tracking down the issue. (that's
how this nice* little code block happened ^_^)

--- Capturing to *.mp4 file
--- using YUV420P

The color is a little off (it has a pink hue)
beforeConvert.jpg ==> http://imagebin.ca/view/7PJxkj.html
afterConvert.jpg ==> http://imagebin.ca/view/r7rfDcJ.html

---Jeff

On Nov 13, 6:46 pm, Robert Harris <tre...@xuggle.com> wrote:
> On Fri, Nov 13, 2009 at 3:20 PM, j...@jungletech.com

je...@jungletech.com

unread,
Nov 20, 2009, 5:30:25 PM11/20/09
to xuggler-users
http://www.youtube.com/watch?v=KaaSSRQ0XrM

There is a link where you can see the video....

Any ideas on how to workaround this issue?

Thanks,
---Jeff

On Nov 16, 11:47 am, "j...@jungletech.com" <j...@jungletech.com>
wrote:

je...@jungletech.com

unread,
Dec 9, 2009, 6:14:11 PM12/9/09
to xuggler-users
fix found:
http://groups.google.pl/group/xuggler-users/msg/66891d69d4fd03fa

code:
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;

import com.xuggle.xuggler.IVideoPicture;
import com.xuggle.xuggler.video.BgrConverter;
import com.xuggle.xuggler.IPixelFormat.Type;

public class Main
{
public static void main(String args[]) throws
AWTException,IOException
{
// capture the whole screen
BufferedImage image = new Robot().createScreenCapture( new
Rectangle (Toolkit.getDefaultToolkit().getScreenSize()) );

BufferedImage screencapture = new BufferedImage(image.getWidth
(),image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);

screencapture.getGraphics().drawImage(image, 0, 0, null);

File beforeConvert = new File("BeforeConverter.jpg");
javax.imageio.ImageIO.write(screencapture, "jpg",
beforeConvert);
BgrConverter _converter = new BgrConverter
(Type.BGR24,screencapture.getWidth(), screencapture.getHeight
() ,screencapture.getWidth(), screencapture.getHeight());

IVideoPicture videoPicture = IVideoPicture.make
(Type.YUV420P,screencapture.getWidth(), screencapture.getHeight());
videoPicture = _converter.toPicture(screencapture, 0);

// Save as JPEG
File afterConvert = new File("AfterConverter.jpg");
ImageIO.write(_converter.toImage(videoPicture),
"jpg",afterConvert);
}
}

Type.BGR24 in the BgrConverter seemed to "fix" the issue.


---Jeff
Reply all
Reply to author
Forward
0 new messages