title: Record and show video JMF
body: <p>I want record a video from a web camera and see what I am recording on the screen.
  Individually, I can either see it on the screen that takes web camera, or record a video, but not both. When I am recording, the jpanel is not updated. It reports no errors at all.
  How do I fix this? Thank you very much. Sorry for my English.</p>
  
  <pre><code>public class NewJFrame extends javax.swing.JFrame implements ActionListener {
  
      private static boolean debugDeviceList = false;
      private static String defaultVideoDeviceName = "Microsoft WDM Image Capture";
      private static String defaultAudioDeviceName = "DirectSoundCapture";
      private static String defaultVideoFormatString = "size=640x480, encoding=yuv, maxdatalength=614400";
      private static String defaultAudioFormatString = "linear, 48000.0 hz, 16-bit, stereo, signed";
      private Timer timer = new Timer(40, this);
      private Player player;
  
      public NewJFrame(){
          initComponents();
  
  
          MediaLocator videoMediaLocator = new MediaLocator("vfw://0");
          DataSource myDataSource = Manager.createDataSource(videoMediaLocator);
  
          player = Manager.createPlayer(myDataSource);
          player.start();                                    
  
          DataSource videoDataSource = myDataSource;
          MediaLocator audioMediaLocator = new MediaLocator("dsound://");
          DataSource audioDataSource = null;
  
          audioDataSource = Manager.createDataSource(audioMediaLocator);
  
          DataSource dArray[] = new DataSource[2];
          dArray[0] = videoDataSource;
          dArray[1] = audioDataSource;
          DataSource mixedDataSource = null;
  
          mixedDataSource = Manager.createMergingDataSource(dArray);
  
  
          FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.MSVIDEO);
  
          Format outputFormat[] = new Format[2];
          outputFormat[0] = new VideoFormat(VideoFormat.INDEO50);
          outputFormat[1] = new AudioFormat(AudioFormat.GSM_MS);
  
          processorModel = new ProcessorModel(mixedDataSource, outputFormat, outputType);
  
          processor = Manager.createRealizedProcessor(processorModel);
  
          source = processor.getDataOutput();
  
          dest = new MediaLocator("file:.\\testcam.avi");
  
          dataSink = null;
          dataSinkListener = null;
          dataSink = Manager.createDataSink(source, dest);
          dataSinkListener = new MyDataSinkListener();
          dataSink.addDataSinkListener(dataSinkListener);
          dataSink.open();
      }                     
  
      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
          timer.start();
          dataSink.start();
          processor.start();
      }                                        
  
      private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          timer.stop();
          processor.stop();
          processor.close();
  
          dataSinkListener.waitEndOfStream(10);
          dataSink.close();
  
          Stdout.log("[all done]");
      }                                        
  
      public static void main(String args[]) {
  
          java.awt.EventQueue.invokeLater(new Runnable() {
  
              public void run() {
                      new NewJFrame().setVisible(true);
              }
          });
      }
  
  
      public BufferedImage grabFrameImage() {
          Image image = null;
          FrameGrabbingControl fGrabbingControl = null;
          if (player != null) {
              fGrabbingControl = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
          }
          javax.media.Buffer buffer = fGrabbingControl.grabFrame();
          if (buffer != null) {
              image = new BufferToImage((VideoFormat) buffer.getFormat()).createImage(buffer);
          }
          if (image != null) {
              return (BufferedImage) image;
          }
          return null;
      }
  }
  </code></pre>