我正在尝试将音频文件写入现有视频文件。不幸的是我收到日志消息,我无法就地编辑现有文件。
我发现了一些关于视频和音频之间所谓的混合的线程,但它们都不能真正帮助我。也许你们中的某个人可以。此外,这也不是我能做的。我只是需要使用它的人,所以我必须修复它。
感谢您的帮助
String[] args = { FFMPEG_FILE.getAbsolutePath(), "-y", "-i", videoPath, "-ss", String.valueOf(-offset.toFrames() / 50.0f), "-i", audioPath, "-c", "copy", "-map", "0:v", "-map","1:a", "-bsf:v", "h264_mp4toannexb","-r", String.valueOf(project.getFramerate()), "-shortest",outputPath };
ProcessBuilder pb = new ProcessBuilder(args).inheritIO();
Process p = pb.start();
int exit = p.waitFor();
if (exit != 0) {
throw new IOException("ffmpeg terminated with a failure");
}
Run Code Online (Sandbox Code Playgroud)
编辑:正如有人评论的那样,outputPath 与 videopath 相同。于是换了一个,这样就不会再出现这个问题了。但我的输出视频仍然没有声音。我给你日志信息,所以也许你可以从中读到一些东西。
INFO: start ffmpeg: [C:\Program Files\ffmpeg\bin\ffmpeg.exe, -y, -i, C:\Users\USERNAME\Desktop\Test_Workflow\1.mkv, -ss, 0.0, -i, C:\Users\USERNAME\Desktop\Test\resources/videos/P1000501.MP4\audio.ogg, -c, copy, -map, 0:v, -map, 1:a, -bsf:v, h264_mp4toannexb, -r, 25, -shortest, …Run Code Online (Sandbox Code Playgroud)