我的Java应用程序正在使用xuggle录制网络摄像头视频。当我使用“ .ts”扩展名时,视频可以正确播放。 但我想将视频记录在扩展名“ .mp4”中。当我更改扩展名时,播放录制的视频的播放器说文件已损坏
您知道会发生什么吗? 预先谢谢你
public StreamServerAgent(Webcam webcam, Dimension dimension, String pathOutputVideo) {
String filename = pathOutputVideo + File.separator + "output-" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".mp4";
IMediaWriter writer = ToolFactory.makeWriter(filename);
Dimension size = WebcamResolution.QVGA.getSize();
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, size.width, size.height);
this.webcam = webcam;
this.dimension = dimension;
this.serverBootstrap = new ServerBootstrap();
this.serverBootstrap.setFactory(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
this.streamServerListener = new StreamServerListenerIMPL();
this.serverBootstrap.setPipelineFactory(new StreamServerChannelPipelineFactory(this.streamServerListener, dimension));
this.timeWorker = new ScheduledThreadPoolExecutor(1);
this.encodeWorker = Executors.newSingleThreadExecutor();
this.h264StreamEncoder = new H264StreamEncoder(dimension, false, writer);
this.secondEncoder = new H264StreamEncoder(dimension, false, writer);
AudioFormat format = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
44100.0F, 16, 2, 4, 44100, false);
this.line = null;
// format is an AudioFormat object
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Error, line not supported");
}
// Obtain and open the line.
try {
this.line = (TargetDataLine) AudioSystem.getLine(info);
this.line.open(format);
} catch (LineUnavailableException ex) {
ex.printStackTrace();
}
this.line.start();
}