3

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?

Mat
  • 202,337
  • 40
  • 393
  • 406
Crystal Cat
  • 151
  • 1
  • 2
  • 10

2 Answers2

4

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

Community
  • 1
  • 1
Russ Hayward
  • 5,617
  • 2
  • 25
  • 30
  • It's great! After learning some basic usages of GStreamer and its java interface,I can access my webcam freely,thanks! :) PS: Every client must install GStream ,so it's there a better way to run my program on other machine not install GStream? – Crystal Cat Apr 21 '12 at 14:12
  • I think it is possible but it is a bit ugly and I'm not sure about the license or whether it is wise. On Windows GStreamer loads its dlls using the PATH and GST_PLUGIN_PATH environment variables. If you modify those variables (just for your process) before you launch your application to point at a directory in your application's folder then you do not need GStreamer to be installed - I think. As I said earlier - I don't recommend it or know if it is legal! – Russ Hayward Apr 21 '12 at 15:37
0

You Can also use OpenCV in order to implement Client Server. OpenCV provides numerous functionalities helping in the capturing of the video. http://docs.opencv.org/java/2.4.2/org/opencv/highgui/VideoCapture.html#VideoCapture(int)