如何使用 java 合并 .webm(音频)文件和 .mp4(视频)文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35939131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 00:46:50  来源:igfitidea点击:

How can I merge .webm (Audio) file and a .mp4 (Video) file using java?

javaffmpegjava-native-interface

提问by user2136160

I have two files one is a .webm audio file and the other one is a .mp4 video file Is there a way to combine these two files together using java?

我有两个文件,一个是 .webm 音频文件,另一个是 .mp4 视频文件有没有办法使用 java 将这两个文件组合在一起?

Thanks in advance.

提前致谢。

回答by cprakashagr

This could be achieved by using ffmpegClibrary via JNIor via executing ffmpegcommand line binaries.

这可以通过使用ffmpegC库通过JNI或通过执行ffmpeg命令行二进制文件来实现。

Here are the steps for command line execution:

以下是命令行执行的步骤:

  1. Download FFmpeg: http://ffmpeg.org/download.html. You Can download the source from the repositoryand build them as per your machine architecture.

  2. Extract downloaded file to specific folder, say c:\ffmpeffolder Using cmd move to specific folder c:\ffmpeffolder\bin

  3. Run following command: $ ffmpeg -i audioInput.webm -i videoInput.mp4 -acodec copy -vcodec copy outputFile.avi
  1. 下载 FFmpeg:http: //ffmpeg.org/download.html。您可以从存储库下载源代码并根据您的机器架构构建它们。

  2. 将下载的文件解压到特定文件夹,比如 c:\ffmpeffolder 使用 cmd 移动到特定文件夹 c:\ffmpeffolder\bin

  3. 运行以下命令: $ ffmpeg -i audioInput.webm -i videoInput.mp4 -acodec copy -vcodec copy outputFile.avi

Command line Execution from Java: https://stackoverflow.com/a/8496537/2900034

Java 命令行执行:https: //stackoverflow.com/a/8496537/2900034

This is it. outputFile.avi will be the resulting file.

就是这个。outputFile.avi 将是结果文件。

Or if you want to work around ffmpeg C libraries

或者,如果您想解决 ffmpeg C 库

Here are some good starts.

这里有一些好的开始。

  1. JNI.
  2. ffmpeg api example.
  1. JNI
  2. ffmpeg api 示例