JMF 中的视频效果

发布于 2024-12-11 07:30:47 字数 1457 浏览 1 评论 0原文

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

I've managed to create a makeshift video player in Java using JMF. The source code is given below. I want to attach video effects to it, such as converting each frame to greyscale and adding text captions to each frame, using JMF.

Information on video effects with JMF seems to be surprisingly scarce. How would I go about creating filters (or codecs, or whatever they're called) to do the aforementioned tasks?

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());
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杯敬自由 2024-12-18 07:30:47

您好,这是我在任何论坛上发表的第一篇文章,对于错误深表歉意。

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

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

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){}

效果类的链接:


回复:

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

在我的程序的这个地方,我停止了 forowred 执行,直到处理器达到一个状态,但是如果状态无法实现,那么程序就会进入无限循环。 JMF 提供了一个 StaeHelper 类来克服 google 的问题。


hi this is my first post in any forum so sorry for mistakes.

to attach any video effect you need to use a "processor"

here is a code sample to adding a processor and adding effect to it :

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 :


re :

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

in this places of my program i stopped forowred execution until the processor achives a state , but if the state is not achivable then the prigram gos into a infinity loop. JMF gives a StaeHelper class to overcome the problem google for it.


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文