如何仅使用客户端JAVA组合AVI和WAV文件?
我的程序正在做一个屏幕捕获视频,将其转换成AVI文件,同时将麦克风的声音录制成WAV文件。完成后,我想将这两个文件合并成一个文件(因此基本上是将WAV文件作为音频添加到视频中) 我使用以下代码进行屏幕捕获(ScreenRecorder类来自org.monte.ScreenRecorder): 对于音频录制,我是这样做的(这样您就可以看到所有的格式、参数等): 我尝试了以下解决方案,但没有成功: JMF(javax.media.Manager,它在createRealizedProcessor中消亡) Xuggle(com.Xuggle.mediatool和com.Xuggle.xuggler) 我很确定他们不工作,因为他们不喜欢输入格式如何仅使用客户端JAVA组合AVI和WAV文件?,java,wav,video-processing,avi,audio-processing,Java,Wav,Video Processing,Avi,Audio Processing,我的程序正在做一个屏幕捕获视频,将其转换成AVI文件,同时将麦克风的声音录制成WAV文件。完成后,我想将这两个文件合并成一个文件(因此基本上是将WAV文件作为音频添加到视频中) 我使用以下代码进行屏幕捕获(ScreenRecorder类来自org.monte.ScreenRecorder): 对于音频录制,我是这样做的(这样您就可以看到所有的格式、参数等): 我尝试了以下解决方案,但没有成功: JMF(javax.media.Manager,它在createRealizedProcessor中消
是的,我可以很容易地从命令行或在服务器上与FFMPEG进行合并,但这对我来说并不好,我需要一个客户端JAVA解决方案(不能真正要求用户安装FFMPEG,所以我可以使用Runtime.getRuntime().exec或其他工具调用它)。我建议您尝试
vlcj
,该库用于与您类似的目的
您可以尝试同时分别阅读和播放其中的两个,或者尝试此库提供的其他方法。您也可以使用此库进行录制部分。谢谢,我将尝试一下!
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);