大家好,
我正在开发一个工具,可以通过执行Java进程并将视频帧提供给其使用FFmpeg来渲染视频。
我目前使用以下FFmpeg命令:
ffmpeg -y -f rawvideo -pix_fmt rgb24 -s %WIDTH%x%HEIGHT% -r %FPS% -i - -an -c:v libx264 -preset ultrafast -pix_fmt yuv420p "%FILENAME%.mp4"
,
其中占位符显然会被替换为实际值。
我用于初始化FFmpeg的代码:
//commandArgs is a list of command line arguments for FFmpeg
List<String> command = new ArrayList<String>();
command.add("ffmpeg");
command.addAll(commandArgs);
process = new ProcessBuilder(command).directory(outputFolder).start();
OutputStream exportLogOut = new FileOutputStream("export.log");
new StreamPipe(process.getInputStream(), exportLogOut).start();
new StreamPipe(process.getErrorStream(), exportLogOut).start();
outputStream = process.getOutputStream();
channel = Channels.newChannel(outputStream);
然后,我有以下方法来编写一个包含视频帧的ByteBuffer到FFmpeg:
public void consume(ByteBuffer buf) {
try {
channel.write(buf);
ByteBufferPool.release(buf);
} catch(Exception e) {
e.printStackTrace();
}
}
现在,我的问题是如何将同步音频数据写入输出文件?我认为我需要使用多个管道,当然我还需要修改命令行参数,但我需要帮助:
1) what kind of Audio Data do I need to feed FFmpeg with?
2) how do I feed Audio and Video in one go?
3) how do I keep Audio and Video synchronized?
非常感谢您提供的任何帮助!
你好, CrushedPixel