如何仅使用客户端JAVA结合AVI和WAV文件?
问题描述:
我的程序正在将屏幕截图视频写入AVI文件,同时还将麦克风的声音录制到WAV文件中。完成后,我想将两者合并为一个文件(因此基本上将WAV文件作为音频添加到视频中)。如何仅使用客户端JAVA结合AVI和WAV文件?
我做了屏幕下面的代码捕获(该ScreenRecorder类是org.monte.screenrecorder):
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
Format fileFormat = new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI);
Format screenFormat = new Format(MediaTypeKey, MediaType.VIDEO,
EncodingKey, ENCODING_AVI_MJPG,
CompressorNameKey, ENCODING_AVI_MJPG,
DepthKey, (int)24,
FrameRateKey, Rational.valueOf(15),
QualityKey, 1.0f,
KeyFrameIntervalKey, (int) (15 * 60));
Format mouseFormat = new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,"black",
FrameRateKey, Rational.valueOf(30));
screenRecorder = new ScreenRecorder(gc, fileFormat, screenFormat, mouseFormat, null);
对于音频记录我做这样的(所以你可以看到所有的格式,参数等):
float sampleRate = 44100;
int sampleSizeInBits = 16;
int channels = 2;
boolean signed = true;
boolean bigEndian = true;
AudioFormat format new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
// checks if system supports the data line
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Line not supported");
System.exit(0);
}
line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format);
line.start(); // start capturing
System.out.println("Start capturing...");
AudioInputStream ais = new AudioInputStream(line);
System.out.println("Start recording...");
// start recording
AudioSystem.write(ais, fileType, wavFile);
我尝试了以下解决方案,但没有成功: JMF(javax.media.Manager,会死在createRealizedProcessor) Xuggle(com.xuggle.mediatool和com.xuggle。 xuggler)
我敢肯定,他们不工作,因为他们不喜欢输入格式。
是的,我可以很容易地通过命令行或服务器与FFMPEG进行合并,但这对我并不好,我需要一个客户端JAVA解决方案(不能真正要求用户安装FFMPEG,所以我可以使用Runtime.getRuntime()。exec或其他)调用它。
答
我建议你试试vlcj
库,用于类似的目的给你。
http://caprica.github.io/vlcj/
你可以尝试阅读,并在同一时间分别扮演其中的两个或尝试这个库为您提供了其他的方法。你也可以用这个库做记录部分。
谢谢,我会试试这个! – KBalazs