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());
}
}
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您好,这是我在任何论坛上发表的第一篇文章,对于错误深表歉意。
要附加任何视频效果,您需要使用“处理器”,
这里是添加处理器并向其添加效果的代码示例:
效果类的链接:
回复:
在我的程序的这个地方,我停止了 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 :
the link for the effect class :
re :
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.