how to build a video chat program in java without jmf?

Crystal Cat picture Crystal Cat · Apr 21, 2012 · Viewed 9.3k times · Source

I want to create a C/S chat program in java using socket, and now I want to add online video-chat feature to it. After google I found jmf and followed some tutorials, but I don't really like it because every client must install jmf and register webcam( or other audio devices).

So I looking forward to an alternative lib without jmf and found libs like (juv, xuggle), and then works well. Unfortunately, they can only drive the webcam, can't access the audio device.

Can anyone give me some advice?

Answer

Russ Hayward picture Russ Hayward · Apr 21, 2012

I have recently been looking at webcam options and I settled on using GStreamer. It does need separate native libraries but you may be able to bundle these with your program (check the license).

The good news is that it has built in video and audio streaming. The bad news is that it takes a bit of time to get your head around as it is incredibly flexible. Here is an example of setting up streams from the command line on Windows.

Send video:
gst-launch ksvideosrc ! queue ! video/x-raw-yuv,width=320,height=240,framerate=4/1 ! videorate ! videoscale ! ffmpegcolorspace ! queue ! smokeenc ! queue ! udpsink host=[TARGET_IP_ADDRESS] port=5000

Receive video:
gst-launch udpsrc port=5000 ! smokedec ! autovideosink

Send audio:
gst-launch audiotestsrc ! audioconvert ! audio/x-raw-int,channels=1,depth=16,width=16,rate=44100 ! rtpL16pay  ! udpsink host=[TARGET_IP_ADDRESS] port=5001

Receive audio:
gst-launch udpsrc port=5001 ! "application/x-rtp,media=(string)audio, clock-rate=(int)44100, width=16, height=16, encoding-name=(string)L16, encoding-params=(string)1, channels=(int)1, channel-positions=(int)1, payload=(int)96" ! rtpL16depay ! audioconvert ! audioresample ! directsoundsink

The sound streams are adapted from the answer here:

moving audio over a local network using GStreamer

For Linux change ksvideosrc to v4l2src and directsoundsink to alsasink. Anything possible on the command line is possible from within Java using the gstreamer-java library:

http://code.google.com/p/gstreamer-java/

And here are some more useful links:

GStreamer Manual

Cheat Sheet

Webcam Examples

Streaming Info