📄 jvidcap.java
字号:
package video.client;
import javax.media.*;
import javax.media.protocol.*;
import javax.media.control.*;
import javax.media.format.*;
import java.awt.*;
import com.sun.media.controls.VFlowLayout; // Lays components one below the other
import java.awt.event.*;
import java.util.*;
public class JVidCap{
// GUI components
RTPTransmit rtpTransmit;
Processor processor = null;
DataSource datasource = null;
String outputType = "video.quicktime";
public JVidCap(String ipAddr,String port) {
startMonitoring();
rtpTransmit = new RTPTransmit(processor,ipAddr,port);
rtpTransmit.start();
}
private Processor startMonitoring() {
// Close the previous processor, which in turn closes the capture device
if (processor != null) {
processor.stop();
processor.close();
}
// Remove the previous monitor
AudioFormat af = null;
VideoFormat vf = null;
// Need audio得到音频的信息
int samplingRate = 8000;
int samplingSize = 8;
int channels = 1;
af = new AudioFormat(AudioFormat.LINEAR, samplingRate, samplingSize,
channels);
//得到视频文件的信息
String encoding = "RGB";
int sizeX = 160;
int sizeY = 120;
Dimension size = new Dimension(sizeX, sizeY);
vf = new VideoFormat(encoding, size, Format.NOT_SPECIFIED,
null, 15f);
// Use CaptureUtil to create a monitored capture datasource
datasource = CaptureUtil.getCaptureDS(vf, af);//得到捕获数据源
if (datasource != null) {
try {
processor = javax.media.Manager.createProcessor(datasource);
return processor;
} catch (Exception me) {
System.err.println(me);
// Make sure the capture devices are released
datasource.disconnect();
return null;
}
}
return null;
}
private void pauseCapture() {
processor.stop();
}
private void resumeCapture() {
processor.start();
}
private void stopCapture() {
// Stop the capture and the file writer (DataSink)
processor.stop();
processor.close();
processor = null;
// Restart monitoring
}
void exit() {
if (processor != null)
processor.close();
rtpTransmit.stop();
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -