java - JMF 中的视频效果

标签 java video-processing jmf

我已经成功使用 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());
        }
    }
}

最佳答案

嗨,这是我在任何论坛上发表的第一篇文章,很抱歉犯了错误。

要附加任何视频效果,您需要使用“处理器”

这里是添加处理器并为其添加效果的代码示例:

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执行,直到处理器达到一个状态,但是如果该状态不可达到,则程序将进入无限循环。 JMF 提供了一个 StaeHelper 类来克服 google 的问题。

<小时/>

关于java - JMF 中的视频效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7847217/

相关文章:

java - 不播放 mp3

java - 除了 JMF 之外,在 Java 中播放媒体的其他方式

java - Spring MVC 将空白 View 返回给用户

java - 我的 try 语句之后的所有内容都必须包含在该 try 语句中才能访问其中的变量吗?

java - Log4j2 无法使用 json 配置文件

java - 抽屉导航上的 NullPointerException

python - 如何保存视频,尽管我取消了该过程

c++ - 如何在opencv中读取.mp4文件

java - xuggler 找不到输入编解码器 ID (avi, msvideo1)

java - 为媒体播放器制作一个搜索栏。