Capture video on vlcj

package vlcj;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Camera {
  private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {      
      public void run() {
        new Camera();
  private Camera() {
     //Membaca file Dll Vlc
     NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:/Program Files/VideoLAN/VLC");
     Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
     System.out.println("JDK Version:  " + System.getProperty("") + " bits.");  
     JFrame frame = new JFrame("vlcj Tutorial");
     mediaPlayerComponent = new EmbeddedMediaPlayerComponent();    
     frame.setLocation(100, 100);       
     frame.setSize(1050, 600);
          //Save video
          File dir = new File(System.getProperty("user.home"), "Videos");
          DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
          String fileName = dir.getAbsolutePath() + "/Capture-" + df.format(new Date()) + ".mpg";          
          //Tweak the options depending on your encoding requirements and audio       
          //capture device (ALSA is not likely to work on Windows of course)
          //String[] options = {":sout=#transcode{vcodec=mp4v,vb=4096,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{dst=" + fileName + "},dst=display}", ":input-slave=alsa://hw:0,0"};
          String [] options =  {":sout=#transcode{vcodec=mpgv,vb=4094,scale=1,acodec=mpg,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{dst=" + fileName + "},dst=display}"};
why no sound after capture video?
GroG's picture

Hey Dedy,You have ALSA

Hey Dedy,

You have ALSA commented out, which is correct if your on Windows..

Now you need to :

  • make sure the ip camera really is streaming audio & video
  • determine the format - is it being packaged with the mpeg4 video? - is it a seperate stream? - what format is it? Ogg? or some other format?
  • change your transcode appropriately - here are some examples with audio -

post a video or at least a picture of what your doing so far....

Dedy_hidayat's picture



do you think I should change the line :
acodec = mpg into acodec = mpga
GroG's picture

Sure, I think you've made

Sure, I think you've made great progress - but now, you know more about your system than I do.  
So, you will have to experiment and try to find the correct codec - documentation regarding your IPCamera should say something about it.

Good Luck

Dedy_hidayat's picture

OK Thanks

thanks Grog

PaulCh's picture

USB camera Detection

Hi, first of all, thanks for this amazing post! Currently im trying to only "see what my webcam sees". So i'm not considering the //Save Video part. When i run the code, it just shows a black window, no image. My webcam doesnt respond either (no "active green light").

What would you suggest?

Thanks in advance!

PS: im running this on Eclipse, Windows 7, the webcam is a Microsoft LifeCam VX-800. And all, besides Windows, is running in a x86 basis.

Dedy_hidayat's picture

OK Thanks

"rtsp://"  this code for capture my ip camera, please ask to Grog for connect to your webcam