【问题标题】:Video effects in JMFJMF 中的视频效果
【发布时间】:2012-05-21 19:53:44
【问题描述】:

我已经设法使用 JMF 在 Java 中创建了一个临时的视频播放器。源代码如下。我想给它附加视频效果,例如将每一帧转换为灰度,并为每一帧添加文本标题,使用 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());
        }
    }
}

【问题讨论】:

    标签: java video-processing jmf


    【解决方案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);
    

    在我的程序的这些地方,我停止了 forowred 执行,直到处理器达到一个状态,但如果该状态不可实现,则 prigram 进入无限循环。 JMF 提供了一个 StaeHelper 类来解决 google 的问题。


    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-11
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 2012-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多