2011-10-21 5 views
0

JMF를 사용하여 Java로 임시 비디오 플레이어를 만들었습니다. 소스 코드는 아래와 같습니다. JMF를 사용하여 각 프레임을 그레이 스케일로 변환하고 각 프레임에 텍스트 캡션을 추가하는 것과 같은 비디오 효과를 첨부하고 싶습니다.JMF의 비디오 효과

JMF로 비디오 효과에 관한 정보는 놀랍지 않게 부족한 것 같습니다. 앞서 언급 한 작업을 수행하기 위해 필터 (또는 코덱, 또는 그들이 무엇이라고 불리는 지)를 작성하는 방법은 무엇입니까?

import java.awt.*; 
import javax.swing.*; 
import javax.media.*; 
import javax.media.format.*; 
import javax.media.protocol.*; 
import javax.media.control.*; 
import java.net.URL; 
import java.net.MalformedURLException; 
import java.io.*; 


public class MediaPlayer extends JFrame 
{ 
    public MediaPlayer() 
    { 

    } 

    public static void main (String[] args) 
    { 
     JFrame frame = new JFrame(); 
     frame.setLayout(new BorderLayout()); 

     try { 
      URL mediaURL = new File("video.avi").toURI().toURL(); 
      Player mediaPlayer = Manager.createRealizedPlayer(mediaURL); 
      Component video = mediaPlayer.getVisualComponent(); 
      Component controls = mediaPlayer.getControlPanelComponent(); 
      frame.add(video,BorderLayout.CENTER); 
      frame.add(controls,BorderLayout.SOUTH); 
      frame.setVisible(true); 
     } 

     catch (MalformedURLException e) { 
      System.out.println(e.toString()); 

     } 

     catch (IOException e) { 
      System.out.println(e.toString()); 
     } 

     catch (NoPlayerException e) { 
      System.out.println(e.toString()); 
     } 

     catch (CannotRealizeException e) { 
      System.out.println(e.toString()); 
     } 
    } 
} 

답변

1

안녕하세요. 이것은 모든 포럼에서 내 첫 번째 게시물이므로 실수로 유감입니다.

는 프로세서를 추가하고 여기에 효과를 추가하는 코드 샘플을 당신이 "프로세서"여기

를 사용해야하는 비디오 효과입니다 연결하려면 :

String strDevName = "your Media MRL"; 
     CaptureDeviceInfo devInfo = CaptureDeviceManager.getDevice(strDevName); 
     MediaLocator ml = devInfo.getLocator(); 
     DataSource ds; 
     Processor p; 
     try{ 
      ds = Manager.createDataSource(ml); 
      p = Manager.createProcessor(ds); 
      p.configure(); 
      while(p.getState() != p.Configured); 
      p.setContentDescriptor(null); 
      TrackControl[] controls = p.getTrackControls(); 
      controls[0].setFormat(new VideoFormat(VideoFormat.YUV));//Specify the Video format of the video specified in the MRL 
       Codec codec[]= { new comp311.jmf.effect.GreyEffect() };//class GrayEffect is a implementation of javax.media.Effect (the link for the class given below) 
      controls[0].setCodecChain(codec); 
      p.realize(); 
      while(p.getState() != p.Realized); 
      p.prefetch(); 
      while(p.getState() != p.Prefetched); 
      video = p.getVisualComponent(); 
      if (video != null) {System.out.println("Prefetched2"); 
       pnlVideo.add(video, BorderLayout.CENTER);//pnlVideo is a JPanel 
       p.start(); 

      } 
     }catch(Exception e){} 

the link for the effect class :


:

while(p.getState() != p.Configured); 
while(p.getState() != p.Realized); 
while(p.getState() != p.Prefetched); 

내 프로그램에서이 프로세서가 상태를 유지할 때까지 실행을 중지했지만 상태가 achivable이 아닌 경우 prigram gos가 무한 루프로 바뀌 었습니다. JMF는 StaeHelper 클래스를 통해 문제를 해결할 수 있습니다.