Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Friday, August 18, 2017

What's new in WRoom 0.0.10?

If you did not know, I have been working on a new open source project called WRoom in the last few months.  It's a big technical experiment but it has a lot of potential at the same time.

Basically, WRoom is a new web browser where you navigate virtual rooms create using a simple text file.  It's easier than HTML/Javascript and you can create maps all over the web, linked together with Teleporters.

I have released a new version today: 0.0.10 ALPHA.  In this new version, I have integrated Texture videos and a bunch of new stuff.  Currently, the Windows version works pretty well and it kind-of work on Linux, at least on my Ubuntu Mate laptop.

Here's a demo of the latest version:


The main features of WRoom:
  • 3D Browsing à la Doom FPS game
  • Supports textures (PNG, JPG) 
  • New Video Textures using FFMPEG
  • Embedded chat room, (Simple avatars are showing other visitors) 
  • Triggered actions: Teleport, play sound, open door
  • Animated textures using multiple image files
  • Easy to create your own using a simple text editor
  • Free as in Open Source

WRoom is a new twist on creating communities online without having to learn HTML and Javascript.  A map editor is on the way to make things easier.  Maps are hosted on any web hosting plan such as Mochahost or your own web server.

Here's a simple map example:

# Set the title for the room
title=Planet Mars
# irc server
chatroom=#wroommars
server=irc.freenode.net
port=6667
# Load the textures
texture=wall03.png
texture=wall01.jpg
texture=wall03.png
floor=floor.png
ceiling=ceiling.jpg
#Load background sound file
#backgroundsound=background011.wav
# Set the map
# 15x10
map=1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
map=1,0,3,3,3,3,3,3,3,3,0,0,0,0,3,3,0,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,3,3,3,3,3,3,3,3,3,1
map=1,0,0,0,0,0,3,0,0,3,0,3,3,3,3,3,0,3,3,0,0,0,0,0,0,0,0,0,0,0,0,3,0,3,0,3,0,0,0,0,0,0,0,0,1
map=1,3,0,3,3,0,3,0,3,0,0,0,0,0,0,0,0,3,3,0,3,3,3,3,3,3,3,3,3,3,0,0,0,3,0,3,0,3,3,3,3,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3,3,3,3,0,3,0,3,3,0,0,3,0,3,0,3,0,3,3,3,3,3,3,0,3,0,3,3,3,3,3,3,3,3,0,3,0,1
map=1,3,0,3,0,0,0,0,0,0,0,0,3,0,3,3,3,0,0,0,3,0,3,3,3,3,3,0,0,0,0,3,0,3,3,0,0,0,0,3,3,0,0,3,1
map=1,3,0,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,3,0,3,0,0,0,0,0,0,0,3,3,3,3,0,3,3,0,3,3,0,3,3,3,0,0,1
map=1,3,0,0,0,0,0,0,0,3,3,0,0,0,3,3,3,3,3,0,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,3,3,0,0,0,3,0,0,1
map=1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
#Set the starting point
start=1,1
# Define the actions
# Actions are: teleport, sound, message, download
# After the action command, enter the location of the action x,y
# Then the parameter
# action=teleport,x,y,URL
# action=sound,x,y,sound.wav
# action=message,x,y,Message string...
# Actions are triggered by pressing the action key: space bar...
action=teleport,43,29,http://wroom.crombz.com/,Congrats! Back to homebase
# Load text to display on walls
# TEXT=x,y,HTML text entry... 
text=1,3,<div style='border:solid red 3px;background-color:#441111;color:#FF0000;font-size:12px;text-align:center;'>Welcome to Mars!<br>Can you find your wayback to WRoom homebase?<br>Good luck!</div>

Hope you like WRoom!

Visit the homepage at http://wroom.crombz.com

Sunday, June 26, 2016

How to capture desktop in Java: Fast method!

If you are developing software in Java, you may need to capture the desktop at some point.  There is the Robot API that does provide a simple way to capture the desktop, but it's not very efficient.

I've found a better way to capture the desktop, or the webcam in Java, relying on FFMpeg.  There is no need for JNI bindings or other obscure libraries dependencies.  All you need is an executable FFMpeg binary in your path.

Why not use Robot?

The Robot API is really easy to use but it has a major drawback: Speed.  On some computers, you may be able to capture up to 30 fps but on other, you'll struggle to capture images at 3 fps.  It seems that the operating system and the video driver are sensitive areas for the Robot API.

FFMpeg?

FFMpeg is a console application that can capture, transcode and even stream video and audio file.  It's a swiss army knife for multimedia content.  It is available on almost all Linux distros, OS X and Windows.

If not already installed, you can download it here: https://ffmpeg.org/

How to capture video?

Once FFMpeg is installed on your system, you can invoke the binary using the Process class as any other executable.

The trick is to retrieve the captured data directly from FFMpeg using the Process class.  Once the raw data is captured, use a BufferedImage to store those raw data and you'll end up with an Image available for whatever you want to do with it.

Here's the code snippet:

BufferedImage buffer = new BufferedImage(720, 480, BufferedImage.TYPE_3BYTE_BGR);
 
String command = "ffmpeg -nostats -loglevel 0 -f x11grab -r 30 -video_size "+ buffer.getWidth() +"x" + buffer.getHeight() + "-i :0.0 -f rawvideo -pix_fmt bgr24 -";

Process p = Runtime.getRuntime().exec(command);
java.io.DataInputStream in = new java.io.DataInputStream(p.getInputStream());
 
byte[] data = ((DataBufferByte) buffer.getRaster().getDataBuffer()).getData(); 

while (!stopMe) {
     in.readFully(buffer);
}
in.close();
p.destroy();

 This code will capture at the highest frame rate that the computer can support.  The speed of the computer will be the limit of your capture processing speed.

The thing you need to focus is the output format of FFMpeg.  The video encoding must be "rawvideo" with a pixel format matching the BufferedImage.  In this example, a 24 bit/pixel is used in BGR format (Blue, Green, Red).  The data is them exported directly to the console (notice the "-" at the end of the command line...) instead of a file.  That means that using the InputStream from the Process class, Java is able to read the data as fast as it can.

Execute this capture process in a Thread making the BufferedImage available for other parts of your software. 

See the whole thing running...

Using this method, I have built ScreenStudio to capture the desktop into a virtual video mixer built entirely in Java.  If you want to see it running live, download the source code of ScreenStudio at http://screenstudio.crombz.com


Leave you questions in the comments or tweet me at http://twitter.com/patrickballeux


Have fun!