2013-05-26 4 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()를 쓸 때; 프로세서 = Manager.createRealizedProcessor (processorModel) 이전; 비디오 레코드,하지만 jPanel 다시 칠하지, 그것은 항상 흰색. 내가 player.start()를 쓸 때; processor = Manager.createRealizedProcessor (processorModel) 이후; 어떤 레코드 웹 카메라 (jPanel Repait)를 볼 수 있지만 avi 파일을 열면 비어 있습니다. 아무도 도와주세요. 내가 뭘 잘못 했니? – user2366175

답변

1

jmapps jmstudio 소스 코드를 사용해보십시오. 거기에는 좋은 코드가 들어 있습니다. 그것은 데이터 싱크 및 파일 형식 설명자에 관한 것입니다.

개념 : 캡처 장치를 통해 소스에서 레코드를 저장하려면 데이터 싱크가 있어야하며 시스템을로드하고 파일에 저장 한 다음 파일에서 플레이어를로드하십시오.

플레이어에서 파일을 읽지 않으면 JMF에서 작동하지 않습니다. 14.5 년 동안 온라인 상태였으며 JMF 라이브 비디오에 문제가 없었습니다.