- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 stackoverflow.com 上看到了以下代码,并将其复制到您在 JMF 上提交的我的系统中:
import Logging.LogRunner; //Logging.LogRunner is absent s error occurs
import java.util.Vector;
import java.awt.*;
import java.awt.event.*;
import javax.media.*;
import javax.media.format.*;
import javax.media.protocol.*;
import javax.media.datasink.*;
import javax.swing.JButton;
import javax.swing.JOptionPane;
/**
* Records audio and video from a usb camera and saves it to disk. Essentially what is happening
* is we are creating two video streams and an audio stream. We use two video streams
* so one can be sent to the file, and the other can be sent to the gui to show the
* user what they are currently recording. This class is configured to use a certain
* audio and video format, but this can easily be changed to fit dirrenet needs.
* This class was created with
* help from http://www.codeproject.com/KB/audio-video/Java_Video_Capture.aspx.
* Please refer to that site for more information.
* @author dvargo
*/
public class VideoRecorder
{
/**
* The source of the video stream
*/
CaptureDeviceInfo device = null;
/**
* The location of media content
*/
MediaLocator ml = null;
/**
* MediaHandler for rendering and controlling time based media data
*/
Player player = null;
/**
* The screen that will display the video as it is being recorded
*/
Component videoScreen = null;
/**
* The Processor processes data and creates an output in the destination
* format required
*/
Processor processor = null;
/**
* takes a DataSource as input and renders the output to a specified destination
*/
DataSink dataSink = null;
/**
*
*/
TheDataSinkListener dataSinkListener = null;
/**
* The form for the video and other gui compoenents
*/
Frame frm = null;
/**
* A reference to the Starter class.
*/
VideoStarter theForm = null; //VideoStarter does not exist so error occurs
/**
* Used to determine if something went wrong
*/
boolean error = false;
/**
* Basic Constructor to begin recording video to a specified file path. This
* constructor initalizes everything needed to begin recording.
* @param saveFileTo The path and file name of where to save the video.
* @param inForm Reference to the Starter class that initatied this recording.
*/
public VideoRecorder(String saveFileTo,VideoStarter inForm)
{
theForm = inForm;
try
{
//gets a list of devices how support the given video format
Vector deviceList = CaptureDeviceManager.getDeviceList(new YUVFormat());
//if we couldnt find anything to record from
if(deviceList.size() == 0)
{
LogRunner.dialogMessage(this.getClass(),"No video capture devices could be found.");
error = true;
return;
}
// get video device - the first one is almost always the only available camera
device = (CaptureDeviceInfo) deviceList.firstElement();
ml = device.getLocator();
//create a source from the device
DataSource ods = null;
ods = Manager.createDataSource(ml);
/*
* Clone the video source so it can be displayed and used to capture
* the video at the same time. Trying to use the same source for two
* purposes would cause a "source is in use" error
*/
DataSource cloneableDS = Manager.createCloneableDataSource(ods);
DataSource PlayerVidDS = cloneableDS;
// The video capture code will use the clone which is controlled by the player
DataSource CaptureVidDS = ((javax.media.protocol.SourceCloneable) cloneableDS).createClone();
/*
* Display video by starting the player on the source clonable data source
* the clones are fed data stopping the player will stop the video flow
* to the clone data source
*/
player = Manager.createRealizedPlayer(PlayerVidDS);
player.start();
// get an audio device and create an audio data source
deviceList = CaptureDeviceManager.getDeviceList(new javax.media.format.AudioFormat(null));
device = (CaptureDeviceInfo) deviceList.firstElement();
ml = device.getLocator();
DataSource audioDataSource = Manager.createDataSource(ml);
// merge audio and video data sources
DataSource mixedDataSource = null;
DataSource dsArray[] = new DataSource[2];
dsArray[0] = CaptureVidDS; // this is a cloned datasource and is controlled by the master clonable data source
dsArray[1] = audioDataSource;
try
{
mixedDataSource = javax.media.Manager.createMergingDataSource(dsArray);
}
catch (Exception e)
{
//exception handling here
error = true;
System.out.println("Error 1");
e.printStackTrace();
}
// setup output file format to msvideo
FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.MSVIDEO);
// setup output video and audio data format
Format outputFormat[] = new Format[2];
//outputFormat[0] = new VideoFormat(VideoFormat.RGB);
outputFormat[0] = new VideoFormat(VideoFormat.YUV);
outputFormat[1] = new AudioFormat(AudioFormat.LINEAR);
// create a new processor
ProcessorModel processorModel = new ProcessorModel(mixedDataSource, outputFormat, outputType);
try
{
processor = Manager.createRealizedProcessor(processorModel);
}
catch (Exception e) {
// exception handling here
error = true;
System.out.println("Error 2");
e.printStackTrace();
}
try
{
// get the output of the processor to be used as the datasink input
DataSource source = processor.getDataOutput();
// create a File protocol MediaLocator with the location of the file to which bits are to be written
MediaLocator mediadestination = new MediaLocator("file:" + saveFileTo);
// create a datasink to create the video file
dataSink = Manager.createDataSink(source, mediadestination);
// create a listener to control the datasink
dataSinkListener = new TheDataSinkListener();
dataSink.addDataSinkListener(dataSinkListener);
dataSink.open();
// now start the datasink and processor
dataSink.start();
processor.start();
}
catch (Exception e)
{
// exception handling here
error = true;
System.out.println("Error 3");
e.printStackTrace();
}
//set up the gui
createGui();
}
catch (Exception e)
{
System.out.println("Error 4");
LogRunner.getLogger().warning("Error recording video - " + e.getMessage());
e.printStackTrace();
error = true;
}
}
/**
* Flag that determines if something went wrong
* @return True if something did go wrong, false if everything is fine.
*/
public boolean getError()
{
return error;
}
/**
* Creates the gui used to display what is currently being recorded.
*/
private void createGui()
{
videoScreen = player.getVisualComponent();
frm = new Frame("Recording");
frm.setSize(300, 300);
frm.setLayout(new BorderLayout());
frm.add(videoScreen,BorderLayout.CENTER);
JButton close = new JButton("Click Here when done");
frm.add(close,BorderLayout.SOUTH);
close.setVisible(true);
close.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
// Stop the processor doing the movie capture first
processor.stop();
processor.close();
// Closing the processor will end the data stream to the data sink.
// Wait for the end of stream to occur before closing the datasink
dataSinkListener.waitEndOfStream(10);
dataSink.close();
// stop and close the player which closes the video data source
player.stop();
player.close();
theForm.done();
// dispose of the frame and close the application
frm.setVisible(false);
}
});
frm.setAlwaysOnTop(true);
frm.setUndecorated(true);
frm.setLocationRelativeTo(theForm.mainWindow);
frm.setVisible(true);
}
}
/**
*
* Control the ending of the program prior to closing the data sink
*/
class TheDataSinkListener implements DataSinkListener {
boolean endOfStream = false;
// Flag the ending of the data stream
public void dataSinkUpdate(DataSinkEvent event)
{
if (event instanceof javax.media.datasink.EndOfStreamEvent)
{
endOfStream = true;
}
}
/**
* Cause the current thread to sleep if the data stream is still available.
* This makes certain that JMF threads are done prior to closing the data sink
* and finalizing the output file
*/
public void waitEndOfStream(long checkTimeMs) {
while (!endOfStream)
{
try
{
//Thread.currentThread().sleep(checkTimeMs);
Thread.sleep(checkTimeMs);
}
catch (InterruptedException ie)
{
System.out.println("Error 5");
e.printStackTrace();
}
}
}
public static void main(String []args)
{
new VideoRecorder("d:/yusuf/abc.mpg",theForm);
}
}
但是我在哪里可以获得 Logging.LogRunner 和 VideoStarter。对于这些,我的程序在编译期间显示错误。显示以下错误消息
1.
symbol: variable LogRunner
location: class VideoRecorder
F:\Tutorials\Java Tutorial\Programs\VideoRecorder\src\VideoRecorder.java:206: error: cannot find symbol
LogRunner.getLogger().warning("Error recording video - " + e.getMessage());
2.
public VideoRecorder(String saveFileTo,VideoStarter inForm)
^
symbol: class VideoStarter
location: class VideoRecorder
请帮忙
最佳答案
我确实是写这句话的人。很抱歉延迟回复,因为我确信您已经过去了,但它可能对将来的某人有用。 LogRunner 是我们用来写出日志消息的类。您可以将其删除,或者使用您想要的任何内容进行日志记录。
VideoStarter 只是一个启动视频录制过程的 JWindow。这个类也不需要它来工作。
关于java - 纠正 JMF 视频捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12885087/
多个 ChildException catch block 和一个 Exception catch block 之间哪个更好? 更好,我的意思是以良好的实践方式。 举例说明: public stati
我正在尝试将脱机计算机记录在文本文件中,以便以后可以再次运行它们。似乎没有被记录或捕获。 function Get-ComputerNameChange { [CmdletBinding()]
我正在将 Scala 'try/catch' 测试代码转换为使用 'intercept' 有没有我不应该使用“拦截”的场景?使用 'intercept' 而不是 'try/catch' 的唯一好处是简
我对erlang很陌生,我正在尝试使用基本的try/catch语句来工作。我正在使用Webmachine处理一些请求,我真正想做的就是解析一些JSON数据并将其返回。如果JSON数据无效,我只想返回一
我不知道如何捕获删除按键。我发现在 ASCII 代码表中,它位于 127 位,但是 if (Key = #127) then 却无济于事。 然后我检查了 VK_DELETE 的值,它是 47。尝试使用
我很少在失败时对数据库查询使用唯一的错误消息 我经常使用简短的标准消息,例如“数据库错误/失败。请与网站管理员联系”或类似的消息。或自动发送给我 我正在寻找一种在PDO中全局设置一次try {}和ca
我有一个变量CompletableFuture completableFuture 。我希望能够使用任何类型的对象来完成它。例如:completableFuture.complete(new Stri
我认为这是基本的东西,但我不知道该怎么做。为什么我得到 IOException never throw in body of相应的 try 语句 public static void main(Str
我在此代码中遇到 JSON 异常: JSONObject jObject = new JSONObject(JSONString); pontosUsuario.setIdUsuari
我正在尝试打印出用单引号括起来的文本。 /bin/bash -lc '/home/CASPER_REPORTS/scripts/CASPER_gen_report.sh CASPER_1' /bin/
我这里遇到了一点问题。我想弄清楚如何捕获 IllegalArgumentException。对于我的程序,如果用户输入负整数,程序应该捕获 IllegalArgumentException 并询问用户
我无法理解 EJBTransactionRolledbackException。 我有实体: @Entity public class MyEntity { @Id @Generate
对于我给自己提出的以下挑战,如果社区的经验给我任何建议,我将不胜感激 - 即,这里有任何关于最佳方法/方向的指示吗? 要求 允许收集/实时监控从用户 Windows PC 到一组特定 IP 地址(或
我想在我的 ABAP 代码中捕获并处理 SAPSQL_DATA_LOSS。 我试过这个: try. SELECT * FROM (rtab_name) AS rtab
我知道捕获错误不是一个好的做法,但在这种情况下,这样做很重要。我正在尝试运行一个包含游戏一部分的 jar,但它给了我一个 unsatisfiedlink 错误,但这是有趣的部分:我正在使用这段代码:
我有一个表单页面,当我保存它时,它会覆盖数据库。表单页面中有一个文本框,允许用户输入 4000 个字符,但如果用户输入的字符超过此值,则会出现以下错误: ERROR 15:54:05 Abstrac
我想知道在python中绑定(bind)键的最简单方法 例如,默认的 python 控制台窗口出现并等待,然后在 psuedo -> if key "Y" is pressed: print (
下面是别人写的类。 我面临的问题是,当它进入parse method时与 null as the rawString ,它正在扔NumberFormatException 。 所以我想做的是,我应该捕
我有一个简单的脚本,可以捕获所有鼠标单击,除非您单击实际有效的内容。链接、Flash 视频等。我如何调整它,以便无论用户点击什么,在视频加载、新页面加载等之前,它都会发送我构建的简单 GET 请求?
我有一个带有一些选择列表的表单,当选择某些值时,这些列表将显示/隐藏更多输入字段。 问题是大多数用户都是数据输入人员,因此他们在输入数据时大量使用键盘,并且选择列表的 change 事件仅在焦点离开输
我是一名优秀的程序员,十分优秀!