2013-05-26 44 views
2

我想從網絡攝像機錄製視頻並查看我在屏幕上錄製的內容。 單獨地,我可以在需要網絡攝像頭的屏幕上看到它,或者錄製視頻,但不能同時看到它。當我錄製時,jpanel不會更新。它根本沒有報告錯誤。 我該如何解決這個問題?非常感謝你。對不起我的英語不好。錄製並顯示視頻JMF

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; 
    } 
} 
+0

當我寫player.start();在processor = Manager.createRealizedProcessor(processorModel)之前;視頻記錄,但jPanel不會重新繪製,它始終是白色的。 當我寫player.start(); after processor = Manager.createRealizedProcessor(processorModel);我看到了什麼記錄網絡攝像頭(jPanel repait),但是當我打開avi文件時,它是空的。 Plese幫助我任何人。我做錯了什麼? – user2366175

回答

1

嘗試使用jmapps jmstudio源代碼,在那裏有很好的代碼。它關於數據接收器和文件類型描述符。

理念:從通過捕捉設備源的記錄,你需要一個數據接收器那裏,然後在系統,存儲裝載到一個文件並加載從文件的球員。

如果您沒有從播放器中的文件中讀取它,它在JMF中不起作用。已經在線14.5年,JMF直播視頻沒有問題。