java - 如何仅使用客户端 JAVA 组合 AVI 和 WAV 文件?

标签 java wav video-processing avi audio-processing

我的程序正在将屏幕捕获视频保存为 AVI 文件,同时还将麦克风的声音录制为 WAV 文件。完成后,我想将两者合并为一个文件(因此基本上将 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/

您可以尝试同时单独阅读和播放其中两个,或者尝试该库为您提供的其他方法。您也可以使用此库进行录音部分。

关于java - 如何仅使用客户端 JAVA 组合 AVI 和 WAV 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42576865/

相关文章:

java - 按后退按钮时 Activity 不发送结果

java - 评估 switch 中的枚举

ffmpeg - Wav 音频文件压缩不起作用

ffmpeg 选择过滤器开始时间?

video - 如何在视频的子部分上设置叠加图像?

java - 将 Infinispan xml 配置从 6.x 迁移到 7.x

java - Gradle CLI:如何查看特定选项的文档

c++ - istream::read 和每个样本的 wav 格式位

java - UnsupportedAudioFileException 的解决方法?

python - 如何在文件夹中使用 opencv 更改速度后保存视频?